您现在的位置是:网站首页> 编程资料编程资料
Python cv.Canny()方法参数与使用方法_python_
2023-05-26
289人已围观
简介 Python cv.Canny()方法参数与使用方法_python_
函数原型与参数详解
OpenCV提供了cv.Canny()方法,该方法将输入的原始图像转换为边缘图像。
该方法的原型为:
cv.Canny(image, threshold1, threshold2[, edges[, apertureSize[, L2gradient]]]) -> edges cv.Canny(dx, dy, threshold1, threshold2[, edges[, L2gradient]]) -> edges
- image参数是array格式的输入图像。
- threshold1与threshold2分别是我们的下界阈值与上界阈值。
- apertureSize是用于查找图像梯度的Sobel核的大小,默认为3。
- L2gradient指定了求梯度幅值的公式,是一个布尔型变量,默认为False。当它为True时,使用L2,否则使用L1。
下面是具体代码:
def canny_detect(image_path, show=True): # 读取图像 image = cv2.imread(image_path, 0) # 获取结果 edges = cv2.Canny(image, 100, 200) if show: # 绘制原图 plt.subplot(121) plt.imshow(image, cmap='gray') plt.title('Original Image') plt.xticks([]) plt.yticks([]) # 绘制边缘图 plt.subplot(122) plt.imshow(edges, cmap='gray') plt.title('Edge Image') plt.xticks([]) plt.yticks([]) plt.show() return edges canny_detect('images/2.jpeg')效果


到此这篇关于Python cv.Canny()方法参数与使用方法的文章就介绍到这了,更多相关Python cv.Canny()方法内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!
您可能感兴趣的文章:
相关内容
- Python OpenCV 图像矫正的原理实现_python_
- Python OpenCV Canny边缘检测算法的原理实现详解_python_
- Python OpenCV Hough直线检测算法的原理实现_python_
- python中字典的常见操作总结2_python_
- python中字典的常见操作总结1_python_
- python中列表的常见操作梳理总结(二)_python_
- python中列表的常见操作梳理总结(一)_python_
- python中字符串的常见操作总结(二)_python_
- python中字符串的常见操作总结(一)_python_
- Pycharm5个非常有用的方法技巧_python_
