OpenCV solvePnP_0
Solve the camera pose from 3D-to-2D point matches, inside ComfyUI
- objectPoints
- imagePoints
- cameraMatrix
- distCoeffs
- rvec
- tvec
- bool
- nparray_1
- nparray_2
This is one of the genuinely serious nodes in the opencv-comfyui pack - the kind that makes you remember the whole thing isn't just a pile of auto-generated filters. solvePnP_0 wraps cv2.solvePnP, the classic Perspective-n-Point routine: you give it a set of known 3D points, their 2D projections in an image, and your camera's intrinsics, and it tells you where the camera was looking - rotation and translation - when the picture was taken.
That's the bread-and-butter of augmented reality, head-pose estimation, and camera tracking. Inside a ComfyUI workflow it's for the same things: estimate the pose of a face or a tracked marker, then drive a warp, a composite, or a ControlNet setup with the result. It's niche in the diffusion world, but if you're the kind of person building a "put this texture on that surface from a real photo" pipeline, this node is exactly what you were missing.
How it works
PnP solves for the rigid transform that maps your 3D points into the camera's coordinate frame such that, when projected through the camera matrix, they land on your 2D points. The unknown is the camera's extrinsic pose - the rvec (rotation as a Rodrigues vector) and tvec (translation).
- objectPoints (NPARRAY) - 3D points, N×3.
- imagePoints (NPARRAY) - their 2D projections, N×2.
- cameraMatrix (NPARRAY) - the 3×3 intrinsic matrix (focal lengths, principal point). You get this from calibration, or from a
calibrationMatrixValues-style node elsewhere in the pack. - distCoeffs (NPARRAY) - lens distortion coefficients; an all-zeros vector means "no distortion."
- useExtrinsicGuess (BOOLEAN) -
falseunless you have a good initial pose to refine. - flags (INT) - the solver method as an OpenCV enum:
0(SOLVEPNP_ITERATIVE) is the safe default;1(EPNP),5(AP3P),6(IPPE) and friends trade robustness for speed. Start at 0. - rvec / tvec (optional NPARRAY) - out-parameters that double as initial guesses when
useExtrinsicGuessis true. Leave them unwired and read the outputs.
Outputs: bool (success - check this, it's False when the solver gives up), then nparray_1 (rvec) and nparray_2 (tvec). Convert rvec back to a 3×3 rotation with Rodrigues_0 if you need the matrix form.
Getting nparrays in and out
This pack deliberately doesn't take IMAGE - everything is nparray. Feed 2D points from an array produced by Image2Nparray or generated in another node, and convert results back to an image with Nparrays2Image when you want to draw the pose. Reminder from the README: only batch size 1, and if a function wants a single-channel image you convert with cvtColor (code 6 = BGR2GRAY). If you hit error: (-215:Assertion failed) img.type() == CV_8UC1, that's this exact issue.
Install
Pack-level, nothing special:
cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui
pip install opencv-contrib-python
or ComfyUI Manager → search "opencv-comfyui". Restart. Only dependency that matters is OpenCV (opencv-contrib-python) plus numpy and torch - no model files.
Troubleshooting
booloutput isFalse- the pose solve failed. Usually a bad camera matrix or mismatched point counts between objectPoints and imagePoints.- Nans in rvec/tvec - degenerate point sets (collinear 3D points) or an incorrect
flags. Try0. error: (-215:Assertion failed)- an image input that should be single-channel isn't; convert withcvtColorcode6.
It's a real CV workhorse hiding under an auto-generated name. If pose estimation is your goal, this is the node the pack was made for.
Inputs (8)
| Name | Type | Default | Description |
|---|---|---|---|
| objectPoints | NPARRAY | — | |
| imagePoints | NPARRAY | — | |
| cameraMatrix | NPARRAY | — | |
| distCoeffs | NPARRAY | — | |
| useExtrinsicGuess | BOOLEAN | — | |
| flags | INT | — | |
| rvecopt | NPARRAY | — | |
| tvecopt | NPARRAY | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| bool | BOOLEAN | — |
| nparray_1 | NPARRAY | — |
| nparray_2 | NPARRAY | — |