opencv-python用原图和mask实现抠图

时间:2022-05-01 03:36:35

1、先上图

原图:test1.png

mask图:test-mask.png

结果图:mask.png

opencv-python用原图和mask实现抠图

 

2、代码部分

import cv2
from PIL import Image
import numpy as np

yuantu = "test1.png"
masktu = "test1-mask.png"

#使用opencv叠加图片
img1 = cv2.imread(yuantu)
img2 = cv2.imread(masktu)

alpha = 0.5
meta = 1 - alpha
gamma = 0
#cv2.imshow('img1', img1)
#cv2.imshow('img2', img2)
#image = cv2.addWeighted(img1,alpha,img2,meta,gamma)
image = cv2.add(img1, img2)

cv2.imshow('image', image)

cv2.waitKey(0)
cv2.destroyAllWindows()

cv2.imwrite("./mask.png",image)