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()