Nodes/opencv-comfyui/OpenCV solvePnPRefineLM_1
ComfyUI Node

OpenCV solvePnPRefineLM_1

SolvePnPRefineLM_1 — the refinement twin, generated twice

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV solvePnPRefineLM_1
  • objectPoints
  • imagePoints
  • cameraMatrix
  • distCoeffs
  • rvec
  • tvec
  • nparray_0
  • nparray_1
criteria

Same story as every _0/_1 pair in this pack, so let's not bury it: solvePnPRefineLM_1 and solvePnPRefineLM_0 are the same node, generated from the same overload, differing only in the display-name suffix. OpenCV's stubs declare cv2.solvePnPRefineLM in MatLike and UMat forms, the generator numbers both, and you get two identical nodes. Pick either one; the result is byte-for-byte the same.

For the actual substance - what refinement does, how the criteria literal works, why you run this after solvePnP - read the solvePnPRefineLM_0 article. This page is the "yes, it's a duplicate" reference.

What it takes

Identical schema to its twin:

  • objectPoints, imagePoints, cameraMatrix, distCoeffs (NPARRAY) - the usual PnP correspondence set.
  • rvec, tvec (NPARRAY) - the initial pose you're refining.
  • criteria (STRING) - a TermCriteria written as a Python tuple literal, parsed with ast.literal_eval. (3, 100, 1e-6) means "stop after 100 iterations or when change drops below 1e-6." Type 3 = count + epsilon.

Outputs: nparray_0 (refined rvec) and nparray_1 (refined tvec).

The one thing that bites people

The criteria string. This pack exposes composite OpenCV types as literal strings, and TermCriteria is the case you'll actually hit. The README warns about the error directly: invalid syntax (<unknown>, line 0) means your literal didn't parse. It needs to be a real Python tuple - commas and parentheses, not spaces - like (3, 100, 1e-6). If you're getting that error, this input is the prime suspect, especially since it's the only STRING input on the node.

The usual pipeline context

This node is the second half of "solve then refine." solvePnP_0 (or solvePnPRansac_0) gives you a first pose; wire its rvec/tvec here along with the same points and camera data, and get a tightened pose out. Refinement assumes you started close - it won't rescue a failed solve, and there's no success flag on this node to tell you it worked, so sanity-check the upstream bool before you trust the output.

All pack-standard plumbing: NPARRAY in and out, Image2Nparray / Nparrays2Image at the edges, batch size 1, cvtColor code 6 for single-channel needs.

Install

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

or ComfyUI Manager → "opencv-comfyui". Restart. Deps: opencv-contrib-python, numpy, torch - no model downloads.

Troubleshooting

  • invalid syntax (<unknown>, line 0) → fix the criteria tuple literal.
  • Pose barely changes → normal for refinement; you started close.
  • Cannot import name 'guidedFilter' at startup → conflicting OpenCV packages; README links the fix.

One node, two names. If you understand solvePnPRefineLM_0, this one adds nothing new - and that's the whole point.

Categoryimage/OpenCV

Inputs (7)

NameTypeDefaultDescription
objectPointsNPARRAY
imagePointsNPARRAY
cameraMatrixNPARRAY
distCoeffsNPARRAY
rvecNPARRAY
tvecNPARRAY
criteriaSTRING

Outputs (2)

NameTypeDescription
nparray_0NPARRAY
nparray_1NPARRAY