【问题标题】:Why cannot draw lines after Canny Edge Detection?为什么 Canny 边缘检测后不能画线?
【发布时间】:2020-09-02 12:31:32
【问题描述】:

实际上,我不喜欢使用计算机视觉。提前抱歉。

我想检测电车车道的边缘。大多数情况下,代码运行良好,但有时它甚至无法画线。我不知道为什么。

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

【问题讨论】:

  • 结果照片中的红线表示线的角度小于30。

标签: opencv edge-detection hough-transform imagefilter canny-operator


【解决方案1】:

首先我要修复 cv2.GuassianBlur() 行。您使用了一个 1x1 内核,它什么都不做,您至少需要使用一个 3x3 内核。如果您想知道为什么 1x1 过滤器不起作用,请查看如何应用卷积。 其次,我会使用 Canny 光圈大小来满足我的需要。此外,在边缘检测之后,您可以将 cv2.erode() 与 3x3 或 5x5 内核一起使用,这样您就不会在图像中看到虚线。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-03-30
    • 2017-04-22
    • 1970-01-01
    • 1970-01-01
    • 2019-01-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多