Nodes/opencv-comfyui/OpenCV solve_1
ComfyUI Node

OpenCV solve_1

The duplicate linear-solver node (and what it solves)

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

Let's get the obvious question out of the way: solve_1 and solve_0 are the same node. Identical inputs, identical outputs, both wrap cv2.solve. The _1 suffix is the pack's auto-generator numbering the second OpenCV overload it parsed; for this function the two generated nodes came out indistinguishable. Use either. The only reason to think about the suffix at all is to understand that this pack generates a node per overload and doesn't deduplicate - the README's "expect dragons" is talking about exactly this.

The node itself solves a linear system: src1 · x = src2. Give it a coefficient matrix and a right-hand side, get back the solution plus a success flag. It's the computational core behind homography and affine estimation, calibration, and any geometry where you fit a transform to data.

The three required inputs:

  • src1 - NPARRAY, coefficient matrix.
  • src2 - NPARRAY, right-hand side.
  • flags - INT, decomposition method: 0 = LU (default, square systems), 1 = SVD (tolerates singular/degenerate systems, slower), 4 = QR. For least-squares on over-determined systems, add 16 (DECOMP_NORMAL).

Optional dst is the out-parameter - leave it alone. The two outputs are the useful part:

  • bool - whether the system was solvable. Read this before trusting anything downstream. false means degenerate input (e.g. collinear points in a fit), and the solution is meaningless.
  • nparray - the solution x.

Two cautions, both from the pack's design. First, the NPARRAY inputs are matrices, not images - this pack's NPARRAY type does double duty, and solve wants math, not pixels. Second, the whole node is only as good as your flags: a degenerate system will happily produce a plausible-looking but wrong solution if you don't check the bool. For beginners, the workflow is: start with flags=0, and if bool comes back false, try flags=1 before assuming your data is broken.

Install is pack-standard: ComfyUI Manager → search "opencv-comfyui", or git clone https://github.com/geroldmeisinger/opencv-comfyui into ComfyUI/custom_nodes, restart. Dependencies are opencv-contrib-python, numpy, torch. Startup failure with Cannot import name 'guidedFilter' from 'cv2.ximgproc' means two conflicting OpenCV installs - uninstall one.

Reality check on audience: if your ComfyUI life is prompting and sampling, you may never need this node, and that's okay. It lives in the geometry/calibration corner of the graph. When you do need it - computing a transform from correspondences, fitting a model to points - it's the difference between hand-wiring math in Python and keeping everything in the visual graph.

Categoryimage/OpenCV

Inputs (4)

NameTypeDefaultDescription
src1NPARRAY
src2NPARRAY
flagsINT
dstoptNPARRAY

Outputs (2)

NameTypeDescription
boolBOOLEAN
nparrayNPARRAY