diff --git a/facefusion/face_helper.py b/facefusion/face_helper.py index 3ef4b92f..8f6596f2 100644 --- a/facefusion/face_helper.py +++ b/facefusion/face_helper.py @@ -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 diff --git a/facefusion/processors/frame/modules/face_enhancer.py b/facefusion/processors/frame/modules/face_enhancer.py index 2e32973d..b2b28f5f 100644 --- a/facefusion/processors/frame/modules/face_enhancer.py +++ b/facefusion/processors/frame/modules/face_enhancer.py @@ -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(): diff --git a/facefusion/processors/frame/modules/face_swapper.py b/facefusion/processors/frame/modules/face_swapper.py index a109153c..f5cf25c2 100644 --- a/facefusion/processors/frame/modules/face_swapper.py +++ b/facefusion/processors/frame/modules/face_swapper.py @@ -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(): diff --git a/facefusion/typing.py b/facefusion/typing.py index d86fb1a0..255f6fe1 100644 --- a/facefusion/typing.py +++ b/facefusion/typing.py @@ -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]