From acde1d7681efe0707e4c6c142bcb971be63dc706 Mon Sep 17 00:00:00 2001 From: chris Date: Wed, 31 May 2023 13:54:41 -0400 Subject: [PATCH] - added UI elements - cleaned up some code --- core/config.py | 3 +-- core/processor.py | 8 +++++--- run.py | 19 ++++++++++++++----- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/core/config.py b/core/config.py index de1894d..a31de4b 100644 --- a/core/config.py +++ b/core/config.py @@ -21,8 +21,7 @@ def get_face(img_data): def get_all_faces(img_data): - analysed = face_analyser.get(img_data) try: - return analysed + return get_face_analyser().get(img_data) except IndexError: return None diff --git a/core/processor.py b/core/processor.py index 8061d30..4a42057 100644 --- a/core/processor.py +++ b/core/processor.py @@ -2,7 +2,7 @@ import os import cv2 import insightface import core.globals -from core.config import get_face +from core.config import get_face, get_all_faces FACE_SWAPPER = None @@ -19,13 +19,15 @@ def process_video(source_img, frame_paths): source_face = get_face(cv2.imread(source_img)) for frame_path in frame_paths: frame = cv2.imread(frame_path) + + swapper = get_face_swapper() try: if core.globals.all_faces: all_faces = get_all_faces(frame) result = frame for singleFace in all_faces: if singleFace: - result = get_face_swapper().get(result, singleFace, source_face, paste_back=True) + result = swapper.get(result, singleFace, source_face, paste_back=True) print('.', end='', flush=True) else: print('S', end='', flush=True) @@ -33,7 +35,7 @@ def process_video(source_img, frame_paths): else: face = get_face(frame) if face: - result = get_face_swapper().get(frame, face, source_face, paste_back=True) + result = swapper.get(frame, face, source_face, paste_back=True) cv2.imwrite(frame_path, result) print('.', end='', flush=True) else: diff --git a/run.py b/run.py index 03b7bb9..fd8b981 100755 --- a/run.py +++ b/run.py @@ -157,6 +157,10 @@ def toggle_fps_limit(): args['keep_fps'] = limit_fps.get() != True +def toggle_all_faces(): + core.globals.all_faces = True if all_faces.get() == 1 else False + + def toggle_keep_frames(): args['keep_frames'] = keep_frames.get() != True @@ -261,16 +265,21 @@ if __name__ == "__main__": target_button = tk.Button(window, text="Select a target", command=select_target, bg="#2d3436", fg="#74b9ff", highlightthickness=4, relief="flat", highlightbackground="#74b9ff", activebackground="#74b9ff", borderwidth=4) target_button.place(x=360,y=320,width=180,height=80) + # All faces checkbox + all_faces = tk.IntVar() + all_faces_checkbox = tk.Checkbutton(window, relief="groove", activebackground="#2d3436", activeforeground="#74b9ff", selectcolor="black", text="Process all faces in frame", fg="#dfe6e9", borderwidth=0, highlightthickness=0, bg="#2d3436", variable=all_faces, command=toggle_all_faces) + all_faces_checkbox.place(x=30,y=500,width=240,height=31) + # FPS limit checkbox limit_fps = tk.IntVar() - fps_checkbox = tk.Checkbutton(window, relief="groove", activebackground="#2d3436", activeforeground="#74b9ff", selectcolor="black", text="Limit FPS to 30", fg="#dfe6e9", borderwidth=0, highlightthickness=0, bg="#2d3436", variable=limit_fps, command=toggle_fps_limit) - fps_checkbox.place(x=30,y=500,width=240,height=31) + fps_checkbox = tk.Checkbutton(window, relief="groove", activebackground="#2d3436", activeforeground="#74b9ff", selectcolor="black", text="Limit FPS to 30 ", fg="#dfe6e9", borderwidth=0, highlightthickness=0, bg="#2d3436", variable=limit_fps, command=toggle_fps_limit) + fps_checkbox.place(x=30,y=475,width=240,height=31) fps_checkbox.select() # Keep frames checkbox keep_frames = tk.IntVar() - frames_checkbox = tk.Checkbutton(window, relief="groove", activebackground="#2d3436", activeforeground="#74b9ff", selectcolor="black", text="Keep frames dir", fg="#dfe6e9", borderwidth=0, highlightthickness=0, bg="#2d3436", variable=keep_frames, command=toggle_keep_frames) - frames_checkbox.place(x=37,y=450,width=240,height=31) + frames_checkbox = tk.Checkbutton(window, relief="groove", activebackground="#2d3436", activeforeground="#74b9ff", selectcolor="black", text="Keep frames dir ", fg="#dfe6e9", borderwidth=0, highlightthickness=0, bg="#2d3436", variable=keep_frames, command=toggle_keep_frames) + frames_checkbox.place(x=30,y=450,width=240,height=31) # Start button start_button = tk.Button(window, text="Start", bg="#f1c40f", relief="flat", borderwidth=0, highlightthickness=0, command=lambda: [save_file(), start()]) @@ -279,5 +288,5 @@ if __name__ == "__main__": # Status label status_label = tk.Label(window, width=580, justify="center", text="Status: waiting for input...", fg="#2ecc71", bg="#2d3436") status_label.place(x=10,y=640,width=580,height=30) - + window.mainloop()