Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reference face path argument #877

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion roop/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def parse_args() -> None:
program.add_argument('--skip-audio', help='skip target audio', dest='skip_audio', action='store_true')
program.add_argument('--many-faces', help='process every face', dest='many_faces', action='store_true')
program.add_argument('--reference-face-position', help='position of the reference face', dest='reference_face_position', type=int, default=0)
program.add_argument('--reference-face-path', help='reference face path', dest='face_reference_path')
program.add_argument('--reference-frame-number', help='number of the reference frame', dest='reference_frame_number', type=int, default=0)
program.add_argument('--similar-face-distance', help='face distance used for recognition', dest='similar_face_distance', type=float, default=0.85)
program.add_argument('--temp-frame-format', help='image format used for frame extraction', dest='temp_frame_format', default='png', choices=['jpg', 'png'])
Expand All @@ -62,6 +63,7 @@ def parse_args() -> None:
roop.globals.many_faces = args.many_faces
roop.globals.reference_face_position = args.reference_face_position
roop.globals.reference_frame_number = args.reference_frame_number
roop.globals.reference_face_path = args.face_reference_path
roop.globals.similar_face_distance = args.similar_face_distance
roop.globals.temp_frame_format = args.temp_frame_format
roop.globals.temp_frame_quality = args.temp_frame_quality
Expand All @@ -71,7 +73,6 @@ def parse_args() -> None:
roop.globals.execution_providers = decode_execution_providers(args.execution_provider)
roop.globals.execution_threads = args.execution_threads


def encode_execution_providers(execution_providers: List[str]) -> List[str]:
return [execution_provider.replace('ExecutionProvider', '').lower() for execution_provider in execution_providers]

Expand Down
1 change: 1 addition & 0 deletions roop/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
many_faces: Optional[bool] = None
reference_face_position: Optional[int] = None
reference_frame_number: Optional[int] = None
reference_face_path: Optional[str] = None
similar_face_distance: Optional[float] = None
temp_frame_format: Optional[str] = None
temp_frame_quality: Optional[int] = None
Expand Down
15 changes: 13 additions & 2 deletions roop/processors/frame/face_swapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,19 @@ def process_image(source_path: str, target_path: str, output_path: str) -> None:


def process_video(source_path: str, temp_frame_paths: List[str]) -> None:

if roop.globals.reference_face_path:
reference_face = get_one_face(cv2.imread(roop.globals.reference_face_path))
set_face_reference(reference_face)


if not roop.globals.many_faces and not get_face_reference():
reference_frame = cv2.imread(temp_frame_paths[roop.globals.reference_frame_number])
reference_face = get_one_face(reference_frame, roop.globals.reference_face_position)
# recorro los temp_frame_paths hasta que reference_face sea distinto de nulo.
for temp_frame_path in temp_frame_paths:
temp_frame = cv2.imread(temp_frame_path)
reference_face = get_one_face(temp_frame, roop.globals.reference_face_position)
if reference_face:
break

set_face_reference(reference_face)
roop.processors.frame.core.process_video(source_path, temp_frame_paths, process_frames)