import cv2
import numpy as np
from get_mask import get_simple_mask #获取mask
img1 = cv2.imread('a.jpg')
img2 = cv2.imread('b.jpg')
m1,m2 = get_simple_mask(img1, img2) # 获取的mask最好进行erode m [0-255]
a = cv2.detail.Blender_createDefault(2)
a.prepare(np.array([0, 0, img1.shape[1], img1.shape[0]]))
a.feed(img1, m1, np.array([0, 0])) # 多张图片就多次feed
a.feed(img2, m2, np.array([0, 0]))
dst, dst_mask = a.blend(None, None)
dst[dst>255]=255
dst[dst<0]=0
dst = dst.astype(np.uint8) # !!!!!!别忘了,不然就是灰度图
cv2.imshow('i1',img1)
cv2.imshow('i2',img2)
cv2.imshow('out',dst)
cv2.waitKey()
img1 img2
out
ref