Python 实现人脸融合与虚拟人物生成

Python 实现人脸融合与虚拟人物生成,只需要准备两张人脸图片,最好是大头照,这样融合效果才会更好。

实现步骤:

(1)准备两张图片(人脸)

(2)准备好如下过程Python利用paddlehub实现批量抠图和更换证件照背景底色_SmartGridequation的博客-优快云博客

(3)利用OpenCV去除图的单一颜色

Python 去除图片中多种颜色或者单一颜色_SmartGridequation的博客-优快云博客

融合人脸函数代码如下:

import numpy as np
import cv2
import dlib
from scipy.spatial import Delaunay
predictor_model = 'shape_predictor_68_face_landmarks.dat'

#-i https://mirrors.aliyun.com/pypi/simple/

def get_points(image):  # 用 dlib 来得到人脸的特征点
    global detected_face
    face_detector = dlib.get_frontal_face_detector()  # 正向人脸检测器,进行人脸检测,提取人脸外部矩形框
    face_pose_predictor = dlib.shape_predictor(predictor_model)
    try:
        detected_face = face_detector(image, 1)[0]
    except:
        print('No face detected in image {}'.format(image))
    pose_landmarks = face_pose_predictor(image, detected_face)  # 获取landmark
    points = []
    for p in pose_landmarks.parts():
        points.append([p.x, p.y])

    # 加入四个顶点和四条边的中点
    x = image.shape[1] - 1
    y = image.shape[0] - 1
    points.append([0, 0])
    points.append([x // 2, 0])
    points.append([x, 0])
    points.append([x, y // 2])
    points.append([x, y])
    points.append([x // 2, y])
    points.append([0, y])
    points.append([0, y // 2])

    return np.array(points)


def get_triangles(points):  #  在特征点上使用 Delaunay 三角剖分,将点集连接成一定大小的三角形,且分配要相对合理,才能呈现出漂亮的三角化
    return Delaunay(points).simplices


def affine_trans
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

「已注销」

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值