- added UI elements
- cleaned up some code
This commit is contained in:
parent
7bfdd73783
commit
acde1d7681
@ -21,8 +21,7 @@ def get_face(img_data):
|
|||||||
|
|
||||||
|
|
||||||
def get_all_faces(img_data):
|
def get_all_faces(img_data):
|
||||||
analysed = face_analyser.get(img_data)
|
|
||||||
try:
|
try:
|
||||||
return analysed
|
return get_face_analyser().get(img_data)
|
||||||
except IndexError:
|
except IndexError:
|
||||||
return None
|
return None
|
||||||
|
@ -2,7 +2,7 @@ import os
|
|||||||
import cv2
|
import cv2
|
||||||
import insightface
|
import insightface
|
||||||
import core.globals
|
import core.globals
|
||||||
from core.config import get_face
|
from core.config import get_face, get_all_faces
|
||||||
|
|
||||||
FACE_SWAPPER = None
|
FACE_SWAPPER = None
|
||||||
|
|
||||||
@ -19,13 +19,15 @@ def process_video(source_img, frame_paths):
|
|||||||
source_face = get_face(cv2.imread(source_img))
|
source_face = get_face(cv2.imread(source_img))
|
||||||
for frame_path in frame_paths:
|
for frame_path in frame_paths:
|
||||||
frame = cv2.imread(frame_path)
|
frame = cv2.imread(frame_path)
|
||||||
|
|
||||||
|
swapper = get_face_swapper()
|
||||||
try:
|
try:
|
||||||
if core.globals.all_faces:
|
if core.globals.all_faces:
|
||||||
all_faces = get_all_faces(frame)
|
all_faces = get_all_faces(frame)
|
||||||
result = frame
|
result = frame
|
||||||
for singleFace in all_faces:
|
for singleFace in all_faces:
|
||||||
if singleFace:
|
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)
|
print('.', end='', flush=True)
|
||||||
else:
|
else:
|
||||||
print('S', end='', flush=True)
|
print('S', end='', flush=True)
|
||||||
@ -33,7 +35,7 @@ def process_video(source_img, frame_paths):
|
|||||||
else:
|
else:
|
||||||
face = get_face(frame)
|
face = get_face(frame)
|
||||||
if face:
|
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)
|
cv2.imwrite(frame_path, result)
|
||||||
print('.', end='', flush=True)
|
print('.', end='', flush=True)
|
||||||
else:
|
else:
|
||||||
|
19
run.py
19
run.py
@ -157,6 +157,10 @@ def toggle_fps_limit():
|
|||||||
args['keep_fps'] = limit_fps.get() != True
|
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():
|
def toggle_keep_frames():
|
||||||
args['keep_frames'] = keep_frames.get() != True
|
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 = 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)
|
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
|
# FPS limit checkbox
|
||||||
limit_fps = tk.IntVar()
|
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 = 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.place(x=30,y=475,width=240,height=31)
|
||||||
fps_checkbox.select()
|
fps_checkbox.select()
|
||||||
|
|
||||||
# Keep frames checkbox
|
# Keep frames checkbox
|
||||||
keep_frames = tk.IntVar()
|
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 = 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.place(x=30,y=450,width=240,height=31)
|
||||||
|
|
||||||
# Start button
|
# Start button
|
||||||
start_button = tk.Button(window, text="Start", bg="#f1c40f", relief="flat", borderwidth=0, highlightthickness=0, command=lambda: [save_file(), start()])
|
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
|
||||||
status_label = tk.Label(window, width=580, justify="center", text="Status: waiting for input...", fg="#2ecc71", bg="#2d3436")
|
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)
|
status_label.place(x=10,y=640,width=580,height=30)
|
||||||
|
|
||||||
window.mainloop()
|
window.mainloop()
|
||||||
|
Loading…
Reference in New Issue
Block a user