opencv-python学习(十六):Canny边缘检测算法

def edge_image(image):
    blurred = cv.GaussianBlur(image, (3, 3), 0)
    gray = cv.cvtColor(blurred, cv.COLOR_RGB2GRAY)
    xgrad = cv.Sobel(gray, cv.CV_16SC1, 1, 0)
    ygrad = cv.Sobel(gray, cv.CV_16SC1, 0, 1)
    edge_output = cv.Canny(xgrad, ygrad, 50, 150)
    cv.imshow("cannyShape", edge_output)
    dst = cv.bitwise_and(image, image, mask=edge_output)
    cv.imshow("color边缘", dst)

src = cv.imread('./static/image/windows.jpg')
cv.imshow("image", src)
edge_image(src)
cv.waitKey(0)
cv.destroyAllWindows()

运行效果:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_33538887/article/details/119114291