Nodes/comfyui_cv/CV Solve PnP (Pose)
ComfyUI Node

CV Solve PnP (Pose)

Estimates the pose (rotation + translation) of a known set of 3D object points seen at given 2D image points (cv2.solvePnP) - e.g. a chessboard or planar marker for augmented reality. Failure-tolerant like 'CV Find Homography': fewer than 4 points, a count mismatch or a degenerate configuration returns found=false with zero rvec/tvec instead of raising. Feed object_points (a planar grid from 'CV Grid Points', or any 'CV Points'), the matching image_points (cv2.findChessboardCorners / Match Features / goodFeaturesToTrack) and a camera matrix ('CV Camera Matrix' or 'Calibrate Camera'); the rvec/tvec drive cv2.projectPoints / drawFrameAxes to overlay a 3D object. Branch on 'found' with a control-flow node to skip the overlay when nothing was detected.

By bmad4ever·Created 3 months ago·Updated 2 days ago· 0
CV Solve PnP (Pose)
  • object_points
  • image_points
  • camera_matrix
  • dist_coeffs
  • rvec
  • tvec
  • found
  • inliers
  • inlier_count
  • reproj_error
methodSOLVEPNP_ITERATIVE
estimationall points (least squares)
reprojection_error3.0
ransac_iterations1000
confidence0.999
Categoryimage/CV/features

Inputs (9)

NameTypeDefaultDescription
object_pointsNPARRAY3D points in object space, Nx3 or Nx1x3 (e.g. 'CV Grid Points' for a chessboard, or 'CV Points' for a cube).
image_pointsNPARRAYThe matching 2D image points, Nx2 or Nx1x2, in the same order as object_points (e.g. findChessboardCorners).
camera_matrixNPARRAY3x3 intrinsic matrix K ('CV Camera Matrix' or 'Calibrate Camera').
methodCOMBOSOLVEPNP_ITERATIVEPnP solver. ITERATIVE (Levenberg-Marquardt) is the general default; IPPE/IPPE_SQUARE are for planar targets.
dist_coeffsoptNPARRAYLens distortion coefficients (k1, k2, p1, p2[, k3...]); leave unconnected for an ideal pinhole camera (no distortion).
estimationoptCOMBOall points (least squares)'all points' fits every correspondence - correct for a chessboard or marker, where they are all good. 'RANSAC' tolerates wrong correspondences and is what feature matches or stereo-derived 3D points need; it also fills the 'inliers' output.
reprojection_erroroptFLOAT3.00.1–100RANSAC only: how many pixels a point may miss its reprojection by and still count as an inlier.
ransac_iterationsoptINT10001–100000RANSAC only: maximum sampling iterations.
confidenceoptFLOAT0.9990–1RANSAC only: probability that the returned pose comes from an all-inlier sample.

Outputs (6)

NameTypeDescription
rvecNPARRAY3x1 Rodrigues rotation vector (zeros if not found). Pass to cv2.projectPoints / drawFrameAxes / Rodrigues / 'CV Pose To Matrix'.
tvecNPARRAY3x1 translation vector (zeros if not found).
foundBOOLEAN
inliersNPARRAYNx1 uint8 mask of the correspondences RANSAC kept (all 255 for the 'all points' estimation, all 0 if not found). Filter the matches with 'CV Filter Points By Mask' / 'CV Filter Points 3D By Mask'.
inlier_countINT
reproj_errorFLOATMean reprojection error in pixels over the inliers - the quality number for this pose (under ~1-3 px is a good fit). 0 when not found.