Nodes/opencv-comfyui/OpenCV SVDecomp_1
ComfyUI Node

OpenCV SVDecomp_1

Singular value decomposition is now a ComfyUI node. Yes, really.

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV SVDecomp_1
  • src
  • w
  • u
  • vt
  • nparray_0
  • nparray_1
  • nparray_2
flags

There's a node in this pack that computes the singular value decomposition of a matrix, and it's probably the least "image" thing you'll ever drag onto a canvas. SVD is the linear-algebra workhorse that powers everything from camera pose estimation to compressed latent approximations - and the opencv-comfyui pack mirrors every top-level cv2 function, so of course cv2.SVDecomp got a node. You will almost certainly never need it for normal generation. You will absolutely need it the day you're doing serious geometry or matrix math inside a workflow, because nothing else in ComfyUI exposes it.

This is SVDecomp_1, one half of a pair. OpenCV declares its functions as overloads in the .pyi file the pack was generated from, so most functions show up twice as _0 and _1. Look at the two nodes side by side and they're the same: same inputs, same outputs. The numbering is a codegen artifact, not a meaningful choice. If you somehow need this node, grab whichever.

What it does

SVD factors any matrix src into three pieces: w (a column vector of singular values), u and vt - such that src = u * diag(w) * vt. The singular values tell you the "energy" of each axis of the matrix, which is why SVD underlies things like PCA, matrix pseudo-inverses, and the fundamental-matrix math in triangulatePoints (its sibling in this pack). In Comfy terms, this is a number-crunching node for the camera-geometry crowd, not a pixel one.

The inputs and outputs that matter

  • src (NPARRAY) - the matrix to decompose.
  • flags (INT) - leave at 0 for the default reduced decomposition. OpenCV's SVD_FULL_UV is 4; that flag makes u and vt square (full-size) instead of reduced. Set it only if you know you want full matrices.
  • Optional w, u, vt - these are OpenCV's call-by-reference out-parameters, exposed as inputs. The README's advice applies verbatim: avoid the optional out-params. The node returns them anyway.

The three outputs are nparray_0 (w), nparray_1 (u), nparray_2 (vt) - the singular values, then the two unitary factors.

Installation

Install the pack once from ComfyUI Manager (search "OpenCV", or clone geroldmeisinger/opencv-comfyui), then:

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

Restart ComfyUI and you'll have a few hundred OpenCV nodes. No model files - it's all generated wrappers. The one real dependency is OpenCV itself: pip install opencv-contrib-python (the README prints opencv-python-contrib, which isn't the package's actual name; use the one from requirements.txt). Because the pack's nodes work on NPARRAY, not IMAGE, you wire Image2Nparray on the way in and Nparrays2Image on the way out - and Image2Nparray only accepts batch size 1.

Common issues

Expect dragons, as the author puts it. The most likely annoyance: you feed an image into src thinking SVD on pixels means something visual. It doesn't - it decomposes the matrix of pixel values, which is a math object, not a picture. And when the output isn't an image (like these three matrices), Nparrays2Image will choke with 'NoneType' object has no attribute 'shape' if you try to force it. If you got here from a 3D-reconstruction workflow, this node is the right tool; if you got here from a filter tutorial, you took a wrong turn.

Categoryimage/OpenCV

Inputs (5)

NameTypeDefaultDescription
srcNPARRAY
flagsINT
woptNPARRAY
uoptNPARRAY
vtoptNPARRAY

Outputs (3)

NameTypeDescription
nparray_0NPARRAY
nparray_1NPARRAY
nparray_2NPARRAY