Nodes/opencv-comfyui/OpenCV findTransformECC_2
ComfyUI Node

OpenCV findTransformECC_2

Image alignment with optional mask — the friendlier ECC variant

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV findTransformECC_2
  • templateImage
  • inputImage
  • warpMatrix
  • inputMask
  • float
  • nparray
motionType
criteria

OpenCV findTransformECC_2 is the "fewer required inputs" version of the ECC image-alignment node. Compared to _0, it drops gaussFiltSize from the required list entirely and makes inputMask optional, leaving you with just the essentials: templateImage, inputImage, warpMatrix, motionType, and criteria. This is the cleaner entry point for anyone who just wants to align two frames without tripping over the mask and smoothing widgets first.

Everything else is the same math: cv2.findTransformECC uses Enhanced Correlation Coefficient optimization to find the warp that best registers inputImage to templateImage, and it returns two things - float, the alignment score (toward 1.0 = well aligned), and nparray, the refined warp matrix. That matrix plugs straight into this pack's warpPerspective to produce the aligned image.

Inputs, in plain terms

  • templateImage / inputImage - the reference and the image to move, both single-channel (NPARRAY via Image2Nparray, then cvtColor with code = 6 to grayscale). ECC asserts on RGB input.
  • warpMatrix - the initial transform guess. 2x3 identity for translation/euclidean/affine, 3x3 identity for homography. ECC refines from here, so start sane.
  • motionType - 0 translation, 1 euclidean (rotation too), 2 affine, 3 homography. Translation is the safe first attempt.
  • criteria - a TermCriteria string literal, e.g. (3, 50, 0.001). The pack parses composite types with literal_eval, so invalid syntax means your literal isn't valid Python.

The optional inputMask, when you get there, lets you tell ECC "only pay attention to these pixels" - handy when part of the frame is unreliable or has a moving object you want ignored.

Where people get caught

Initialization. ECC is a local optimizer. Give it a wildly wrong warpMatrix and it converges to a wrong answer that still looks like it tried. Identity is always a safe start, and the score output exists precisely so you can verify: if it's low, your starting guess or motion type is wrong.

Grayscale gate. Multi-channel input dies with an assertion (img.type() == CV_8UC1). This is the #1 stumble on this node family, and the fix is always cvtColor code 6.

Outputs aren't frames. A float score and a matrix - the matrix previews through Nparrays2Image only if you enjoy 'NoneType' object has no attribute 'shape' errors. Use warpPerspective to see pixels.

Install

Same pack. ComfyUI Manager → search opencv-comfyui → install → restart, or:

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

requirements.txt installs opencv-contrib-python, numpy, torch. A broken cv2 import (usually duplicate OpenCV installs, guidedFilter error as the tell) stops the whole pack from registering.

Verdict

If you just want to align two frames and the required gaussFiltSize of _0 feels like ceremony, _2 is your node. _3 is its byte-identical twin. Start with translation motion, identity warp, (3, 50, 0.001) criteria, and read the score.

Categoryimage/OpenCV

Inputs (6)

NameTypeDefaultDescription
templateImageNPARRAY
inputImageNPARRAY
warpMatrixNPARRAY
motionTypeINT
criteriaSTRING
inputMaskoptNPARRAY

Outputs (2)

NameTypeDescription
floatFLOAT
nparrayNPARRAY