步骤 :噪声去除,计算图像梯度,非极大值抑制, 滞后阈值
cv2.Canny()可以完成以上几步。
import cv2 import numpy as np from matplotlib import pyplot as plt img = cv2.imread('messi5.jpg',0) edges = cv2.Canny(img,100,200) plt.subplot(121),plt.imshow(img,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()
来源:https://www.cnblogs.com/h694879357/p/12272609.html