苛刻和阈值

时间:2019-05-13 13:17:34

标签: opencv hough-transform houghlinesp

我正在使用opencv Houghlinesp来检测停车场中的线路。这是源图片

当我执行hough变换-p来检测线条时,我得到了这样的最终图像。

它确实检测到空白区域。有什么想法可以消除汽车顶部的这些嘈杂的线条吗?或对替代算法或方法的任何指导都受到高度赞赏。

img = cv.imread('Parking-Lot.jpg')
threshold=100
minLineLength = 60
rho=2
maxLineGap=20
theta = np.pi/180
edges = cv.Canny(img, 100, 200)
lines = cv.HoughLinesP(edges, rho, theta, threshold, np.array([]), minLineLength =minLineLength , maxLineGap=maxLineGap)
 for i in range(len(lines)):
    for line in lines[i]:
        cv.line(img, (line[0],line[1]), (line[2],line[3]), (0,255,0), 2)
cv2.imwrite("lines.jpg", img)

1 个答案:

答案 0 :(得分:0)

在应用边缘检测之前,可以通过对图像进行阈值处理来消除大部分噪点。这样,您将移除(大部分)汽车,并保留您感兴趣的空白行:

import cv2

img = cv2.imread('Parking-Lot.jpg')
threshold=100
minLineLength = 60
rho=2
maxLineGap=20
theta = np.pi/180

# here you convert the image to grayscale and then threshhold to binary
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
ret,thresh = cv2.threshold(gray,180,255,cv2.THRESH_BINARY)

# continue with the threshholded image instead
edges = cv2.Canny(thresh, 100, 200)
lines = cv2.HoughLinesP(edges, rho, theta, threshold, np.array([]), minLineLength =minLineLength , maxLineGap=maxLineGap)
for i in range(len(lines)):
  for line in lines[i]:
     cv2.line(img, (line[0],line[1]), (line[2],line[3]), (0,255,0), 2)
cv2.imwrite("lines.jpg", img)

这将为您提供更清洁的结果:

enter image description here

随时尝试使用阈值参数;您将需要找到一个排除大多数汽车的阈值,同时保留所有要检测的行。