Hough Line Detection
Turn vote peaks into usable segments with endpoints. Standard Hough returns infinite lines; the probabilistic variant returns the dashes you actually draw.
Why Does This Exist?
The parent Hough transform finds infinite lines, but lane systems need the dash from here to there, and document scanners need four corners, not four infinities. Endpoints live in the image, not in parameter space, so a second mechanism must walk each winning line and report which stretches actually contain edge pixels. This page is that applied layer: standard versus probabilistic output and the three parameters that shape segments.
Stable keypoints help verify the returned geometry against repeatable landmarks. Round shapes belong to Hough circles.
Think of It Like This
Dashes on a foggy road
A road's center line is one infinite idea, but painters lay dashes with gaps the fog chews wider. An inspector walks the line's path, notes where paint actually survives, bridges gaps shorter than a stride, and ignores lone flecks. Minimum length, maximum gap, and the vote threshold are that inspector's three rules written as numbers.
It stops holding in fresh snow. When the whole road is buried, walking the path finds nothing and no rule recovers it, the same way maxLineGap cannot bridge occlusion longer than the visible remainder.
How It Actually Works
Infinite lines versus segments
Standard Hough returns peaks: direction plus offset, no endpoints. The probabilistic variant (Matas, Galambos, and Kittler) samples edge pixels, votes incrementally, and once a peak crosses threshold, walks the line in the image to collect supporting pixels into segments with endpoints. Same votes, plus a reporting pass that converts geometry into drawable output.
The three segment parameters
Threshold counts votes: a value of means at least edge pixels backed the line. Minimum line length drops short clutter: lane dashes survive at pixels while arrowheads and text strokes vanish. Maximum line gap bridges broken paint: a gap of pixels joins dashes across sensor noise but will not leap a -pixel occlusion. Tune in that order, threshold first, because the later two only filter what the first one admits.
Reading dashed-lane output
Expect each physical dash to return as one segment when gaps stay under the maximum and length clears the minimum. Fragmented output with three segments per dash means the gap allowance is too small or the threshold too high; mile-long segments spanning intersections mean the gap allowance is far too large. The segment count per expected marking is the tuning dial's readout.
Code
The standard probabilistic call shape on a Canny edge map:
import cv2
edges = cv2.Canny(gray, 50, 150)segments = cv2.HoughLinesP(edges, 1, 3.14159 / 180, 50, minLineLength=100, maxLineGap=10)# segments holds (x1, y1, x2, y2) rows; None means no line cleared the thresholdOne-pixel rho bins, one-degree theta bins, votes to qualify, dashes shorter than pixels dropped, gaps under bridged.
Watch Out For
Drowning in overlapping duplicate segments
Symptom: one lane edge returns forty near-identical segments, and downstream fitting wobbles between them. Thick edges vote from both flanks and neighbouring bins each cross threshold independently. Raise the threshold first, thin edges with a smaller Canny aperture, then merge near-collinear segments by angle and offset before fitting.
Bridging across real gaps with maxLineGap
Symptom: two collinear but distinct markings, like a stop line and a crosswalk stripe, fuse into one phantom segment. The gap parameter cannot tell paint gaps from semantic gaps. Keep it below the smallest meaningful separation in the scene, and split merged segments at gradient valleys when fusion still happens.
The Quick Version
- Standard Hough returns infinite lines; the probabilistic variant adds endpoints.
- Threshold sets the vote count a line needs; is a common starting point.
- Minimum length removes text strokes and specks; maximum gap bridges broken paint.
- Segments per expected marking is the tuning readout: fragments mean strict settings, mergers mean loose ones.
- Thick edges double-vote, so thin the edge map before blaming the parameters.