Nodes/opencv-comfyui/OpenCV HoughLinesWithAccumulator_0
ComfyUI Node

OpenCV HoughLinesWithAccumulator_0

Hough lines that tell you how confident the detector was

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV HoughLinesWithAccumulator_0
  • image
  • lines
  • nparray
rho
theta
threshold
srn
stn
min_theta
max_theta

HoughLinesWithAccumulator_0 is HoughLines_0 with one bonus: each detected line carries its vote count. Where the plain version returns [rho, theta] per line, this one returns [rho, theta, votes] - the third column is how many edge pixels actually supported that line. It's a niche upgrade, but if you want to rank detections by confidence instead of just taking whatever crossed the threshold, this is the node.

How it works

Identical machinery to HoughLines_0: edge points vote into a (rho, theta) accumulator, and lines clearing threshold votes are returned. The difference is purely in what gets surfaced - the accumulator's raw count per winning cell comes along as the third element. You can think of it as HoughLines with the scoring information exposed, which is genuinely useful when you want to keep the top-K strongest lines or filter by "how much evidence".

Same pipeline as the other Hough nodes: Image2NparraycvtColor (code 6 for BGR2GRAY) → Canny_0 → this node. It needs an 8-bit grayscale nparray; feed it the 3-channel BGR output and you get the pack's img.type() == CV_8UC1 assertion error.

The inputs that matter

  • image (NPARRAY) - grayscale, ideally a Canny edge map.
  • rho (FLOAT) - distance resolution; 1.0.
  • theta (FLOAT) - angle resolution; 0.0174 (one degree).
  • threshold (INT) - minimum votes to report a line.
  • srn, stn (FLOAT) - multi-scale Hough; leave 0.
  • min_theta, max_theta (FLOAT) - angle range, radians. Restricting this filters noise cheaply.

Output nparray is shape (N, 1, 3): [rho, theta, votes]. The optional lines input is the generator's out-parameter; leave it disconnected. To use the votes as a confidence score you'll need to slice the third column - another reminder that this pack hands you raw arrays, not high-level results.

When it's worth it

The vote count lets you set a relative bar - "keep the top 5 lines" or "drop anything with fewer votes than the median" - instead of a hard threshold you have to guess at. If you're extracting perspective or document boundaries and fighting noise, that's a real advantage. For simple "are there lines here?" checks, plain HoughLines_0 is enough and has fewer columns to deal with.

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 files.

Gotchas

The third column is in vote units, not percentages - its scale depends on your edge map's density, so don't compare vote counts across different images. And note there's no draw-the-lines helper (the author lists it as a TODO), so visualizing output means line_0 and some endpoint math.

Categoryimage/OpenCV

Inputs (9)

NameTypeDefaultDescription
imageNPARRAY
rhoFLOAT
thetaFLOAT
thresholdINT
srnFLOAT
stnFLOAT
min_thetaFLOAT
max_thetaFLOAT
linesoptNPARRAY

Outputs (1)

NameTypeDescription
nparrayNPARRAY