Nodes/opencv-comfyui/OpenCV warpAffine_1
ComfyUI Node

OpenCV warpAffine_1

The second warpAffine overload — pick either, it's the same matrix math

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV warpAffine_1
  • src
  • M
  • dst
  • nparray
dsize
flags
borderMode
borderValue

This is the _1 overload of cv2.warpAffine, and before you compare it to warpAffine_0 line by line: don't bother. The two nodes are functionally identical in this pack - same inputs, same output, same 2×3 matrix math. The pack's generator numbered OpenCV's overloaded type definitions, and for warpAffine the overloads wrapped to the same call. Whichever one ComfyUI shows in your search is the one to use.

The function itself is worth a real recommendation, because it's one of the most useful nodes in the whole pack. Affine warping covers rotation, translation, scaling, and shear - every "parallel lines stay parallel" geometric move - driven by a 2×3 matrix M. You build M with the pack's getRotationMatrix2D_0 (center, angle, scale) or getAffineTransform_0 (from point pairs), then warp. That's how you straighten a tilted generation, re-center a subject, align a layer, or cheaply augment a training set.

Inputs and outputs

  • src - the NPARRAY image (via Image2Nparray).
  • M - the 2×3 matrix as NPARRAY, typically out of getRotationMatrix2D_0.
  • dsize - output size as a literal, (512, 512) style. The pack parses these with ast.literal_eval, so the commas and parens are load-bearing.
  • flags - interpolation: 0 nearest, 1 linear (default), 2 cubic, 4 Lanczos.
  • borderMode / borderValue - edge handling: 0 constant fill with borderValue (literal, e.g. (0, 0, 0)), 1 replicate edges.

Optional dst - leave it unplugged, per the README's out-param advice. Output: one nparray, back to IMAGE via Nparrays2Image.

Installing

Pack-standard. ComfyUI Manager, search "opencv-comfyui", install, restart:

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

Dependencies: opencv-contrib-python, numpy, torch - no models, no extra downloads.

Quick troubleshooting

invalid syntax (<unknown>, line 0) means your dsize/borderValue literal isn't valid Python - write (512, 512), not 512 512. Black corners after a rotation mean borderMode is on constant fill; switch to 1 or set a borderValue. And remember this pack is batch-1 only: feed it a single image, not a batch, or pull a frame out with ImageFromBatch. Same advice as warpAffine_0, because it is the same node.

Categoryimage/OpenCV

Inputs (7)

NameTypeDefaultDescription
srcNPARRAY
MNPARRAY
dsizeSTRING
flagsINT
borderModeINT
borderValueSTRING
dstoptNPARRAY

Outputs (1)

NameTypeDescription
nparrayNPARRAY