Canny边缘检测算法opencv实现

在OpenCV中要实现Canny检测使⽤的API:

canny = cv2.Canny(image, threshold1, threshold2)

参数:
image:灰度图,
threshold1: minval,较⼩的阈值将间断的边缘连接起来
threshold2: maxval,较⼤的阈值检测图像中明显的边缘

       

import cv2 as cv
import numpy as np
from matplotlib import pyplot as plt
# 1 图像读取
img = cv.imread('./image/horse.jpg',0)
# 2 Canny边缘检测
lowThreshold = 0
max_lowThreshold = 100
canny = cv.Canny(img, lowThreshold, max_lowThreshold)
# 3 图像展示
plt.figure(figsize=(10,8),dpi=100)
plt.subplot(121),plt.imshow(img,cmap=plt.cm.gray),plt.title('原图')
plt.xticks([]), plt.yticks([])
plt.subplot(122),plt.imshow(canny,cmap = plt.cm.gray),plt.title('Canny检测后结果
plt.xticks([]), plt.yticks([])
plt.show()

基本上一行代码就ok!

你可能感兴趣的:(opencv,算法,计算机视觉)