Skip to content

Cv2.HoughLines

How does it work?

As you know, a line in the image space can be expressed with two variables. For example:

Hough_Lines_Tutorial_Theory_0.jpg

For Hough Transforms, we will express lines in the Polar system. Hence, a line equation can be written as:

\(y = (−cosθ * sinθ)x + (r sinθ)\)

Synopsis

with the arguments:

cv2.HoughLines(image, rho, theta, threshold[, lines[, srn[, stn]]]) -> lines
cv2.HoughLines2(image, storage, method, rho, theta, threshold, param1=0, param2=0) -> lines
  • image - 8-bit, single-channel binary source image. The image may be modified by the function.
  • lines - Output vector of lines. Each line is represented by a two-element vector (\rho, \theta) . \rho is the distance from the coordinate origin (0,0) (top-left corner of the image). \theta is the line rotation angle in radians ( 0 \sim \textrm{vertical line}, \pi/2 \sim \textrm{horizontal line} ).
  • rho - Distance resolution of the accumulator in pixels.
  • theta - Angle resolution of the accumulator in radians.
  • threshold - Accumulator threshold parameter. Only those lines are returned that get enough votes ( >\texttt{threshold} ).
  • srn - For the multi-scale Hough transform, it is a divisor for the distance resolution rho . The coarse accumulator distance resolution is rho and the accurate accumulator resolution is rho/srn . If both srn=0 and stn=0 , the classical Hough transform is used. Otherwise, both these parameters should be positive.
  • stn - For the multi-scale Hough transform, it is a divisor for the distance resolution theta.
  • method - One of the following Hough transform variants:
    • CV_HOUGH_STANDARD classical or standard Hough transform. Every line is represented by two floating-point numbers (\rho, \theta) , where \rho is a distance between (0,0) point and the line, and \theta is the angle between x-axis and the normal to the line. Thus, the matrix must be (the created sequence will be) of CV_32FC2 type
    • CV_HOUGH_PROBABILISTIC probabilistic Hough transform (more efficient in case if the picture contains a few long linear segments). It returns line segments rather than the whole line. Each segment is represented by starting and ending points, and the matrix must be (the created sequence will be) of the CV_32SC4 type.
    • CV_HOUGH_MULTI_SCALE multi-scale variant of the classical Hough transform. The lines are encoded the same way as CV_HOUGH_STANDARD.
  • param1 - First method-dependent parameter:
    • For the classical Hough transform, it is not used (0).
    • For the probabilistic Hough transform, it is the minimum line length.
    • For the multi-scale Hough transform, it is srn.
  • param2 - Second method-dependent parameter:
    • For the classical Hough transform, it is not used (0).
    • For the probabilistic Hough transform, it is the maximum gap between line segments lying on the same line to treat them as a single line segment (that is, to join them).
    • For the multi-scale Hough transform, it is stn.

See also

Favorite site