Nodes/opencv-comfyui/OpenCV getAffineTransform_1
ComfyUI Node

OpenCV getAffineTransform_1

The affine transform solver, and its identical twin

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV getAffineTransform_1
  • src
  • dst
  • nparray

getAffineTransform_1 is getAffineTransform_0's duplicate. Same node code, same inputs, same output - pick whichever you find first in the menu. The only difference is the number, and the number is an artifact of this pack's generator producing one node per OpenCV overload.

So, the node: it computes the 2×3 affine matrix that maps three source points onto three destination points. It's the "solve for the transform" step - feed the result to warpAffine and you've got yourself a rotation/scale/translation/shear pipeline for straightening a photographed sign, aligning a detected face, or mapping a region onto a target.

An affine transform is the linear-plus-offset family: it keeps straight lines straight and parallel lines parallel. Three point pairs pin down the six unknowns in the 2×3 matrix exactly. And here's the trap worth repeating from the twin article: affine can't do perspective. If your four corners of a rectangle need to map onto a trapezoid, that's getPerspectiveTransform territory (four points). Reaching for affine when you need perspective gives you a subtly wrong result that "looks close." Know which one you need before you start.

Inputs

  • src (NPARRAY) - source points, 3×2 (x, y).
  • dst (NPARRAY) - destination points, 3×2 (x, y).

Note that dst here is a required input, not the pack's usual ignored out-parameter. Both fields are real. And the correspondence order matters: src row 1 maps to dst row 1, and so on.

Output is nparray, the 2×3 affine matrix - a float matrix, not a picture. Keep it out of Nparrays2Image.

Installing

Ships in geroldmeisinger/opencv-comfyui. ComfyUI Manager: search "opencv-comfyui". Or:

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

Restart ComfyUI. requirements.txt installs opencv-contrib-python, numpy, and torch.

Common issues

Exactly three points per array - anything else trips OpenCV's assertion. Mismatched point order produces a transform that runs without error and is silently wrong. And the pack-wide rules: single-image batches, BGR-vs-RGB awareness if points come from image analysis.

That's the node. If you were hoping _1 held some improved variant, it doesn't - and knowing that is more useful than any secret feature, because it tells you something real about the pack: it's generated, not curated, and the README is upfront about the roughness. For point-driven geometry in ComfyUI, either twin does the job.

Categoryimage/OpenCV

Inputs (2)

NameTypeDefaultDescription
srcNPARRAY
dstNPARRAY

Outputs (1)

NameTypeDescription
nparrayNPARRAY