Bootstrap

python 掩模mask

本例中通过定义一个正方形和一个圆形,将它们分别进行与、或、非、异或三种运算,可以实现两种掩模形状的组合。

import numpy as np
import cv2

image = cv2.imread("img/img.jpg")
# 创建矩形区域,填充白色255
rectangle = np.zeros(image.shape[0:2], dtype = "uint8")
cv2.rectangle(rectangle, (25, 25), (275, 275), 255, -1)
cv2.imshow("Rectangle", rectangle)
 
# 创建圆形区域,填充白色255
circle = np.zeros(ima
;