如何实现随机hough变换检测线?

时间:2017-11-21 05:16:45

标签: python opencv image-processing computer-vision

我能够使用Opencv的“cv2.HoughLines”来检测图像中的线条。但我想知道如何使用opencv python实现Randomized Hough Transform来检测线条,因为文献综述说RHT比HT更好。有人可以帮帮我吗?

这是我有enter image description here

的图片

使用以下代码后

lines = cv2.HoughLines(imgray, 1, np.pi / 180, 300)
for rho, theta in lines[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(imgray, (x1, y1), (x2, y2), (0, 0, 255), 2)

我得到了以下结果 enter image description here

1 个答案:

答案 0 :(得分:0)