Ask Your Question

zhanmer's profile - activity

2016-07-19 15:05:58 -0600 received badge  Editor (source)
2016-07-19 11:46:58 -0600 answered a question Unable to understand implementation of Hough Transform

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)