Nodes/opencv-comfyui/OpenCV recoverPose_0
ComfyUI Node

OpenCV recoverPose_0

Recover camera rotation and translation from two photos

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV recoverPose_0
  • points1
  • points2
  • cameraMatrix1
  • distCoeffs1
  • cameraMatrix2
  • distCoeffs2
  • E
  • R
  • t
  • mask
  • int
  • nparray_1
  • nparray_2
  • nparray_3
  • nparray_4
method
prob
threshold

This is the node you'd use if you were building a tiny Structure-from-Motion pipeline inside ComfyUI. recoverPose takes two sets of matched 2D points - the same physical scene features seen from two camera positions - and works out how the camera moved between the shots: the rotation R and translation t that relate the two views. It's the geometric core behind photogrammetry, 3D reconstruction, and augmented-reality tracking, and it's about as far from image generation as this pack gets. If you're here from a normal img2img workflow, you probably want to keep scrolling. If you're doing 3D-from-2D experiments, read on.

How it works, briefly: your two images share some features (corners, texture points). Give the node those matched points, plus each camera's intrinsic calibration, and it computes the essential matrix that encodes the relative motion, then decomposes that matrix into the rotation and translation that must have produced it. Calibration is the whole game here - recoverPose assumes you know the focal length, principal point, and lens distortion of your cameras. No calibration, no meaningful answer.

The _0 variant: full two-camera RANSAC

recoverPose_0 is the overload that handles two separate cameras (stereo rig or two distinct lenses), each with its own intrinsics and distortion, and uses RANSAC to reject bad matches:

  • points1, points2 - matched 2D points from view 1 and view 2, as NPARRAYs. The classic layout is N×2 float32, but OpenCV also accepts 1×N×2. Whatever your matcher outputs, make it consistent.
  • cameraMatrix1, cameraMatrix2 - the 3×3 intrinsic matrices ([[fx, 0, cx], [0, fy, cy], [0,0,1]]) for each camera.
  • distCoeffs1, distCoeffs2 - lens distortion coefficients (a 1×5 or 1×8 array; an all-zeros array means "no distortion").
  • method - int; 1 (RANSAC) is the one you want, 4 (LMEDS) is the robust alternative. It's OpenCV's constant value, not a friendly dropdown.
  • prob - RANSAC confidence (0.999 default).
  • threshold - RANSAC inlier threshold in pixels (1.0 default).
  • Optional E, R, t, mask - preallocated out-parameters. Leave them unplugged.

Outputs, in order: int (the number of inlier matches), nparray_1 (R, 3×3 rotation), nparray_2 (t, 3×1 translation), nparray_3 (E, the 3×3 essential matrix), nparray_4 (inlier mask). The translation is only up to an unknown scale - recovering true scale needs a known distance somewhere in the scene.

Reality check

This is deep, calibration-hungry computer vision. In ComfyUI you'd need a source of matched feature points (this pack doesn't compute them - no findFundamentalMat-style node in this batch), camera intrinsics, and a reason to care. recoverPose_1 next to it is a byte-identical duplicate; the auto-generator couldn't distinguish the overload stubs. If your data is a single essential matrix E rather than two full camera calibrations, the _2/_3 variants are the leaner entry point.

Install

No models, no downloads - the pack is wrappers over OpenCV:

cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui
pip install opencv-contrib-python

Or search "OpenCV" in ComfyUI Manager, restart, browse image/OpenCV. Conflicting OpenCV installs show up as the guidedFilter import error - fix linked in the README. And batch_size==1 only, as with the whole pack.

Categoryimage/OpenCV

Inputs (13)

NameTypeDefaultDescription
points1NPARRAY
points2NPARRAY
cameraMatrix1NPARRAY
distCoeffs1NPARRAY
cameraMatrix2NPARRAY
distCoeffs2NPARRAY
methodINT
probFLOAT
thresholdFLOAT
EoptNPARRAY
RoptNPARRAY
toptNPARRAY
maskoptNPARRAY

Outputs (5)

NameTypeDescription
intINT
nparray_1NPARRAY
nparray_2NPARRAY
nparray_3NPARRAY
nparray_4NPARRAY