为什么在Canny Edge Detection之后无法绘制线条?

实际上,我对使用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)
cv2.imshow(‘test’,combo_image)

要查看它:HoughBundler

预期:expected img

Canny:canny img of wrong result

结果:wrong result

jamney 回答:为什么在Canny Edge Detection之后无法绘制线条?

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

本文链接:https://www.f2er.com/2339642.html

大家都在问