Python+OpenCV 掩膜mask及位运算

图像圆形掩膜: 


import numpy as np
import argparse
import cv2

# 构建参数解析器
img = np.zeros([100,100,3],np.uint8)
img[:,:,:]=255

img=cv2.ellipse(img, (50,50), (35, 25), 0, 0, 360, (0, 0, 0), -1)
# img = cv2.circle(img, (100, 100), 50, (0, 0, 0), -1)

img_ = cv2.GaussianBlur(img,(121,121),0)


# 创建圆形区域,填充白色255
circle = np.zeros(img_.shape[:2], dtype = "uint8")
cv2.circle(circle, (50,50), 40, 255, -1)
# cv2.imshow("Circle", circle)

mask = circle
# cv2.imshow("Mask", mask)

# Apply out mask -- notice how only the person in the image is cropped out
masked = cv2.bitwise_and(img_, img_, mask=mask)
cv2.imshow("Mask Applied to Image", masked)
cv2.waitKey(0)

原文:http://blog.csdn.net/eric_pycv/article/details/72887748

问题引入

你可能感兴趣的:(python宝典,opencv,图像掩摸)