Ask Your Question
0

Unable to understand implementation of Hough Transform

asked 2016-07-01 01:41:57 -0600

u93482963 gravatar image

updated 2016-07-13 10:27:21 -0600

I copied the same code as given in this tutorial for hough lines : tutorial. This is my output: C:\fakepath\houghlines3.jpg

I do not understand why I am getting a different output.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-07-19 11:32:15 -0600

zhanmer gravatar image

updated 2016-07-19 15:05:58 -0600

I came across the same issue, it seems something has changed since that tutorial was created.

I used the following code to get it working.

HoughLines

lines = cv2.HoughLines(edges, 1, np.pi/180, 200)
for i in range(len(lines)):
    rho, theta = lines[i][0]
    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))

    cv2.line(img, (x1, y1), (x2 ,y2), (0, 0, 255), 2)

HoughLinesP

lines = cv2.HoughLinesP(edges, 1, np.pi/180, 200)
for i in range(len(lines)):
    x1, y1, x2, y2 = lines[i][0]
    cv2.line(img, (x1, y1), (x2, y2), (0, 0, 255), 2)
edit flag offensive delete link more

Comments

Hello @zhanmer, are you up to supplying a pull request with the suggested fix to the library? If not let me know and I will do it for you!

StevenPuttemans gravatar imageStevenPuttemans ( 2016-07-20 04:58:38 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-07-01 01:41:57 -0600

Seen: 294 times

Last updated: Jul 19 '16