Nodes/comfyui_cv/cv2.getOptimalNewCameraMatrix
ComfyUI Node

cv2.getOptimalNewCameraMatrix

Raw wrapper of cv2.getOptimalNewCameraMatrix(cameraMatrix, distCoeffs, imageSize, alpha, newImgSize?, centerPrincipalPoint?). Parameters marked '?' are optional; blank means OpenCV default. See the OpenCV documentation for details.

By bmad4ever·Created 3 months ago·Updated 2 days ago· 0
cv2.getOptimalNewCameraMatrix
  • cameraMatrix
  • distCoeffs
  • imageSize
  • newImgSize
  • newCameraMatrix
  • validPixROI
alpha0.0000
centerPrincipalPointfalse
Categoryimage/CV/low-level/cv2 G

Inputs (6)

NameTypeDefaultDescription
cameraMatrixNPARRAYInput camera intrinsic matrix. A data array (points / matrix), NOT an image - only an NPARRAY link is accepted here.
distCoeffsNPARRAYInput vector of distortion coefficients $\distcoeffs$. If the vector is NULL/empty, the zero distortion coefficients are assumed. A data array (points / matrix), NOT an image - only an NPARRAY link is accepted here.
imageSizeCV_TUPLE0,0Original image size. One value with 2 components (w, h) - it travels as a whole, so it cannot arrive half-connected. Wire it from 'CV Tuple' or type the components in place.
alphaFLOAT0.0000-1e+38–1e+38Free 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.
newImgSizeoptCV_TUPLE0,0Image size after rectification. By default, it is set to imageSize . One value with 2 components (w, h) - it travels as a whole, so it cannot arrive half-connected. Wire it from 'CV Tuple' or type the components in place.
centerPrincipalPointoptBOOLEANfalseOptional 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. Preset to the OpenCV default (False).

Outputs (2)

NameTypeDescription
newCameraMatrixNPARRAY
validPixROIBOUNDING_BOXnew_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 . A cv2 Rect as core BOUNDING_BOX data ({x, y, width, height}, nested one group per frame) - feed 'Crop By Bounding Boxes', 'Draw BBoxes', or 'CV Split Tuple' for x/y/w/h.