python-在固定点粘贴图片

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()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值