Nodes/ComfyUI CV/cv2.HoughCirclesWithAccumulator
ComfyUI Node

cv2.HoughCirclesWithAccumulator

Circle detection with the confidence column attached

By bmad4ever·Created 3 months ago·Updated 14 days ago· 1
cv2.HoughCirclesWithAccumulator
  • image
  • nparray
◄methodHOUGH_GRADIENT►
◄dp0.0000►
◄minDist0.0000►
◄param1100.0000►
◄param2100.0000►
◄minRadius0►
◄maxRadius0►

The same circle detector, with the vote count kept. cv2.HoughCircles returns (x, y, radius) and throws away how many votes each circle earned; this variant keeps it, so each row is (x, y, radius, votes). One extra column, and it turns a yes/no detector into a rankable one.

Votes are the useful number here. A circle that collected 90 votes is a real rim; one that scraped by with 11 is the detector's opinion about texture. Rather than tuning param2 until the false positives disappear - which also deletes your genuine weak detections - you can set the threshold low, then sort or filter on the vote column and keep the top N. That is the same "and then rank it" habit the rest of the pack leans on.

How it works

Identical machinery to cv2.HoughCircles: Canny internally (the higher threshold is param1), a 3-D accumulator over centre-x, centre-y and radius, then circles above threshold extracted. The pairs of edges (minDist) and the accumulator resolution (dp) mean the same thing. The difference: the extra value propagated with each returned circle is the accumulator score, which is the strongest vote count in that circle's neighbourhood.

Which is why this node is the OpenCV 5.0 flavor of the API. If it is missing from your node list entirely, the pack's registry skipped it - it is generated from, and probed against, the installed cv2 build, and this pack's behavior is curated against opencv-contrib-python-headless~=5.0.0.93.

For method-specific parameter meanings, read the sibling node's semantics, because they are the shared trap. param2 is an accumulator vote threshold for HOUGH_GRADIENT and a perfectness measure between 0 and 1 for HOUGH_GRADIENT_ALT. dp starts at 0 in the widget and needs to be set explicitly - 1 for the default method, 1.5 for ALT. maxRadius <= 0 means "image's largest dimension"; a negative value makes the gradient method return centres with no radius at all. The dropdown lists all five Hough modes even though only the two gradient ones apply to circles.

Inputs and outputs

  • image - 8-bit single channel. A colour IMAGE link is converted to grayscale by the wrapper. Frame 0 of a batch - not in the pack's per-frame loop list.
  • method - HOUGH_GRADIENT (default) or HOUGH_GRADIENT_ALT.
  • dp, minDist - accumulator resolution and minimum centre separation.
  • param1 - Canny high threshold, default 100 (ALT wants ~300).
  • param2 - vote threshold, or perfectness for ALT.
  • minRadius, maxRadius - the constraint that usually decides whether this works at all.

Output is a single nparray with an extra column relative to the plain variant. Wire it into CV Draw Circles (which wants (x, y, r) triples and will ignore extra columns... check your layout, and slice with CV Take By Index if the shape upsets it), or - more interestingly - use the votes: cv2.sortIdx on the last column, CV Take By Index for the top N, CV Array To Text to read the numbers out, Preview CV Array to look at the distribution of votes in your scene.

Do not feed the votes to anything that expects coordinates. Because the extra column is appended, a naive (x, y, r) consumer reads one column over and draws circles in the wrong places - cheap to spot on a preview, easy to miss if you are only looking at the mask downstream.

Install

Manager → search comfyui_cv (bmad4ever), or by hand:

cd ComfyUI/custom_nodes
git clone https://github.com/bmad4ever/comfyui_cv
pip install "opencv-contrib-python-headless~=5.0.0.93"

Python ≥ 3.12 and a recent ComfyUI on the V3 API. The pack's only runtime dependency is that pinned OpenCV wheel; no models, no downloads.

When it goes wrong

  • Duplicate detections. Still minDist and the radius range, exactly as with the plain node. Votes do not fix that; they just tell you which of the duplicates won.
  • The everything-is-a-circle case. On noisy texture, thousands of weak circles pass a low param2. This is the node where that is manageable - keep them, sort by votes, take twenty.
  • Vote scales are not comparable across images or settings. They depend on dp, image size, and edge strength. Rank within one detection run, do not carry a numeric "votes > 40 means real" rule between projects.
  • Frame 0 only. Batch inputs collapse to the first frame; split the batch if you need per-frame circles.
  • Contrib/version drift. The registry is built from the installed cv2 and skips functions that build lacks. If some other custom pack replaces your OpenCV wheel, this node can vanish without an error message - tools/repair_opencv_contrib.py --check first, --apply if it flags anything.
Categoryimage/CV/low-level/cv2 H

Inputs (8)

NameTypeDefaultDescription
imageNPARRAY,IMAGE,MASK - - - Accepts a ComfyUI IMAGE/MASK directly (frame 0 of a batch) or an NPARRAY. Arithmetic ops (add, multiply, etc.) process the full IMAGE batch when both inputs have the same batch size.
methodCOMBOHOUGH_GRADIENT - - -
dpFLOAT0.0000-1e+38–1e+38 - - -
minDistFLOAT0.0000-1e+38–1e+38 - - -
param1optFLOAT100.0000-1e+38–1e+38 - - - Preset to the OpenCV default (100.0).
param2optFLOAT100.0000-1e+38–1e+38 - - - Preset to the OpenCV default (100.0).
minRadiusoptINT0-2147483648–2147483647 - - - Preset to the OpenCV default (0).
maxRadiusoptINT0-2147483648–2147483647 - - - Preset to the OpenCV default (0).

Outputs (1)

NameTypeDescription
nparrayNPARRAY—