insightface 换脸

复制代码
import datetime
import numpy as np
import os
import os.path as osp
import glob
import cv2
import insightface
from insightface.app import FaceAnalysis
from insightface.data import get_image as ins_get_image


assert insightface.__version__>='0.7'

if __name__ == '__main__':
    初始化
    app = FaceAnalysis(name='buffalo_l')
    app.prepare(ctx_id=0, det_size=(640, 640))
    swapper = insightface.model_zoo.get_model('inswapper_128.onnx', download=True, download_zip=True)


    img = ins_get_image('t1')
    faces = app.get(img)
    faces = sorted(faces, key = lambda x : x.bbox[0])
    assert len(faces)==6
    source_face = faces[2]
    res = img.copy()
    for face in faces:
        res = swapper.get(res, face, source_face, paste_back=True)
    cv2.imwrite("./t1_swapped.jpg", res)
    res = []
    for face in faces:
        _img, _ = swapper.get(img, face, source_face, paste_back=False)
        res.append(_img)
    res = np.concatenate(res, axis=1)
    cv2.imwrite("./t1_swapped2.jpg", res)

参考:

https://github.com/deepinsight/insightface/tree/0cb03d391bb9335821448ce6e0519dbc870ec68d/examples/in_swapper

相关推荐
hui函数3 分钟前
Python全栈(基础篇)——Day13:后端内容(模块详解)
后端·python
西柚小萌新13 分钟前
【深入浅出PyTorch】--7.2.PyTorch可视化2
人工智能·pytorch·python
java1234_小锋26 分钟前
TensorFlow2 Python深度学习 - 使用TensorBoard可视化数据
python·深度学习·tensorflow·tensorflow2
源来是大数据的菜鸟28 分钟前
基于Multi-Agent开发的SmartCare系统自动化运维管家
python·运维开发
该用户已不存在40 分钟前
我的Python工具箱,不用加班的秘密
前端·后端·python
星期天要睡觉1 小时前
计算机视觉(opencv)——实时颜色检测
人工智能·python·opencv·计算机视觉
aerror1 小时前
json转excel xlsx文件
开发语言·python·json
查士丁尼·绵2 小时前
笔试-士兵过河
python
weixin_46682 小时前
编程之python基础
开发语言·python
打酱油的;2 小时前
【无标题】
爬虫·python·php