python - 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')
解决方案
您应该始终检查您的数据。只需逐步运行脚本并检查中间值即可显示出问题所在:mpimg.imread
将图像读取为值在 0 和 1 之间的浮点数组。模糊后,将其转换为uint8
,这会将几乎所有值设置为 0。简单在投射之前将图像乘以 255 以uint8
解决您的问题。
推荐阅读
- asp.net-core - Kestrel / IIS 托管与 ASP.Net Core 2.2 / 3.0 应用程序切换
- jquery - 剃刀控制器值为空
- java - IntelliJ IDEA - 直接在 IDE 中运行时,Java 工具 premain 会被调用两次
- android - android中的分段圆形进度条
- spring - 使用 Spring Security 保护不同用户的不同端点
- python - 如何使用 Python For-loop 编写文件
- center - 单击时如何在 Mapbox GL JS 地图上居中标记?
- google-bigquery - 将 ARRAY_TO_STRING 与整数数组一起使用
- asp.net-core - Api 使用子域而不是完整的网站 url
- flutter - 使用 Firestore 从列表创建子集合的有效方法