OpenCV solveLP_0
A linear programming solver, as a ComfyUI node. Yes, really.
- Func
- Constr
- z
- int
- nparray
This is one of the strangest nodes in the whole opencv-comfyui pack, and honestly that's kind of the point of the pack. solveLP_0 is cv2.solveLP - a simplex-method linear programming solver - wrapped up as a ComfyUI node. There are no pixels involved. There's no diffusion model. You give it a cost function and some constraints as nparrays and it hands back the optimal solution. It exists because the pack's author auto-generated a node for every top-level OpenCV function, and OpenCV happens to ship an LP solver in its core.
So when would you reach for it? If you're building a workflow that does genuine optimization - minimizing a cost subject to linear constraints, say, or solving a small allocation problem on the way to producing an image - this is the node. Realistically? For most of us this is a curiosity, a reminder that these nodes are auto-generated and not everything in them belongs in an image pipeline. The README says as much: "not every function is useful within ComfyUI without further processing."
What it does
cv2.solveLP solves the linear programming problem "minimize cᵀx subject to a set of linear inequality constraints," using the simplex method. In this node:
- Func (NPARRAY, required) is the row-vector of objective-function coefficients - the
cyou're minimizing over. - Constr (NPARRAY, required) is the constraint matrix - the inequalities the solution has to satisfy.
- constr_eps (FLOAT, required here) is the tolerance for deciding a constraint is satisfied. Smaller is stricter.
- z (NPARRAY, optional) is an out-parameter you can mostly ignore; the solver writes the solution into it, and the node returns it anyway.
The outputs are int and nparray. The int is the solver status: 1 means a feasible optimum was found, 0 means the problem is unbounded, -1 means it's infeasible. The nparray is the solution vector x. That status output is the one you'll actually watch - -1 and 0 mean your constraints are wrong.
The honest friction
Two things bite you here. First, there's no convenient way to type a matrix of numbers into ComfyUI - these inputs are NPARRAY sockets, not widgets. The pack gives you Image2Nparray to get arrays from images, and functions like getGaussianKernel_0 that produce arrays, but nothing that says "type a vector here." So in practice you feed Func and Constr with arrays that other cv2 nodes emitted, which makes this node awkward for actual ad-hoc LP work.
Second, you can't preview the result as an image. Nparrays2Image expects an array that is an image; a 1-D solution vector will blow up with the classic 'NoneType' object has no attribute 'shape' error. If you genuinely need LP in a workflow, a Python/Execute node is often the more practical route. This node is the "the generator wrapped everything" version.
Install
Nothing special - this is pack-level. In ComfyUI Manager search "opencv-comfyui", or:
cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui
pip install opencv-contrib-python
then restart ComfyUI. No model files to download; the only real dependency is OpenCV itself (opencv-contrib-python, plus numpy and torch).
Troubleshooting
- Output status is 0 or -1 - your LP problem is unbounded or infeasible; check your constraint matrix, not the node.
invalid syntax (<unknown>, line 0)- this is the pack's composite-parameter parser tripping; here it means one of your literal inputs was malformed.- The classic
guidedFilterimport error on install - conflicting OpenCV packages; see the pack README's known-issue link.
It's a weird node, but that's the deal with auto-generated packs: sometimes you get a gift, sometimes you get a linear programming solver.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| Func | NPARRAY | — | |
| Constr | NPARRAY | — | |
| constr_eps | FLOAT | — | |
| zopt | NPARRAY | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| int | INT | — |
| nparray | NPARRAY | — |