使用python opencv实现图像边缘检测
时间: 2023-10-08 14:06:44 浏览: 261
使用Python和OpenCV库可以很方便地实现图像边缘检测。下面是一个示例代码:
```python
import cv2
# 读取图像
image = cv2.imread('image.jpg', 0) # 使用灰度模式读取图像
# 进行边缘检测
edges = cv2.Canny(image, 100, 200) # 使用Canny算法进行边缘检测
# 显示结果
cv2.imshow('Original Image', image)
cv2.imshow('Edges', edges)
cv2.waitKey(0)
cv2.destroyAllWindows()
```
在这个示例中,我们首先使用`cv2.imread`函数读取图像,其中参数0表示以灰度模式读取图像。然后,我们使用`cv2.Canny`函数进行边缘检测,其中的参数100和200分别表示边缘梯度的最小和最大阈值。最后,使用`cv2.imshow`函数显示原始图像和边缘图像,并使用`cv2.waitKey`等待用户关闭窗口。
阅读全文
相关推荐
















