Pass kps direct to warp_face

This commit is contained in:
henryruhs 2023-10-16 22:51:24 +02:00
parent bc7910e79f
commit 1c3ccea849
4 changed files with 6 additions and 6 deletions

View File

@ -4,7 +4,7 @@ import cv2
import numpy
from cv2.typing import Size
from facefusion.typing import Face, Frame, Matrix, Template
from facefusion.typing import Frame, Kps, Matrix, Template
TEMPLATES : Dict[Template, numpy.ndarray[Any, Any]] =\
{
@ -27,8 +27,8 @@ TEMPLATES : Dict[Template, numpy.ndarray[Any, Any]] =\
}
def warp_face(target_face : Face, temp_frame : Frame, template : Template, size : Size) -> Tuple[Frame, Matrix]:
affine_matrix = cv2.estimateAffinePartial2D(target_face.kps, TEMPLATES[template], method = cv2.LMEDS)[0]
def warp_face(temp_frame : Frame, kps : Kps, template : Template, size : Size) -> Tuple[Frame, Matrix]:
affine_matrix = cv2.estimateAffinePartial2D(kps, TEMPLATES[template], method = cv2.LMEDS)[0]
crop_frame = cv2.warpAffine(temp_frame, affine_matrix, size)
return crop_frame, affine_matrix

View File

@ -143,7 +143,7 @@ def enhance_face(target_face: Face, temp_frame: Frame) -> Frame:
frame_processor = get_frame_processor()
model_template = get_options('model').get('template')
model_size = get_options('model').get('size')
crop_frame, affine_matrix = warp_face(target_face, temp_frame, model_template, model_size)
crop_frame, affine_matrix = warp_face(temp_frame, target_face.kps, model_template, model_size)
crop_frame = prepare_crop_frame(crop_frame)
frame_processor_inputs = {}
for frame_processor_input in frame_processor.get_inputs():

View File

@ -1,7 +1,6 @@
from typing import Any, List, Dict, Literal, Optional
from argparse import ArgumentParser
import threading
import numpy
import onnx
import onnxruntime
@ -148,7 +147,7 @@ def swap_face(source_face : Face, target_face : Face, temp_frame : Frame) -> Fra
model_template = get_options('model').get('template')
model_size = get_options('model').get('size')
source_face = prepare_source_face(source_face)
crop_frame, affine_matrix = warp_face(target_face, temp_frame, model_template, model_size)
crop_frame, affine_matrix = warp_face(temp_frame, target_face.kps, model_template, model_size)
crop_frame = prepare_crop_frame(crop_frame)
frame_processor_inputs = {}
for frame_processor_input in frame_processor.get_inputs():

View File

@ -2,6 +2,7 @@ from typing import Any, Literal, Callable, List, TypedDict, Dict
from insightface.app.common import Face
import numpy
Kps = numpy.ndarray[Any, Any]
Face = Face
Frame = numpy.ndarray[Any, Any]
Matrix = numpy.ndarray[Any, Any]