OpenCV HoughLinesP_0
Finite segments, not infinite lines
- image
- lines
- nparray
HoughLinesP_0 is the probabilistic Hough transform, and it's the line detector you'll actually want 90% of the time. Where plain HoughLines_0 returns infinite lines as [rho, theta], this one returns finite segments with real start and end coordinates [x1, y1, x2, y2]. It's also faster - the "probabilistic" part means it only votes with a random subset of edge points, which cuts computation way down. If you're detecting document edges, lane markings, cables, or the straight lines in a generated image, this is the node.
How it works
Same voting idea as the classic Hough transform, with two twists: it samples a subset of edge points instead of all of them (hence "probabilistic"), and it walks along each detected line to find where actual edge support starts and stops, producing segments instead of infinite lines. That's why it has two extra parameters - minLineLength and maxLineGap - that the plain version doesn't.
The pipeline
It needs an 8-bit grayscale nparray, and it detects on edges you provide. Standard chain:
Image2Nparray- ComfyIMAGE→ OpenCV nparray (BGR, 0–255, uint8).cvtColor_0with code6- BGR2GRAY.Canny_0- edge map.HoughLinesP_0- segments out.
Feed it the raw 3-channel BGR array and you'll get the pack's standard img.type() == CV_8UC1 assertion error. That grayscale conversion is the #1 beginner stumble across all the Hough nodes.
The inputs that matter
image(NPARRAY) - grayscale edge map.rho(FLOAT) - distance resolution;1.0.theta(FLOAT) - angle resolution;0.0174(π/180, one degree).threshold(INT) - minimum votes to accept a line. Raise it for fewer, stronger lines.minLineLength(FLOAT) - minimum segment length in pixels. Lines shorter than this are dropped. This is your noise filter - bump it up to kill little specks.maxLineGap(FLOAT) - maximum gap in pixels between segments before they're merged into one. Raise it to connect dashed lines.
Output nparray is shape (N, 1, 4) - each row [x1, y1, x2, y2]. Leave the optional lines input disconnected.
The drawing problem (it's real)
The output is coordinates, not pixels. This pack has no "render the detected lines" node - the author lists it as an unfinished TODO. To visualize, you'd iterate the segments and draw with the pack's line_0 node, which needs [x1, y1, x2, y2] and color. It works, but it's a few nodes of plumbing and a reminder that these auto-generated nodes are raw OpenCV, not a polished vision toolkit.
Install
cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui
or "OpenCV" via ComfyUI Manager, plus pip install opencv-contrib-python. No model downloads.
Gotchas
Start strict: high threshold, high minLineLength, and you'll get clean lines; loosen threshold and maxLineGap only if you're missing what you want. And if a workflow saved with HoughLinesP_1 loads with a missing-node error, install this pack and you'll get both - _1 is just the duplicate overload.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| image | NPARRAY | — | |
| rho | FLOAT | — | |
| theta | FLOAT | — | |
| threshold | INT | — | |
| minLineLength | FLOAT | — | |
| maxLineGap | FLOAT | — | |
| linesopt | NPARRAY | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| nparray | NPARRAY | — |