读取图片,并在新图片上生成轮廓图

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

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函数找到的是白色边缘的轮廓图ui

相关文章
相关标签/搜索