abidrahmank / OpenCV2-Python-Tutorials

This repo contains tutorials on OpenCV-Python library using new cv2 interface
1.25k stars 887 forks source link

Hough Transform Example Code Does Not Produce the Plot Shown #251

Open valschmidt opened 4 years ago

valschmidt commented 4 years ago

The code example in py_houghlines.rst only plots the first line detected, not all the lines as shown in the "result" image.

This is not a big deal, but as a first time user caused me a bit of confusion.

The following should fix it:

for line in lines:
    rho = line[0][0]
    theta = line[0][1]
    a = np.cos(theta)
    b = np.sin(theta)
    x0 = a*rho
    y0 = b*rho
    x1 = int(x0 + 1000*(-b))
    y1 = int(y0 + 1000*(a))
    x2 = int(x0 - 1000*(-b))
    y2 = int(y0 - 1000*(a))