首页 > 解决方案 > Canny 边缘检测不适用于高斯模糊图像

问题描述

我正在尝试检测此车道图像上的边缘。首先使用高斯滤波器模糊图像并应用 Canny 边缘检测,但它只给出空白图像而没有检测边缘。

输入图像 在此处输入图像描述

我已经这样做了:

#imports
import matplotlib.pyplot as plt
import numpy as np
import cv2
import matplotlib.image as mpimg

image= mpimg.imread("Screenshot from Lane Detection Test Video 01.mp4.png")
image = image[:,:,:3]
image_g = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)

image_blurred = cv2.GaussianBlur(image_g, (3, 3), 0)
threshold_low = 50
threshold_high = 100
image_blurred = image_blurred.astype(np.uint8)
image_canny = cv2.Canny(image_blurred, threshold_low, threshold_high)
plt.imshow(image_canny,cmap='gray')  

标签: pythonopencvimage-processingcomputer-vision

解决方案


您应该始终检查您的数据。只需逐步运行脚本并检查中间值即可显示出问题所在:mpimg.imread将图像读取为值在 0 和 1 之间的浮点数组。模糊后,将其转换为uint8,这会将几乎所有值设置为 0。简单在投射之前将图像乘以 255 以uint8解决您的问题。


推荐阅读