给定一张图片,求出这个图片的轮廓图,然后把轮廓图在另外单独图片上显示轮廓图。

def get_contours2(path):
    # 读取并显示原始图
    image_raw=cv2.imread(path,0)
    ret, image_raw = cv2.threshold(image_raw, 100, 255, cv2.THRESH_BINARY_INV)
    cv2.imshow('image_raw',image_raw)

    # 得到轮廓
    _, contours, hierarchy = cv2.findContours(image_raw, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
    
    # 生成同等尺寸的空白图
    height, width = image_raw.shape
    image_c = np.zeros((height, width), np.uint8)
    cv2.imshow('image_new',image_c)

    # 在新生成图上画轮廓
    cv2.drawContours(image_c, contours, -1, (255), 1)
    cv2.imshow('image_c',image_c)
    
    cv2.waitKey()

需要注意的是,cv2.threshold函数找到的是白色边缘的轮廓图

相关文章:

  • 2022-12-23
  • 2021-12-05
  • 2021-08-15
  • 2021-09-30
  • 2021-12-26
  • 2022-12-23
猜你喜欢
  • 2021-06-11
  • 2022-12-23
  • 2021-11-07
  • 2021-11-06
  • 2022-12-23
  • 2021-12-31
  • 2022-12-23
相关资源
相似解决方案