Skip to content

getOptimalNewCameraMatrix

geometryfunctionOpenCV 5.0.0
import { getOptimalNewCameraMatrix } from '@banou/opencv-wasm'

Use after await initOpenCV(). See the initialization and named imports guide.

ARGUMENTScameraMatrix, distCoeffs, imageSize, alpha
FUNCTIONgetOptimalNewCameraMatrix
RETURN TYPEgetOptimalNewCameraMatrixResult
Call structure. A void return can still write to destination arguments. The parameter descriptions define inputs, outputs and ownership.

Returns the new camera intrinsic matrix based on the free scaling parameter.

getOptimalNewCameraMatrix(cameraMatrix: Mat, distCoeffs: Mat, imageSize: Size, alpha: number, newImgSize: Size, centerPrincipalPoint: boolean): getOptimalNewCameraMatrixResult;
3 available overloads
getOptimalNewCameraMatrix(cameraMatrix: Mat, distCoeffs: Mat, imageSize: Size, alpha: number): getOptimalNewCameraMatrixResult;
getOptimalNewCameraMatrix(cameraMatrix: Mat, distCoeffs: Mat, imageSize: Size, alpha: number, newImgSize: Size): getOptimalNewCameraMatrixResult;
getOptimalNewCameraMatrix(cameraMatrix: Mat, distCoeffs: Mat, imageSize: Size, alpha: number, newImgSize: Size, centerPrincipalPoint: boolean): getOptimalNewCameraMatrixResult;
cameraMatrix

Input camera intrinsic matrix.

distCoeffs

Input vector of distortion coefficients \distcoeffs. If the vector is NULL/empty, the zero distortion coefficients are assumed.

imageSize

Original image size.

alpha

Free scaling parameter between 0 (when all the pixels in the undistorted image are valid) and 1 (when all the source image pixels are retained in the undistorted image). See #stereoRectify for details.

newImgSize

Image size after rectification. By default, it is set to imageSize .

centerPrincipalPoint

Optional flag that indicates whether in the new camera intrinsic matrix the principal point should be at the image center or not. By default, the principal point is chosen to best fit a subset of the source image (determined by alpha) to the corrected image.

Returns

new_camera_matrix Output new camera intrinsic matrix.

The function computes and returns the optimal new camera intrinsic matrix based on the free scaling parameter. By varying this parameter, you may retrieve only sensible pixels alpha=0 , keep all the original image pixels if there is valuable information in the corners alpha=1 , or get something in between. When alpha>0 , the undistorted result is likely to have some black pixels corresponding to "virtual" pixels outside of the captured distorted image. The original camera intrinsic matrix, distortion coefficients, the computed new camera intrinsic matrix, and newImageSize should be passed to #initUndistortRectifyMap to produce the maps for #remap . Scalar output parameters are returned as named fields in this object. Release returned native handles with using or delete(), including handles nested in results.

These signatures describe this package. Upstream documentation can mention optional backends that are absent from this build. Check runtime compatibility before choosing a backend or file format.