from PIL import Image
from ...FaceRotate import FaceRotate
from ...Morph import Morph
import cv2
from numpy import *
def merge():
source_path = '/root/Desktop/test.jpg'
yuantu = cv2.imread(source_path)
eye_path = '/root/Desktop/2111_A_real_A.png'
eye_pic = Image.open(eye_path)
eye_pic = eye_pic.resize((180, 180))
mph = Morph()
f = FaceRotate()
Bpoint = f.get_points(yuantu)
radius = 90
x0 = int(Bpoint[100][0])
y0 = int(Bpoint[100][1])
x1 = x0 - radius
y1 = y0 - radius
x2 = x0 + radius
y2 = y0 + radius
height = y2 - y1
width = x2 - x1
crop_img = yuantu[y1:y1 + height, x1:x1 + width]
cv2.imwrite('/root/Desktop/crop_img.jpg', crop_img)
crop_img_ = Image.open('/root/Desktop/result.jpg')
crop_img_new = Image.blend(crop_img_, eye_pic, 0.7)
yuantu_ = Image.open(source_path)
yuantu_.paste(crop_img_new, (x0, y0))
yuantu_.show()
yuantu_.save('/root/Desktop/result_new.jpg')
if __name__ == '__main__':
merge()
python-在固定点粘贴图片
最新推荐文章于 2023-02-09 17:34:58 发布