Pass kps direct to warp_face
This commit is contained in:
parent
bc7910e79f
commit
1c3ccea849
@ -4,7 +4,7 @@ import cv2
|
|||||||
import numpy
|
import numpy
|
||||||
from cv2.typing import Size
|
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]] =\
|
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]:
|
def warp_face(temp_frame : Frame, kps : Kps, template : Template, size : Size) -> Tuple[Frame, Matrix]:
|
||||||
affine_matrix = cv2.estimateAffinePartial2D(target_face.kps, TEMPLATES[template], method = cv2.LMEDS)[0]
|
affine_matrix = cv2.estimateAffinePartial2D(kps, TEMPLATES[template], method = cv2.LMEDS)[0]
|
||||||
crop_frame = cv2.warpAffine(temp_frame, affine_matrix, size)
|
crop_frame = cv2.warpAffine(temp_frame, affine_matrix, size)
|
||||||
return crop_frame, affine_matrix
|
return crop_frame, affine_matrix
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ def enhance_face(target_face: Face, temp_frame: Frame) -> Frame:
|
|||||||
frame_processor = get_frame_processor()
|
frame_processor = get_frame_processor()
|
||||||
model_template = get_options('model').get('template')
|
model_template = get_options('model').get('template')
|
||||||
model_size = get_options('model').get('size')
|
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)
|
crop_frame = prepare_crop_frame(crop_frame)
|
||||||
frame_processor_inputs = {}
|
frame_processor_inputs = {}
|
||||||
for frame_processor_input in frame_processor.get_inputs():
|
for frame_processor_input in frame_processor.get_inputs():
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
from typing import Any, List, Dict, Literal, Optional
|
from typing import Any, List, Dict, Literal, Optional
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
import numpy
|
import numpy
|
||||||
import onnx
|
import onnx
|
||||||
import onnxruntime
|
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_template = get_options('model').get('template')
|
||||||
model_size = get_options('model').get('size')
|
model_size = get_options('model').get('size')
|
||||||
source_face = prepare_source_face(source_face)
|
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)
|
crop_frame = prepare_crop_frame(crop_frame)
|
||||||
frame_processor_inputs = {}
|
frame_processor_inputs = {}
|
||||||
for frame_processor_input in frame_processor.get_inputs():
|
for frame_processor_input in frame_processor.get_inputs():
|
||||||
|
@ -2,6 +2,7 @@ from typing import Any, Literal, Callable, List, TypedDict, Dict
|
|||||||
from insightface.app.common import Face
|
from insightface.app.common import Face
|
||||||
import numpy
|
import numpy
|
||||||
|
|
||||||
|
Kps = numpy.ndarray[Any, Any]
|
||||||
Face = Face
|
Face = Face
|
||||||
Frame = numpy.ndarray[Any, Any]
|
Frame = numpy.ndarray[Any, Any]
|
||||||
Matrix = numpy.ndarray[Any, Any]
|
Matrix = numpy.ndarray[Any, Any]
|
||||||
|
Loading…
Reference in New Issue
Block a user