《OpenCV系列教程》
项目位置:OpenCV-Sample
代码位置:30-CutCircularArea.py
效果如下:
代码:
import cv2
import numpy as np
#加载图片
img = cv2.imread('./res/icon.png', cv2.IMREAD_UNCHANGED)
#获取图片尺寸
height, width = img.shape[:2]
height = int(height)
width = int(width)
#生成内显示模板
circleIn = np.zeros((height, width, 1), np.uint8)
circleIn = cv2.circle(circleIn, (width // 2, height // 2), min(height, width) // 2, (1), -1)
#实际使用中不需要写入文件
#np.savetxt('./out/circle.txt', circleIn[:, :, 0], fmt="%d", delimiter="")
#生成外显示模板
circleOut = circleIn.copy()
cir