import cv2 as cv
import numpy as np
import matplotlib.pyplot as pltimg = cv.imread("../SampleImages/pomeranian.png", cv.IMREAD_GRAYSCALE)
print(img.shape)#图像Canny边缘检测
#cv.Canny(image, threshold1, threshold2[, edges[, apertureSize[, L2gradient ]]])
#image:原图
#threshold1: 阈值1(最小值)
#threshold2:阈值2(最大值)
#edges: 图像边缘信息
#apertureSize: sobel算子卷积核大小
#L2gradient: True: 使用L2范数做梯度计算
# False: 使用L1范数做梯度计算
#参考资料:https://blog.csdn.net/weixin_42272768/article/details/111244896?spm=1001.2101.3001.6650.8&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-8-111244896-blog-119821939.235%5Ev38%5Epc_relevant_default_base&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-8-111244896-blog-119821939.235%5Ev38%5Epc_relevant_default_base&utm_relevant_index=14
img_canny_thresholds1 = cv.Canny(img, 128, 140)
img_canny_thresholds2 = cv.Canny(img, 32, 128)#显示图像
fig,axes = plt.subplots(nrows=1, ncols=3, figsize=(15,15), dpi=100)
axes[0].set_title("Original")
axes[0].imshow(img, cmap=plt.cm.gray)
axes[1].set_title("Canny Min:128 Max:140")
axes[1].imshow(img_canny_thresholds1, cmap=plt.cm.gray)
axes[2].set_title("Canny Min:32 Max:128")
axes[2].imshow(img_canny_thresholds2, cmap=plt.cm.gray)