Nodes/opencv-comfyui/OpenCV estimateAffine3D_2
ComfyUI Node

OpenCV estimateAffine3D_2

Rigid 3D alignment with a scale factor — estimateAffine3D_2 explained

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV estimateAffine3D_2
  • src
  • dst
  • nparray
  • float
force_rotation

The estimateAffine3D family splits into two different jobs. The _0/_1 pair computes a general affine transform (rotation, translation, and per-axis scale/shear). This one, estimateAffine3D_2, is the similarity transform overload: rotation, translation, and a single uniform scale - the rigid-body-plus-size-change model. That's the right fit when your two point sets are the same object measured at different sizes: a 3D model and a scan of it, a template and a target, two reconstructions of the same thing at different scales.

It's the cv2.estimateAffine3D(src, dst, force_rotation) overload from opencv-comfyui (geroldmeisinger/opencv-comfyui), the auto-generated "every OpenCV function as a node" pack. Its twin estimateAffine3D_3 is functionally identical - the generator emitted both from near-identical stub overloads. Pick _2, this one, since you're here.

Inputs and outputs

  • src (NPARRAY) - source 3D points, N×3.
  • dst (NPARRAY) - matching destination 3D points, N×3.
  • force_rotation (BOOLEAN) - this is the interesting knob. True forces the solution to use a proper rotation matrix (determinant +1, no reflection). False allows a reflection, which OpenCV can use when a strict rotation can't line the points up well. If you know your two point sets are related by a real rotation, leave it True.
  • Outputs: nparray - the 3×4 similarity transform (rotation + translation). float - the estimated uniform scale factor, reported separately. That scale is the point of this overload - the _0/_1 general version folds scale into the matrix without telling you what it was.

How it works

Like its siblings, this solves a least-squares alignment problem for 3D point correspondences, but constrained to a rotation + uniform scale + translation model (7 degrees of freedom instead of 12). Because the model is stiffer, it's much more stable when you know the motion really is a rigid-body-plus-scale change - it won't waste degrees of freedom on shear that isn't there. The returned float scale tells you directly how much bigger or smaller one point set is than the other.

Wiring it up

Honest assessment: this is deep-end geometry, and in ComfyUI it's mostly for people processing depth/3D data (depth maps from models like Depth Anything can become point sets). You build N×3 arrays yourself and feed them as nparrays; there's no image conversion in the path. The outputs are a matrix and a number, not displayable images - don't feed them to Nparrays2Image. If your data is 2D imagery, estimateAffine2D_0 is the accessible version of this idea.

Install

ComfyUI Manager (search "opencv-comfyui") or git clone https://github.com/geroldmeisinger/opencv-comfyui into ComfyUI/custom_nodes, then restart. Dependencies: opencv-contrib-python, numpy, torch - no model downloads. Pack gotchas apply: batch_size-1 images only, Python-literal strings for composite params, and the author's "Expect dragons!" warning about the raw, auto-generated UI.

Categoryimage/OpenCV

Inputs (3)

NameTypeDefaultDescription
srcNPARRAY
dstNPARRAY
force_rotationBOOLEAN

Outputs (2)

NameTypeDescription
nparrayNPARRAY
floatFLOAT