Canny算法提取图像边缘后,用闭运算连接断掉的线

实验:

 1 # Writer : wojianxinygcl@163.com
 2 # Date   : 2020.3.22
 3 import cv2 as cv
 4 import numpy as np
 5 
 6 image = cv.imread("../bird.png")
 7 gray = cv.cvtColor(image,cv.COLOR_RGB2GRAY)
 8 
 9 # 80以下为0,210以上为255,中间使用 8-近邻算法确定像素值
10 edges = cv.Canny(gray,80,210)
11 
12 # 使用闭运算连接中断的图像前景,迭代运算三次
13 result = cv.morphologyEx(edges,cv.MORPH_CLOSE,kernel=(3,3),iterations=3)
14 
15 cv.imshow('After Canny',edges)
16 cv.imshow('After Morphology Close',result)
17 cv.waitKey(0)
18 cv.destroyAllWindows()

 


实验结果:


Canny算法结果(左)、Canny算法后闭运算结果(右) ↑

    如果你觉得对你有帮助,帮忙点赞哦!

posted on 2020-03-22 14:11  我坚信阳光灿烂  阅读(2555)  评论(0编辑  收藏  举报

导航