我正在使用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)发布于 2019-05-13 22:55:47
在应用边缘检测之前,可以通过对图像进行阈值处理来消除大部分噪声。这样,您将删除(大部分)汽车,并保留您感兴趣的空白线条:
import cv2
import numpy as np
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)这将为您带来更清晰的结果:

您可以随意尝试阈值参数;您将需要找到一个阈值,该阈值可以排除大多数汽车,同时保留所有要检测的线路。
https://stackoverflow.com/questions/56113213
复制相似问题