import cv2
import numpy as np
# Read images : src image will be cloned into dst
img = cv2.imread(r"E:\1\data\img\4.png") #背景影像
obj= cv2.imread(r"E:\1\data\img\2.png") #目标影像
# Create an all white mask
mask = 255 * np.ones(obj.shape, obj.dtype)
# The location of the center of the src in the dst
width, height, channels = img.shape
print(img.shape)
center = (height//2, width//2)
print(center)
# Seamlessly clone src into dst and put the results in output
normal_clone = cv2.seamlessClone(obj,img, mask,center , cv2.NORMAL_CLONE)
mixed_clone = cv2.seamlessClone(obj, img, mask,center , cv2.MIXED_CLONE)
# Write results
cv2.imwrite(r"E:\1\data\result\normal_clone.png", normal_clone)
cv2.imwrite(r"E:\1\data\result\mixed_clone.png", mixed_clone)
可以用于数据增强