CV Matrix Multiply
The boring node that makes homography chains work
- left
- right
- result
Two inputs, one output, left @ right. That's the node. It computes through numpy rather than cv2, so it isn't even an OpenCV wrapper - it's the arithmetic that the OpenCV nodes assume you can do.
Why it matters: transformations compose by multiplication, and in a graph you rarely have all of them at once. Stitch frame 2 onto frame 3, frame 3 onto frame 4, and if you want to know where frame 4 sits on the original canvas you multiply them together in order. That's the entire use case, and it's the difference between a two-image panorama and a ten-image one:
H_total = H_12 @ H_23 @ H_34 # chain of pairwise homographies
Order is not a suggestion. left @ right means right applies first. Get it backwards and you get a matrix that's numerically fine and geometrically wrong, which is the worst kind of error because nothing throws.
Inputs and outputs
left- NPARRAY, MxK.right- NPARRAY, KxN. Inner dimensions must agree; they won't be guessed for you.result- NPARRAY, MxN float64.
The float64 output is deliberate and worth knowing: repeated matrix products accumulate error, and doing that in float32 burns precision you'll want back later. It also means the result is directly acceptable to CV Matrix To Pose, which orthonormalizes as a matter of course - precisely because a rotation block that's been through a chain of multiplications isn't quite a rotation any more.
Nothing else in the pack is a scaled/translated variant of this: CV Transform Points 3D applies a matrix to a point cloud, CV Compose Pose (Trajectory) chains relative poses into a trajectory, CV Find Homography (RANSAC) produces the pairwise matrices in the first place. This is the plain multiply you put between them.
Install
cd ComfyUI/custom_nodes
git clone https://github.com/bmad4ever/comfyui_cv
Manager → ComfyUI CV. Restart, reload the tab. The pack's only real dependency is opencv-contrib-python-headless~=5.0.0.93 (plus numpy and torch, which you already have), Python ≥ 3.12, and a ComfyUI new enough for the V3 node API - the pack builds all its node schemas with it, so an old ComfyUI gives you an import error rather than a partial install.
Common issues
Shape errors, and they're not silent. A K/K mismatch raises. That's better than most of this pack's failure modes - the design rule here is mostly "empty outputs and a found flag rather than an exception," and this node is one of the few places where an error is the correct response because there is no meaningful fallback.
Wrong-looking results with no error. Almost always order, or a matrix from a different convention. Flip the inputs and see. If your chain involves poses rather than 2-D homographies, remember that a 4x4 with a translation column doesn't compose the same way a pure rotation does - the translation is applied in the frame it's expressed in.
You don't have matrices to multiply yet. The usual path: CV Find Homography (RANSAC) between image pairs → this node to chain them → CV Warp Perspective / CV Warp Affine to apply. For 3-D: CV PPF Pose Estimation or CV ICP Register → CV Matrix To Pose → cv2.projectPoints or CV Rasterize Mesh.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| left | NPARRAY | Left matrix (MxK). | |
| right | NPARRAY | Right matrix (KxN). |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| result | NPARRAY | MxN float64 matrix = left @ right. |