使用cv2.bitwise_and制作掩膜

mask部分框住的是要展示出来的区域,代码如下:

res = img = cv2.imread(img_path)
mask = np.zeros(img.shape, dtype=np.uint8)
mask[upper:lower,left:right] = 255
res = cv2.bitwise_and(img, mask)
cv2.imshow("res", res)

 如果你出现这种bitwise_and运算之后res图像变成全黑的问题。检查upper,lower,left,right的值不能小于0。

使用cv2.bitwise_and制作掩膜_第1张图片

你可能感兴趣的:(python)