Nodes/opencv-comfyui/OpenCV solvePoly_0
ComfyUI Node

OpenCV solvePoly_0

A polynomial root finder in ComfyUI, because OpenCV ships one

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV solvePoly_0
  • coeffs
  • roots
  • float
  • nparray
maxIters

solvePoly_0 finds the roots of a polynomial. Not roots of an image - roots of a literal polynomial equation, like the ones you solved in high school, now available as a ComfyUI node because the opencv-comfyui pack wraps every top-level OpenCV function and cv2.solvePoly happens to be one of them.

Why would that live in a workflow? It's a math utility, the same category as solveLP_0. If your workflow does curve fitting, solves a characteristic equation to decide a parameter, or computes intersections analytically, this is the node. For everyone else it's a curiosity - proof that the pack really did wrap everything, including the math library hiding inside OpenCV.

What it does

OpenCV's solvePoly takes a row of polynomial coefficients (highest degree first) and returns the roots, real and complex, found by iterative refinement. Inputs:

  • coeffs (NPARRAY) - the coefficients, highest power first. For 2x² + 3x - 5 you'd pass [2, 3, -5].
  • maxIters (INT) - the iteration cap for the root-finding loop. More isn't automatically better; hundreds is plenty for well-behaved polynomials.
  • roots (NPARRAY, optional) - an out-parameter the solver writes into. Leave it unwired and read the output.

Outputs: float and nparray. The float is the solution error the solver reports (a residual - how far the computed roots are from actually satisfying the equation), and the nparray is the root vector. Complex roots come back as a 1-D array of interleaved real/imaginary pairs, which is exactly the kind of output that trips up people expecting an image.

Where people get burned

This is a pure-math node in an image-pack, so the friction is predictable:

  • The output isn't an image. Feed nparray into Nparrays2Image and you'll hit the README's own warning: 'NoneType' object has no attribute 'shape'. A root vector is not an image. There's no preview node for plain arrays - the README lists a "Preview Nparray" node as a to-do.
  • Getting coefficients in is awkward. coeffs is a NPARRAY socket, not a text box. The pack can turn images into arrays (Image2Nparray) and generate kernels, but there's no "type your vector here" widget. For real polynomial work, a Python/Execute node is the saner tool.
  • The complex-pair output means the "nparray" may hold values your downstream nodes don't expect. Check the docs before wiring it into anything image-shaped.

None of that is a bug in the node - it's the honest shape of an auto-generated wrapper for a function that was never meant to live in an image graph.

Install

cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui
pip install opencv-contrib-python

or ComfyUI Manager → "opencv-comfyui". Restart. Deps: opencv-contrib-python, numpy, torch - no models to fetch.

Troubleshooting

  • 'NoneType' object has no attribute 'shape' on the output - you tried to render a root vector as an image; you can't, it isn't one.
  • invalid syntax (<unknown>, line 0) - malformed literal input somewhere upstream; the pack's parser is strict.
  • Weird/missing roots - bump maxIters or check your coefficient order (highest degree first).
  • Cannot import name 'guidedFilter' at startup - conflicting OpenCV packages; README has the fix.

Fun to know it exists, occasionally genuinely useful, mostly a museum piece. That's solvePoly_0 in one sentence.

Categoryimage/OpenCV

Inputs (3)

NameTypeDefaultDescription
coeffsNPARRAY
maxItersINT
rootsoptNPARRAY

Outputs (2)

NameTypeDescription
floatFLOAT
nparrayNPARRAY