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://www.toymoban.com/news/detail-693835.html
https://github.com/deepinsight/insightface/tree/0cb03d391bb9335821448ce6e0519dbc870ec68d/examples/in_swapper文章来源地址https://www.toymoban.com/news/detail-693835.html
到了这里,关于insightface 换脸的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!