这篇文章主要利用python去做一个边缘提取的例子。
效果展示
要求
- python3
- binary images(二值图)
- python的opencv库; 如果没有可以直接
pip3 install opencv-python
代码
代码很简单,直接复制代码并且修改下文件路径,运行即可
# -*- coding: utf-8 -*-
import cv2
import os
def Edge_Extract(root):
img_root = os.path.join(root,'img_masks') # 修改为保存图像的文件名
edge_root = os.path.join(root,'img_edge') # 结果输出文件
if not os.path.exists(edge_root):
os.mkdir(edge_root)
file_names = os.listdir(img_root)
img_name = []
for name in file_names:
if not name.endswith('.png'):
assert "This file %s is not PNG&#