Nodes/comfyui_cv/CV Generalized Hough (Shape Template)
ComfyUI Node

CV Generalized Hough (Shape Template)

Finds an arbitrary SHAPE given as a template image (cv2.createGeneralizedHoughBallard / ...Guil). Where cv2_HoughCircles/HoughLines only fit shapes with a formula, the generalized transform builds an R-table from the template's edge points and lets every scene edge vote for where the shape's reference point must be - so it finds any outline you can draw, and it does it from EDGES, which means partial occlusion and texture/colour changes do not matter (unlike cv2_matchTemplate, which correlates raw pixels). Ballard finds translations only. Guil also searches scale and rotation, which multiplies the accumulator by every scale x angle step - keep the ranges TIGHT or it takes minutes. These are cv2 classes the raw wrappers cannot expose. Zero detections is a valid result (found=false).

By bmad4ever·Created 3 months ago·Updated 2 days ago· 0
CV Generalized Hough (Shape Template)
  • image
  • template
  • found
  • positions
  • scales
  • angles
  • votes
  • bboxes
  • count
methodBallard (position only, fast)
canny_low50
canny_high100
min_distance10
votes_threshold30
dp1.0
levels360
min_scale0.80
max_scale1.20
scale_step0.10
min_angle0
max_angle360
angle_step10.0
position_votes100
scale_votes100
angle_votes10000
Categoryimage/CV/features

Inputs (18)

NameTypeDefaultDescription
imageNPARRAY,IMAGEScene to search (converted to grayscale internally; edges are computed inside with the canny_* thresholds). 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.
templateNPARRAY,IMAGEImage of the shape to find. Its edges become the R-table, so a clean, tightly cropped outline works far better than a busy crop. 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.
methodCOMBOBallard (position only, fast)Ballard: translation only, one accumulator, fast. Guil: also scale and rotation, orders of magnitude slower - narrow min/max scale and angle before using it.
canny_lowINT501–255Lower Canny hysteresis threshold used for BOTH the template and the scene edges. Lower it if the shape's outline is faint.
canny_highINT1001–255Upper Canny hysteresis threshold; roughly 2-3x the lower one.
min_distanceFLOAT101–1000Minimum distance in pixels between two reported detections - this is what stops one shape being reported as a cluster of near-identical hits.
votes_thresholdINT301–100000Ballard only: how many edge points must vote for a position before it counts. LOWER it if nothing is found, raise it if the scene is full of false hits. It scales with the template's edge-pixel count.
dpoptFLOAT1.00.5–10Accumulator resolution divisor: 1.0 = same resolution as the image, 2.0 = half (coarser, faster, more tolerant).
levelsoptINT36010–3600Number of gradient-direction bins in the R-table.
min_scaleoptFLOAT0.800.05–10Guil only: smallest template scale to search.
max_scaleoptFLOAT1.200.05–10Guil only: largest template scale to search.
scale_stepoptFLOAT0.100.01–1Guil only: scale increment. Every extra step costs a full pass.
min_angleoptFLOAT00–360Guil only: smallest rotation in DEGREES to search.
max_angleoptFLOAT3600–360Guil only: largest rotation in degrees.
angle_stepoptFLOAT10.00.1–90Guil only: rotation increment in degrees. 1 degree over the full circle is 360 passes - start coarse.
position_votesoptINT1001–100000Guil only: vote threshold of the POSITION stage.
scale_votesoptINT1001–100000Guil only: vote threshold of the SCALE stage.
angle_votesoptINT100001–1000000Guil only: vote threshold of the ANGLE stage.

Outputs (7)

NameTypeDescription
foundBOOLEANTrue when at least one instance was detected - branch on it with 'Basic data handling: IfElse'.
positionsNPARRAYNx2 float32 centres of the detected shapes - feed 'CV Draw Points'.
scalesNPARRAY(N,) float32 template scale per detection (all 1.0 for Ballard, which does not search scale).
anglesNPARRAY(N,) float32 rotation in DEGREES per detection (all 0 for Ballard).
votesNPARRAYNx3 int32 accumulator votes (position, scale, angle) - the detection confidence. Sort or threshold on column 0 to keep the strongest hits.
bboxesBOUNDING_BOXOne {x, y, width, height, score, label} dict per detection: the template's size scaled by 'scales', centred on the position - feed the core 'Draw BBoxes'.
countINTHow many instances were detected; 0 is valid, not an error.