Skip to main content

图像边缘检测

图像边缘检测1、实现原理2、实现效果3、实现代码

1、实现原理

使用cv2.Canny() 函数对图像进行边缘检测。

2、实现效果

x cd ~/opencv x python3 10.image_edge.py

注意:选中图片按q可以退出程序!

image-20250106161749169

3、实现代码

import cv2 def edge_detection(input_path, output_path, threshold1, threshold2): image = cv2.imread(input_path, cv2.IMREAD_GRAYSCALE) if image is None: print("Error: Unable to open image file.") return edges = cv2.Canny(image, threshold1, threshold2) if cv2.imwrite(output_path, edges): print(f"Image saved to {output_path}") cv2.imshow('Image Preview', cv2.imread(output_path)) cv2.waitKey(0) cv2.destroyAllWindows() else: print("Error: Unable to save image file.") edge_detection('/home/jetson/opencv/images/yahboom_logo.png', \ '/home/jetson/opencv/images/yahboom_logo_edge.png', \ 100, 200)