Nodes/opencv-comfyui/OpenCV remap_0
ComfyUI Node

OpenCV remap_0

Bend any image any way you like — remap_0 is the master warp

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV remap_0
  • src
  • map1
  • map2
  • dst
  • nparray
interpolation
borderMode
borderValue

remap_0 is the heavy artillery of geometric transforms. While a perspective or affine warp is a single fixed formula, remap lets you move every pixel to an arbitrary location of your choosing. Lens distortion correction, fisheye removal, barrel distortion, swirl effects, polar-to-cartesian math, undistortion from camera calibration - all of it funnels through this one node, wrapped for ComfyUI by opencv-comfyui (geroldmeisinger/opencv-comfyui).

Here's the mental model: you supply two maps that describe, for each destination pixel, which source pixel to sample. map1 holds the x-coordinates, map2 the y-coordinates. The output is the source image resampled through those maps. That's the whole trick - and it's also the whole difficulty, because in a pure ComfyUI graph, generating the maps is the hard part.

The inputs that matter

  • src - the image you're warping, an NPARRAY from Image2Nparray.
  • map1 - NPARRAY, float32. Either a single-channel (H, W) grid of destination→source x-coordinates, or a two-channel (H, W, 2) map where map2 then stays empty.
  • map2 - NPARRAY, float32, the y-coordinate map (single-channel form). If map1 is two-channel, this is ignored.
  • interpolation - 0 nearest, 1 linear (the default), 2 cubic, 4 Lanczos. Linear is fine for distortion work.
  • borderMode - what to do where the map points off-image: 0 constant, 1 replicate edge, 2 reflect, 3 wrap, 4 reflect-101.
  • borderValue - a Scalar literal (B, G, R) used only for constant borders. And yes, BGR.

Output is the remapped nparray, which goes to Nparrays2Image and back into normal ComfyUI.

The honest warning

This is the node where the pack's "Expect dragons" banner is most earned. The maps must be float32 numpy arrays of exactly the right shape - feed it anything else and you get the classic map1 must be CV_32FC1 assertion crash. And producing those maps inside ComfyUI means either a python/node-js node that can build numpy arrays, or precomputed maps from a calibration script loaded some other way. There is no built-in "make a fisheye map" widget, and there won't be - this pack is a thin wrapper, not a convenience layer.

So: if you already have undistortion maps from a camera-calibration pass (the standard output of OpenCV's stereo/calibration tooling), remap_0 is exactly right. If you're hoping for a no-code barrel-distortion slider, this isn't the node - you'd be happier with one of the Image-Filters style packs for casual effects.

Installing it

ComfyUI Manager (search "opencv-comfyui"), or:

cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui

restart, then confirm OpenCV:

pip install opencv-contrib-python

And remember the borderValue literal rule: (0, 0, 0) parses, 0, 0, 0 throws the pack's signature invalid syntax error.

Categoryimage/OpenCV

Inputs (7)

NameTypeDefaultDescription
srcNPARRAY
map1NPARRAY
map2NPARRAY
interpolationINT
borderModeINT
borderValueSTRING
dstoptNPARRAY

Outputs (1)

NameTypeDescription
nparrayNPARRAY