Nodes/opencv-comfyui/OpenCV stereoRectify_1
ComfyUI Node

OpenCV stereoRectify_1

StereoRectify, the second overload — same camera math

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV stereoRectify_1
  • cameraMatrix1
  • distCoeffs1
  • cameraMatrix2
  • distCoeffs2
  • R
  • T
  • R1
  • R2
  • P1
  • P2
  • Q
  • nparray_0
  • nparray_1
  • nparray_2
  • nparray_3
  • nparray_4
  • literal_5
  • literal_6
imageSize
flags
alpha
newImageSize

stereoRectify_1 is the numbered twin of stereoRectify_0, and the numbering is the only difference. I looked at the generated source: same class shape, same inputs, same call to cv2.stereoRectify. This pack auto-generates one node per OpenCV overload and leaves the duplicates in, so you can pick either suffix and get the same behavior. Fine. Now, the actual function is worth understanding, because it's serious camera math hiding in a node graph.

cv2.stereoRectify is the calibrated-stereo workhorse. You feed it the two cameras' intrinsics (cameraMatrix1/cameraMatrix2), their distortion coefficients, the rotation R and translation T between them, plus imageSize and alpha. It returns the rectification transforms: R1, R2, P1, P2, and Q - the first four remap both views so epipolar lines become horizontal scanlines, and Q is the matrix that converts disparity into 3D coordinates. This is the step you need before stereo block matching - note the pack only wraps standalone cv2 functions, so the StereoBM/StereoSGBM classes aren't included and you'd run matching in your own cv2 code - and it only makes sense if you actually have a calibrated stereo rig. If you don't have intrinsics and a measured R/T, this isn't your node - the uncalibrated cousin stereoRectifyUncalibrated is the one that works from feature matches alone.

Inputs and outputs. All the camera matrices are NPARRAY; imageSize and newImageSize are STRING literals you type like (640, 480). flags is an INT (0 is the default), alpha a FLOAT controlling how much of the image survives cropping. Outputs: five NPARRAYs (nparray_0nparray_4 = R1, R2, P1, P2, Q) and two STRING outputs (literal_5, literal_6) that are the valid-pixel ROI rectangles, stringified by the generator. Wire R1/R2 and P1/P2 into cv2.remap-style processing and Q into the disparity-to-depth step.

Honest expectations. This is raw, auto-generated OpenCV in a UI built for image generation. No friendly widgets, no calibration helper, no bundled checkerboard flow - you're expected to know the OpenCV docs (the README points straight at them). The author's own warning, "Expect dragons!", applies to every node here and this one most of all. It works, it calls the real cv2 function with your values, and it will happily produce nonsense if you feed it plausible-looking garbage.

Install. ComfyUI Manager → search "opencv-comfyui", or:

cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui

restart. Needs opencv-contrib-python, numpy, torch; if you see Cannot import name 'guidedFilter' from 'cv2.ximgproc' at startup, resolve the conflicting OpenCV packages first. And keep the pack's type contract in mind - NPARRAY means numpy BGR uint8, nothing tensor-shaped.

Categoryimage/OpenCV

Inputs (15)

NameTypeDefaultDescription
cameraMatrix1NPARRAY
distCoeffs1NPARRAY
cameraMatrix2NPARRAY
distCoeffs2NPARRAY
imageSizeSTRING
RNPARRAY
TNPARRAY
flagsINT
alphaFLOAT
newImageSizeSTRING
R1optNPARRAY
R2optNPARRAY
P1optNPARRAY
P2optNPARRAY
QoptNPARRAY

Outputs (7)

NameTypeDescription
nparray_0NPARRAY
nparray_1NPARRAY
nparray_2NPARRAY
nparray_3NPARRAY
nparray_4NPARRAY
literal_5STRING
literal_6STRING