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

相关推荐
没有不重的名么几秒前
spyder使用教程
开发语言·python
Wonderful U1 分钟前
Python+Django实战|线上问卷与投票调研系统:自定义题型、问卷发布、链接分享、答卷收集、数据可视化、报表导出
python·信息可视化·django
Cloud_Shy61810 分钟前
解读《Effective Python 3rd Edition》:从练气到老魔(第五章 Item 36 - 39)
开发语言·人工智能·笔记·python
zmzb010311 分钟前
Python课后习题训练记录Day128
开发语言·python
AIFQuant12 分钟前
全球行情自动更新、多品种展示、性能优化实战指南
python·性能优化·金融·node.js·restful
蜂蜜黄油呀土豆15 分钟前
ReWOO 与 Plan-and-Execute:解耦的规划
python·ai·大模型
去码头整点薯条ing17 分钟前
某红书笔记接口逆向【x-s参数】
javascript·爬虫·python
xxie12379418 分钟前
参数Parameter,形参Formal Parameter,实参Actual Argument
开发语言·python
love530love20 分钟前
Hermes-Agent 本地化部署与详细交互式配置实战指南 [LM Studio + QQ ]
人工智能·windows·python·aigc·agent·hermes·hermes-agent
高洁0121 分钟前
人人可用的智能体来了
python·深度学习·机器学习·数据挖掘·知识图谱