-
Notifications
You must be signed in to change notification settings - Fork 0
/
mdet_gui.py
106 lines (80 loc) · 3.79 KB
/
mdet_gui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import os
import tkinter as tk
from tkinter import filedialog, messagebox
from natsort import natsorted
from exec_mdet import ExecMdet
def create_new_structure(src_dir, dst_dir):
for dir, _ ,_ in os.walk(src_dir):
dirs_name = dir.replace(dst_dir, "")
new_dir = os.path.join(dst_dir, dirs_name.replace(os.path.sep, "_out" + os.path.sep) + "_out")
new_dir = os.path.normpath(new_dir)
#print("output directory is ", new_dir)
os.makedirs(new_dir, exist_ok=True)
def find_image_files(folder_path):
image_extensions = ['.jpg', '.jpeg', '.png', '.gif', '.bmp']
image_files = []
for root, dirs, files in os.walk(folder_path):
for file in files:
if any(file.lower().endswith(ext) for ext in image_extensions):
image_files.append(os.path.join(root, file))
image_files = natsorted(image_files)
return image_files
def browse_session_root():
directory = filedialog.askdirectory()
if directory:
session_root_entry.delete(0, tk.END)
session_root_entry.insert(0, directory)
def start_process():
session_root = session_root_entry.get()
threshold = float(threshold_entry.get())
checkpoint = checkpoint_entry.get()
diff_reasoning = diff_reason_swich.get()
skip = skip_swich.get()
open_folder = True
image_files = find_image_files(session_root)
if checkpoint.startswith("r"):
checkpoint = len(image_files) // int(checkpoint[1:])
elif not checkpoint:
checkpoint = None
else:
checkpoint = int(checkpoint)
print(f"Session Root:{session_root}, Threshold:{threshold}, Checkpoint:{checkpoint}, Differential reasoning:{diff_reasoning}, Exist skip:{skip}")
parent_dir = os.path.dirname(session_root)
create_new_structure(session_root, parent_dir)
output_dir = session_root + "_out"
exec_mdet = ExecMdet(image_files, threshold, session_root, checkpoint, diff_reasoning, skip)
exec_mdet.run_detector_with_image_queue()
messagebox.showinfo("Info", f"Process completed successfully. Check the output folder {output_dir} for results.")
root.destroy()
if open_folder:
os.startfile(output_dir)
root = tk.Tk()
root.title("ImageExtractWin GUI")
tk.Label(root, text="Session Root:").grid(row=0, column=0, padx=10, pady=5)
session_root_entry = tk.Entry(root, width=50)
session_root_entry.grid(row=0, column=1, padx=10, pady=5)
browse_button = tk.Button(root, text="Browse", command=browse_session_root)
browse_button.grid(row=0, column=2, padx=10, pady=5)
tk.Label(root, text="Threshold:").grid(row=1, column=0, padx=10, pady=5)
threshold_entry = tk.Entry(root, width=50)
threshold_entry.insert(0, "0.2")
threshold_entry.grid(row=1, column=1, padx=10, pady=5)
tk.Label(root, text="Checkpoint:").grid(row=2, column=0, padx=10, pady=5)
checkpoint_entry = tk.Entry(root, width=50)
checkpoint_entry.grid(row=2, column=1, padx=10, pady=5)
tk.Label(root, text="Differential reasoning:").grid(row=3, column=0, padx=10, pady=5)
diff_reason_swich = tk.BooleanVar(root)
diff_reason_swich.set(False)
#add checkbutton for differential reasoning
diff_reason_checkbutton = tk.Checkbutton(root, variable=diff_reason_swich)
diff_reason_checkbutton.grid(row=3, column=1, padx=10, pady=5)
tk.Label(root, text="Skip existing files:").grid(row=4, column=0, padx=10, pady=5)
skip_swich = tk.BooleanVar(root)
skip_swich.set(False)
#add checkbutton for skip existing files
skip_checkbutton = tk.Checkbutton(root, variable=skip_swich)
skip_checkbutton.grid(row=4, column=1, padx=10, pady=5)
start_button = tk.Button(root, text="Start", command=start_process)
start_button.grid(row=5, column=0, columnspan=3, pady=20)
if __name__ == "__main__":
root.mainloop()