picassooo

代码如下:

import cv2
import numpy as np

def FillHole(mask):
    contours, hierarchy = cv2.findContours(mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
    len_contour = len(contours)
    contour_list = []
    for i in range(len_contour):
        drawing = np.zeros_like(mask, np.uint8)  # create a black image
        img_contour = cv2.drawContours(drawing, contours, i, (255, 255, 255), -1)
        contour_list.append(img_contour)

    out = sum(contour_list)
    return out

if __name__ == \'__main__\':
    mask_in = cv2.imread(\'C:\\Users\\admin\\Desktop\\mask_in.tif\', 0)
    mask_out = FillHole(mask_in)
    cv2.imwrite(\'C:\\Users\\admin\\Desktop\\mask_out.tif\', mask_out)

效果如下:

      

     孔洞填充前                       孔洞填充后

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2021-05-19
  • 2021-06-29
  • 2022-02-04
  • 2021-06-11
  • 2021-12-05
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-10-21
  • 2021-12-05
  • 2022-01-21
  • 2021-08-10
  • 2022-01-03
  • 2021-04-24
相关资源
相似解决方案