Nodes/opencv-comfyui/OpenCV solve_0
ComfyUI Node

OpenCV solve_0

Solve a linear system inside your ComfyUI graph

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV solve_0
  • src1
  • src2
  • dst
  • bool
  • nparray
flags

solve_0 solves a system of linear equations: given src1 (a matrix of coefficients) and src2 (a right-hand side), it returns the x that satisfies src1 · x = src2, plus a boolean telling you whether it actually succeeded. It's cv2.solve wrapped as a node, and it's the kind of node that makes people who build image-generation workflows blink - but it's genuinely the workhorse underneath a lot of computer-vision math.

Where it earns its keep: homography and affine estimation, camera calibration, geometric transforms. If you're building a workflow that computes a perspective warp from point correspondences, or fitting a transform to matching keypoints, at some point you're solving a linear system - and that's this node. It's the "give me the transform parameters" step, and it sits naturally next to the pack's getPerspectiveTransform and findHomography family.

The mechanism is OpenCV's dense linear solver, with a choice of decomposition picked by flags. The outputs are the important part here, because they're a tuple:

  • bool - whether the system was solvable. This is your canary: false means singular or near-singular coefficients, i.e. your point correspondences are degenerate (collinear points, for instance) and the transform you computed is garbage.
  • nparray - the solution x.

Inputs:

  • src1 - NPARRAY, the coefficient matrix (typically n×n for a square system, or n×m for over-determined).
  • src2 - NPARRAY, the right-hand side.
  • flags - INT, the decomposition method. 0 is DECOMP_LU (square systems), 1 is DECOMP_SVD (works for singular/degenerate systems, slower), 4 is DECOMP_QR. For least-squares fits of over-determined systems, combine 16 (DECOMP_NORMAL) with one of the above. Beginners: start with 0; switch to 1 if you get false returns.
  • Optional dst - the OpenCV out-parameter; leave it unconnected.

A wrinkle worth knowing: the inputs are NPARRAYs, and - same as setIdentity - these are matrices, not images. The pack's NPARRAY type serves both, and context tells you which. Don't feed this node a photo and expect a useful x.

And yes, solve_1 is the twin overload: same inputs, same behavior, both call cv2.solve. The auto-generator numbered the overloads and didn't dedupe them. Pick one and be consistent.

Install: ComfyUI Manager → search "opencv-comfyui", or git clone https://github.com/geroldmeisinger/opencv-comfyui into ComfyUI/custom_nodes, restart. Requirements: opencv-contrib-python, numpy, torch. If ComfyUI won't start with Cannot import name 'guidedFilter' from 'cv2.ximgproc', you have two conflicting OpenCV installs - uninstall one.

Honest take for most users: you'll rarely touch this node, and that's fine - it's a tool for the geometry and calibration corner of the ecosystem, not for day-to-day generation. But when a workflow needs a transform computed from data rather than hand-wired, this is the node that does it, and knowing what the bool output means is the difference between silent garbage and a solvable bug.

Categoryimage/OpenCV

Inputs (4)

NameTypeDefaultDescription
src1NPARRAY
src2NPARRAY
flagsINT
dstoptNPARRAY

Outputs (2)

NameTypeDescription
boolBOOLEAN
nparrayNPARRAY