add previews to gui

This commit is contained in:
Somdev Sangwan 2023-05-30 06:50:45 +05:30
commit e6a2511362
2 changed files with 150 additions and 0 deletions

View File

@ -4,4 +4,16 @@ onnx==1.14.0
insightface==0.7.3 insightface==0.7.3
psutil==5.9.5 psutil==5.9.5
tk==0.1.0 tk==0.1.0
<<<<<<< HEAD
torch==2.0.1 torch==2.0.1
=======
<<<<<<< HEAD
<<<<<<< HEAD
pillow==9.0.1
=======
torch==2.0.1
>>>>>>> 54f800d (Add GPU support, Quit on missing model, Remove globals (sorry))
=======
torch==2.0.1
>>>>>>> 36e960e (restore onnxruntime)
>>>>>>> TitasDas-feature/preview-for-face-image-and-input-video

138
run.py
View File

@ -1,6 +1,22 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
<<<<<<< HEAD
import sys import sys
import time import time
=======
<<<<<<< HEAD
<<<<<<< HEAD
import sys
import time
<<<<<<< HEAD
=======
>>>>>>> 54f800d (Add GPU support, Quit on missing model, Remove globals (sorry))
=======
import sys
>>>>>>> dc0653a (Restore globals, add process time for better comparison)
=======
>>>>>>> 2b14613 (Move process time to the correct place)
>>>>>>> TitasDas-feature/preview-for-face-image-and-input-video
import torch import torch
import shutil import shutil
import core.globals import core.globals
@ -25,6 +41,8 @@ from core.config import get_face
import webbrowser import webbrowser
import psutil import psutil
import cv2 import cv2
import threading
from PIL import Image, ImageTk
pool = None pool = None
args = {} args = {}
@ -51,8 +69,23 @@ def start_processing():
start_time = time.time() start_time = time.time()
if args['gpu']: if args['gpu']:
process_video(args['source_img'], args["frame_paths"]) process_video(args['source_img'], args["frame_paths"])
<<<<<<< HEAD
end_time = time.time() end_time = time.time()
print(flush=True) print(flush=True)
=======
<<<<<<< HEAD
<<<<<<< HEAD
end_time = time.time()
print(flush=True)
=======
print(flush=True)
end_time = time.time()
>>>>>>> 2b14613 (Move process time to the correct place)
=======
end_time = time.time()
print(flush=True)
>>>>>>> 0f782ff (Move process time to the correct place)
>>>>>>> TitasDas-feature/preview-for-face-image-and-input-video
print(f"Processing time: {end_time - start_time:.2f} seconds", flush=True) print(f"Processing time: {end_time - start_time:.2f} seconds", flush=True)
return return
frame_paths = args["frame_paths"] frame_paths = args["frame_paths"]
@ -65,17 +98,65 @@ def start_processing():
p.get() p.get()
pool.close() pool.close()
pool.join() pool.join()
<<<<<<< HEAD
end_time = time.time()
print(flush=True)
print(f"Processing time: {end_time - start_time:.2f} seconds", flush=True)
=======
<<<<<<< HEAD
<<<<<<< HEAD
end_time = time.time() end_time = time.time()
print(flush=True) print(flush=True)
print(f"Processing time: {end_time - start_time:.2f} seconds", flush=True) print(f"Processing time: {end_time - start_time:.2f} seconds", flush=True)
def preview_image(image_path):
img = Image.open(image_path)
img = img.resize((180, 180), Image.ANTIALIAS)
photo_img = ImageTk.PhotoImage(img)
left_frame = tk.Frame(window)
left_frame.place(x=60, y=100)
img_label = tk.Label(left_frame, image=photo_img)
img_label.image = photo_img
img_label.pack()
def preview_video(video_path):
cap = cv2.VideoCapture(video_path)
if not cap.isOpened():
print("Error opening video file")
return
ret, frame = cap.read()
if ret:
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
img = Image.fromarray(frame)
img = img.resize((180, 180), Image.ANTIALIAS)
photo_img = ImageTk.PhotoImage(img)
right_frame = tk.Frame(window)
right_frame.place(x=360, y=100)
img_label = tk.Label(right_frame, image=photo_img)
img_label.image = photo_img
img_label.pack()
cap.release()
=======
print(flush=True)
=======
>>>>>>> 0f782ff (Move process time to the correct place)
end_time = time.time()
print(flush=True)
print(f"Processing time: {end_time - start_time:.2f} seconds", flush=True)
>>>>>>> 2b14613 (Move process time to the correct place)
>>>>>>> TitasDas-feature/preview-for-face-image-and-input-video
def select_face(): def select_face():
args['source_img'] = filedialog.askopenfilename(title="Select a face") args['source_img'] = filedialog.askopenfilename(title="Select a face")
preview_image(args['source_img'])
def select_target(): def select_target():
args['target_path'] = filedialog.askopenfilename(title="Select a target") args['target_path'] = filedialog.askopenfilename(title="Select a target")
threading.Thread(target=preview_video, args=(args['target_path'],)).start()
def toggle_fps_limit(): def toggle_fps_limit():
@ -148,7 +229,15 @@ if __name__ == "__main__":
start() start()
quit() quit()
window = tk.Tk() window = tk.Tk()
<<<<<<< HEAD
window.geometry("600x500") window.geometry("600x500")
=======
<<<<<<< HEAD
window.geometry("600x700")
=======
window.geometry("600x500")
>>>>>>> a440cef (better gui)
>>>>>>> TitasDas-feature/preview-for-face-image-and-input-video
window.title("roop") window.title("roop")
window.configure(bg="#2d3436") window.configure(bg="#2d3436")
window.resizable(width=False, height=False) window.resizable(width=False, height=False)
@ -160,21 +249,46 @@ if __name__ == "__main__":
# Select a face button # Select a face button
face_button = tk.Button(window, text="Select a face", command=select_face, bg="#2d3436", fg="#74b9ff", highlightthickness=4, relief="flat", highlightbackground="#74b9ff", activebackground="#74b9ff", borderwidth=4) face_button = tk.Button(window, text="Select a face", command=select_face, bg="#2d3436", fg="#74b9ff", highlightthickness=4, relief="flat", highlightbackground="#74b9ff", activebackground="#74b9ff", borderwidth=4)
<<<<<<< HEAD
face_button.place(x=60,y=120,width=180,height=80) face_button.place(x=60,y=120,width=180,height=80)
# Select a target button # Select a target button
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=120,width=180,height=80) target_button.place(x=360,y=120,width=180,height=80)
=======
<<<<<<< HEAD
face_button.place(x=60,y=320,width=180,height=80)
# Select a target button
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)
=======
face_button.place(x=60,y=120,width=180,height=80)
# Select a target button
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=120,width=180,height=80)
>>>>>>> a440cef (better gui)
>>>>>>> TitasDas-feature/preview-for-face-image-and-input-video
# 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)
<<<<<<< HEAD
fps_checkbox.place(x=30,y=230,width=240,height=31) fps_checkbox.place(x=30,y=230,width=240,height=31)
=======
<<<<<<< HEAD
fps_checkbox.place(x=30,y=500,width=240,height=31)
=======
fps_checkbox.place(x=30,y=230,width=240,height=31)
>>>>>>> a440cef (better gui)
>>>>>>> TitasDas-feature/preview-for-face-image-and-input-video
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)
<<<<<<< HEAD
frames_checkbox.place(x=37,y=280,width=240,height=31) frames_checkbox.place(x=37,y=280,width=240,height=31)
# Start button # Start button
@ -184,4 +298,28 @@ 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=440,width=580,height=30) status_label.place(x=10,y=440,width=580,height=30)
=======
<<<<<<< HEAD
frames_checkbox.place(x=37,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()])
start_button.place(x=240,y=560,width=120,height=49)
# 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)
=======
frames_checkbox.place(x=37,y=280,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()])
start_button.place(x=240,y=360,width=120,height=49)
# 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=440,width=580,height=30)
>>>>>>> a440cef (better gui)
>>>>>>> TitasDas-feature/preview-for-face-image-and-input-video
window.mainloop() window.mainloop()