Nodes/opencv-comfyui/OpenCV initInverseRectificationMap_0
ComfyUI Node

OpenCV initInverseRectificationMap_0

The inverse-rectification map builder for when you need to undo the undo

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV initInverseRectificationMap_0
  • cameraMatrix
  • distCoeffs
  • R
  • newCameraMatrix
  • map1
  • map2
  • nparray_0
  • nparray_1
size
m1type

initInverseRectificationMap_0 computes the inverse rectification map: the remap tables that undo a previous undistort/rectify step and put an image back into the distorted, raw-camera geometry. Where initUndistortRectifyMap_0 builds maps to correct lens distortion, this one builds the maps to reverse that correction - for example, when you've processed a rectified image (a rectified stereo pair, a corrected frame) and need to project the result back into the original camera's pixel coordinates so it lines up with the raw footage.

That's a genuinely obscure thing to want, and I'll say it plainly: this is the most "you must already know what you're doing" node in the pack. It's camera-calibration inverse mapping. If you're doing stereo rectification or compositing corrected results back onto raw footage, this is the function. If you're not, nothing in this article is going to make you need it - and that's fine. cv2.initInverseRectificationMap was designed for the specific case where remap with the forward map isn't the whole story because you want to go the other direction.

The honest framing applies double here: this pack auto-generates a node per OpenCV function, the README says "Expect dragons!", and nothing about this function is beginner-friendly. The inputs are raw calibration matrices.

How it works. It takes the same camera model as the forward version - cameraMatrix (3×3 intrinsics), distCoeffs (distortion coefficients), R (rectification transform, np.eye(3) if unused), newCameraMatrix (the adjusted matrix), plus the output size and a m1type - and produces two maps (map1, map2) that remap_0 applies. The maps encode, per output pixel, the source pixel to sample, but computed for the inverse transform.

The inputs that matter:

  • size (STRING) - output size as a Python literal, exactly (width, height), e.g. (1920, 1080). This is parsed with ast.literal_eval, so wrong syntax = the pack's invalid syntax error. The most common beginner stumble.
  • m1type (INT) - 5 (CV_32FC1, float maps, precision) or 3 (CV_16SC2, integer maps, speed/memory). 5 unless you're optimizing.

The optional map1/map2 are out-parameters - leave them unwired, per the README's standing advice, and take the outputs.

Outputs. Two NPARRAYs - nparray_0 (map1) and nparray_1 (map2) - for remap_0's map1/map2 inputs.

Installing. ComfyUI Manager → search "opencv-comfyui", or:

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

Restart ComfyUI; it's under image/OpenCV.

Where people get burned. Same trio as its sibling: the size literal has to be (w, h), wrong-shaped matrices throw terse OpenCV assertions, and initInverseRectificationMap_1 is identical generated code - pick either one. And one more, specific to this function: an inverse map for a camera you haven't already forward-rectified is a mistake in waiting. Build the forward map first, understand the geometry, then reach for this.

Categoryimage/OpenCV

Inputs (8)

NameTypeDefaultDescription
cameraMatrixNPARRAY
distCoeffsNPARRAY
RNPARRAY
newCameraMatrixNPARRAY
sizeSTRING
m1typeINT
map1optNPARRAY
map2optNPARRAY

Outputs (2)

NameTypeDescription
nparray_0NPARRAY
nparray_1NPARRAY