Nodes/opencv-comfyui/OpenCV undistortPoints_0
ComfyUI Node

OpenCV undistortPoints_0

Fix distorted keypoints, not pixels — the math twin of undistort

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV undistortPoints_0
  • src
  • cameraMatrix
  • distCoeffs
  • dst
  • R
  • P
  • nparray

undistort fixes a whole image's lens distortion; undistortPoints fixes just the points. Same calibration math, different payload: instead of remapping every pixel, this node takes an array of 2D feature coordinates - keypoints, corners, matched points - and returns where each one would sit if the lens weren't bending the light. That's the operation you want before any geometry work: feature matching, homography estimation, stereo correspondence, or computing camera pose from known points. Correct the points, and every downstream geometry computation starts from honest coordinates instead of bent ones.

For the ComfyUI crowd this is niche-but-real. If you're building a pipeline that finds feature points in real photographs (with the pack's goodFeaturesToTrack or corner nodes) and then does anything geometric with them, the points come out of the detector distorted. Run them through undistortPoints with the camera's intrinsics and distortion coefficients and the math downstream - like triangulatePoints, findHomography, or pose estimation - has a fighting chance of being right. This is undistortPoints_0; an identical _1 twin exists from the overload expansion.

Inputs and outputs that matter

  • src (NPARRAY) - the input points, as an N×2 or N×1×2 array. This is not an image; it's a list of (x, y) coordinates.
  • cameraMatrix (NPARRAY) - the 3×3 intrinsics matrix.
  • distCoeffs (NPARRAY) - the distortion coefficients.

Optional R is a rectification matrix (leave unwired unless your rig rectifies) and P is the new camera matrix for reprojection (leave unwired to get normalized coordinates). The optional dst is an out-parameter - leave it alone. Output is one nparray of corrected points.

Installation

Pack-wide: ComfyUI Manager (search "OpenCV" or geroldmeisinger/opencv-comfyui), or git clone https://github.com/geroldmeisinger/opencv-comfyui into ComfyUI/custom_nodes, restart. Needs opencv-contrib-python (pip install opencv-contrib-python). No models.

Common issues

The predictable failures: feeding an image instead of points (it wants coordinates, so a photograph in means nonsense out), wrong point-array shape (assertion error), and the pack-wide rules - NPARRAY only, batch size 1, Image2Nparray/Nparrays2Image at the edges. Also remember the output is point coordinates, not a viewable image; trying to push it through Nparrays2Image hits the README's 'NoneType' object has no attribute 'shape' wall. Use it where the math is the point.

Categoryimage/OpenCV

Inputs (6)

NameTypeDefaultDescription
srcNPARRAY
cameraMatrixNPARRAY
distCoeffsNPARRAY
dstoptNPARRAY
RoptNPARRAY
PoptNPARRAY

Outputs (1)

NameTypeDescription
nparrayNPARRAY