我想从图像中移除遮罩,并用背景色替换它。在这个例子中,我想把克里斯蒂亚诺的脸从原图上去掉
这就是我现在使用的代码
# load background (could be an image too)
bk = np.full(frame.shape, 255, dtype=np.uint8) # white bk
# blur the mask to help remove noise, then apply the
# mask to the frame
skinMask = cv2.GaussianBlur(skinMask, (3, 3), 0)
#skinMask = cv2.bitwise_not(skinMask)
skin = cv2.bitwise_and(frame, frame, mask = skinMask)
cv2.imshow("mask", skin)
mask = cv2.bitwise_not(skinMask)
bk_masked = cv2.bitwise_and(bk, bk, mask=mask)
# combine masked foreground and masked background
final = cv2.bitwise_or(bk_masked,skin)
我不知道你的面具到底是什么形状,但交换操作应该是非常直接的。在
这将生成一个图像,背景值将替换遮罩值的正部分。在
相关问题 更多 >
编程相关推荐