Nodes/opencv-comfyui/OpenCV recoverPose_4
ComfyUI Node

OpenCV recoverPose_4

Recover pose with just focal length and principal point

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV recoverPose_4
  • E
  • points1
  • points2
  • R
  • t
  • mask
  • int
  • nparray_1
  • nparray_2
  • nparray_3
focal
pp

recoverPose_4 is the "I don't have a full camera matrix, just the numbers" convenience overload. Instead of passing an entire 3×3 intrinsics matrix, you give it the two numbers that define a simple calibrated pinhole camera - the focal length focal and the principal point pp - plus an essential matrix E and the matched points, and it hands back the rotation R and translation t between the two views.

This matters because it matches how people actually get calibration data. If you know your lens's focal length in pixels and where the optical center sits (roughly the image center for most cameras), you have everything the essential-matrix decomposition needs. The cameraMatrix-taking variants (_2/_3) are the same math with the calibration pre-packed into a matrix; this one lets you type the two scalars directly instead.

Inputs

  • E - 3×3 essential matrix (NPARRAY).
  • points1, points2 - matched 2D points (N×2 or 1×N×2).
  • focal - a float, the focal length in pixels. For a "normal" phone or webcam image this is commonly a few hundred to a couple thousand px, depending on sensor and crop.
  • pp - the principal point, as a string literal parsed with ast.literal_eval. Write it as a tuple, e.g. (640, 360) for a 1280×720 image's center. A wrong pp skews the whole result, so don't guess wildly.
  • Optional R, t, mask - out-parameters; leave them unplugged.

Outputs: int (number of points consistent with the recovered pose), nparray_1 (R), nparray_2 (t, scale-ambiguous), nparray_3 (inlier mask).

The literal-input trap

pp is one of the pack's string-literal fields, so it goes through ast.literal_eval at runtime. If you type it wrong you get the README's famous invalid syntax (<unknown>, line 0) error. The fix is always the same: a proper Python literal - (640, 360), not 640,360 with a missing paren, and not "640,360" quoted. This is the most likely failure mode on this node, and it's purely a syntax thing, not a geometry thing.

recoverPose_5 next to it is a byte-identical duplicate - same overload, two stubs, two nodes. Use either.

Reality check

The usual caveats apply hard: this is 3D computer vision, you must supply real matched points and an E that's actually an essential matrix, and translation comes out scale-ambiguous. But of the four recoverPose overloads, this one has the friendliest inputs if your calibration is just "I know the focal length and the image is roughly centered" - which for casual experimentation is most people.

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. batch_size==1 only; the guidedFilter import error at load means conflicting OpenCV packages (fix linked in the README).

Categoryimage/OpenCV

Inputs (8)

NameTypeDefaultDescription
ENPARRAY
points1NPARRAY
points2NPARRAY
focalFLOAT
ppSTRING
RoptNPARRAY
toptNPARRAY
maskoptNPARRAY

Outputs (4)

NameTypeDescription
intINT
nparray_1NPARRAY
nparray_2NPARRAY
nparray_3NPARRAY