这是我的管道,也许可以给您一些帮助。
首先,获取灰度图像并处理高斯模糊。
img = cv2.imread('src.png')
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
kernel_size = 5
blur_gray = cv2.GaussianBlur(gray,(kernel_size, kernel_size),0)
其次,进程边缘检测使用Canny。
low_threshold = 50
high_threshold = 150
edges = cv2.Canny(blur_gray, low_threshold, high_threshold)
然后,使用HoughLinesP来获取行。您可以调整参数以获得更好的性能。
rho = 1 # distance resolution in pixels of the Hough grid
theta = np.pi / 180 # angular resolution in radians of the Hough grid
threshold = 15 # minimum number of votes (intersections in Hough grid cell)
min_line_length = 50 # minimum number of pixels making up a line
max_line_gap = 20 # maximum gap in pixels between connectable line segments
line_image = np.copy(img) * 0 # creating a blank to draw lines on
# Run Hough on edge detected image
# Output "lines" is an array containing endpoints of detected line segments
lines = cv2.HoughLinesP(edges, rho, theta, threshold, np.array([]),
min_line_length, max_line_gap)
for line in lines:
for x1,y1,x2,y2 in line:
cv2.line(line_image,(x1,y1),(x2,y2),(255,0,0),5)
最后,在srcImage上画线。
# Draw the lines on the image
lines_edges = cv2.addWeighted(img, 0.8, line_image, 1, 0)
这是我的最后演出。
最终图片:
0
我正在尝试检测停车处的线路,如下所示。
我希望得到的是清晰的线条和交叉线上的(x,y)位置。但是,结果并不十分令人满意。
我猜这是由于两个主要原因:
一些行非常断或丢失。即使是人眼也可以清楚地识别它们。尽管HoughLine可以帮助连接一些缺失的线,但由于HoughLine有时会将不必要的线连接在一起,所以我还是希望手动进行。
有一些重复的行。
该工作的一般管道如下所示:
1.选择一些特定的颜色(白色或黄色)
2.重复膨胀和腐蚀,直到无法更改图像( 参考 )
3.应用canny过滤线并使用HoughLinesP来获取线
我不知道为什么在选择某些颜色的第一步之后,这些线就断掉了并且带有噪音。我认为在这一步中,我们应该做一些事情以使折线成为完整的,噪音较小的线。然后尝试应用某些方法来执行Canny和Hough线。有任何想法吗?