alphabetagamma
alphabetagamma

Reputation: 1

I've been trying to apply Hough transformation for line detection on an image of rails. But I'm facing problems

'apply canny'
edges = cv2.Canny(gray, 200, 200)
plt.rcParams["figure.figsize"] = (100, 100)
plt.imshow(edges)

result = img.copy()
lines= cv2.HoughLines(edges, 1, math.pi/180.0, 170, np.array([]), 0, 0)

a,b,c = lines.shape

for i in range(0, (a)):
    rho = lines[i][0][0]
    theta = lines[i][0][1]
    a = math.cos(theta)
    b = math.sin(theta)
    x0, y0 = a*rho, b*rho
    pt1 = ( int(x0+1000*(-b)), int(y0+1000*(a)) )
    pt2 = ( int(x0-1000*(-b)), int(y0-1000*(a)) )
    cv2.line(result, pt1, pt2, (0, 0, 255), 2, cv2.LINE_AA)
plt.imshow(result)
plt.rcParams["figure.figsize"] = (100, 100)
plt.show()

This is the code I have used for detecting the lines. I used it for vertical lines as well and It performed better.

This is the result I got

This is the raw image

Result after increasing the threshold

Canny Result

Upvotes: 0

Views: 70

Answers (0)

Related Questions