Nodes/opencv-comfyui/OpenCV undistort_1
ComfyUI Node

OpenCV undistort_1

Undistort_1 — the second overload of the lens-fix node

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV undistort_1
  • src
  • cameraMatrix
  • distCoeffs
  • dst
  • newCameraMatrix
  • nparray

undistort_1 is the second numbered version of cv2.undistort, and like every _0/_1 pair in this pack it's the same function generated twice from OpenCV's overload declarations. Same inputs, same output, no behavioral difference. If your workflow has this node in it, the content below is exactly what it's doing.

And what it's doing is genuinely worth having: correcting lens distortion on real photographs before they go into an image pipeline. Every wide-angle or phone photo is bowed at the edges; undistort warps it back flat given the right calibration data. In a ComfyUI context the payoff is that img2img and ControlNet see undistorted geometry instead of learning a camera's barrel bend as part of the "style." It's a deterministic, millisecond preprocess - precisely the move the post-processing KB advocates: fix the optics with a filter, don't pay for it in generation quality.

Inputs and outputs that matter

  • src (NPARRAY) - the distorted image.
  • cameraMatrix (NPARRAY) - the 3×3 intrinsics matrix (fx, fy, cx, cy plus the 1).
  • distCoeffs (NPARRAY) - the radial/tangential distortion coefficients (k1, k2, p1, p2, k3, ...).

Optional newCameraMatrix re-projects onto different optics - leave it unwired to keep the input camera matrix. Optional dst is the out-parameter - leave it unwired too. Output is one nparray - the straightened image.

Installation

One pack, both twins: ComfyUI Manager (search "OpenCV"), or git clone https://github.com/geroldmeisinger/opencv-comfyui into ComfyUI/custom_nodes, restart. Requires opencv-contrib-python (pip install opencv-contrib-python). No models - calibration data is something you supply, not download.

Common issues

The README-grounded failure modes apply here squarely: grayscale-input assertions (CV_8UC1 - convert with cvtColor, code=6), batch-size-1 limits on Image2Nparray (split with ImageFromBatch), and the ever-present NPARRAY workflow (Image2Nparray in, Nparrays2Image out). The calibration-data requirement is the real cost of this node - you need intrinsics and distortion coefficients from a checkerboard calibration or known rig parameters, and this pack doesn't generate them for you. It's a power tool for people who shoot with known cameras, not a plug-and-play fix.

Categoryimage/OpenCV

Inputs (5)

NameTypeDefaultDescription
srcNPARRAY
cameraMatrixNPARRAY
distCoeffsNPARRAY
dstoptNPARRAY
newCameraMatrixoptNPARRAY

Outputs (1)

NameTypeDescription
nparrayNPARRAY