blending_images_mask5.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:python-opencv2 作者: bunkahle 项目源码 文件源码
def composite(img1, img2, mask0):
    if mask0.shape[2] == 3:
        mask2 = cv2.cvtColor(mask0, cv2.COLOR_BGR2GRAY)
    else:
        mask2 = mask0[:]
    mask1 = np.ones((img1.shape[0], img1.shape[1], 3), np.uint8)
    mask1[..., 0] = mask2
    mask1[..., 1] = mask2
    mask1[..., 2] = mask2
    white = np.ones((img1.shape[0], img1.shape[1], 3), np.uint8)
    white[:] = (0, 0, 0)
    invmask = np.zeros((img1.shape[0], img1.shape[1], 3), np.uint8)
    invmask = cv2.absdiff(white, mask1)
    invmask = cv2.bitwise_not(invmask)
    output = np.zeros((img1.shape[0], img1.shape[1], 3), np.uint8)
    cv2.subtract(img2, invmask, dst=output)
    return output
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号