Canny 算法

Canny 算法是一种更新的边缘检测器,设计为信号处理问题。在 OpenCV 中,它输出标记检测到的边缘的二进制图像。

Python:

import cv2
import sys

# Load the image file
image = cv2.imread('image.png')

# Check if image was loaded improperly and exit if so
if image is None:
    sys.exit('Failed to load image')

# Detect edges in the image. The parameters control the thresholds
edges = cv2.Canny(image, 100, 2500, apertureSize=5)

# Display the output in a window
cv2.imshow('output', edges)
cv2.waitKey()