为什么在检测Canny Edge之后不能画线?

问题描述 投票:0回答:1

实际上,我对使用Computer Vision并不感兴趣。预先抱歉。

我想检测电车道的边缘。通常,该代码运行良好,但有时甚至无法画一条线。我不知道为什么。

cropped_Image函数只是裁剪当前帧的多边形区域。

display_lines函数绘制角度的绝对值在30到90之间的线。它使用cv2.line绘制线。

这里是代码:

_,frame = cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_RGB2GRAY)  # convert image to gray to be one layer
blur = cv2.GaussianBlur(gray, (1, 1), 0)  # to reduce noise in gray scale image
canny = cv2.Canny(blur, 150, 200, apertureSize=3)
cropped_image = region_of_interest(canny) # simply, it crops bottom  of image 
lines = cv2.HoughLinesP(cropped_image, 1, np.pi / 180, 100, np.array([]), 
minLineLength=5, maxLineGap=5)

hough_bundler = HoughBundler()
lines_merged = hough_bundler.process_lines(lines, cropped_image)
line_image = display_lines(frame, lines_merged)
combo_image = cv2.addWeighted(frame, 0.8, line_image, 1, 1)
cv2.imshow(‘test’, combo_image)

查看:HoughBundler

预期:expected img

Canny:canny img of wrong result

结果:wrong result

opencv edge-detection hough-transform imagefilter canny-operator
1个回答
0
投票

首先,我将从修复cv2.GuassianBlur()行开始。您使用了1x1内核,该内核什么也不做,您至少需要使用3x3内核。如果您想知道为什么1x1滤镜不起作用,请研究如何应用卷积。其次,我会使用Canny光圈大小来满足自己的需求。同样,在边缘检测之后,您可以将cv2.erode()与3x3或5x5内核一起使用,以免图像中出现折线。

© www.soinside.com 2019 - 2024. All rights reserved.