-
Notifications
You must be signed in to change notification settings - Fork 0
/
YoloGUI.py
103 lines (77 loc) · 4.02 KB
/
YoloGUI.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
#
# Object Detection with Yolo.V3
#
# Coded by Amir otd :)[https://github.com/amirotd]
import tkinter as tk
from tkinter import filedialog, messagebox
from Yolo import YOLO
class YoloGui(tk.Tk):
def __init__(self):
super().__init__()
self.title("Yolo object detection")
self.geometry('512x256+200+100')
self.configure(bg='LightSteelBlue2')
self['padx'] = 5
self['pady'] = 5
self.grid_columnconfigure(0, weight=5)
self.grid_columnconfigure(1, weight=5)
self.grid_rowconfigure(0, weight=5)
self.grid_rowconfigure(1, weight=5)
self.grid_rowconfigure(2, weight=5)
self.grid_rowconfigure(3, weight=5)
self.image_var = tk.StringVar(self)
self.image_var.set('')
self.yolo_var = tk.StringVar(self)
self.yolo_var.set('')
self.confidence_var = tk.StringVar(self)
self.confidence_var.set('0.5')
self.threshold_var = tk.StringVar(self)
self.threshold_var.set('0.3')
self.upload_frame = tk.LabelFrame(self, text='Add File', bg='LightSteelBlue2')
self.upload_frame.grid(column=0, row=0)
self.upload_box = tk.Entry(self.upload_frame, textvariable=self.image_var, width=60)
self.upload_box.grid(column=0, row=0)
self.upload_button = tk.Button(self.upload_frame, text='Browse', command=self.upload_file, bg='SteelBlue3', fg='white', activebackground='SteelBlue2')
self.upload_button.grid(column=1, row=0)
self.yolo_path_frame = tk.LabelFrame(self, text='Yolo Path', bg='LightSteelBlue2')
self.yolo_path_frame.grid(column=0, row=1)
self.yolo_path_box = tk.Entry(self.yolo_path_frame, textvariable=self.yolo_var, width=60)
self.yolo_path_box.grid(column=0, row=0)
self.yolo_button = tk.Button(self.yolo_path_frame, text='Browse', command=self.set_path, bg='SteelBlue3', fg='white', activebackground='SteelBlue2')
self.yolo_button.grid(column=1, row=0)
self.settings_frame = tk.LabelFrame(self, text='Settings', bg='LightSteelBlue2')
self.settings_frame.grid(column=0, row=2)
self.confidence_label = tk.Label(self.settings_frame, text='Confidence', bg='SteelBlue3', fg='white')
self.confidence_label.grid(column=0, row=0)
self.confidence_box = tk.Spinbox(self.settings_frame, textvariable=self.confidence_var, increment=0.1, from_=0, to=100, width=10)
self.confidence_box.grid(column=1, row=0)
self.threshold_label = tk.Label(self.settings_frame, text='Threshold ', bg='SteelBlue3', fg='white')
self.threshold_label.grid(column=0, row=1)
self.threshold_box = tk.Spinbox(self.settings_frame, textvariable=self.threshold_var, increment=0.1, from_=0, to=100, width=10)
self.threshold_box.grid(column=1, row=1)
self.buttons_frame = tk.Frame(self)
self.buttons_frame.grid(column=0, row=3)
self.start_button = tk.Button(self.buttons_frame, text='Start', command=self.start, bg='SteelBlue3', fg='white', activebackground='SteelBlue2')
self.start_button.grid(column=0, row=0)
self.quit_button = tk.Button(self.buttons_frame, text='Quit', command=self.destroy, bg='SteelBlue3', fg='white', activebackground='SteelBlue2')
self.quit_button.grid(column=1, row=0)
def upload_file(self):
filename = filedialog.askopenfilename()
self.image_var = filename
self.upload_box.delete(0, tk.END)
self.upload_box.insert(0, self.image_var)
self.upload_box.xview_moveto(1)
def set_path(self):
path = filedialog.askdirectory()
self.yolo_var = path
self.yolo_path_box.delete(0, tk.END)
self.yolo_path_box.insert(0, self.yolo_var)
def start(self):
try:
y = YOLO(self.image_var, self.yolo_var, float(self.confidence_var.get()), float(self.threshold_var.get()))
y.start_process()
except:
messagebox.showerror("Error", "Please Enter a Valid Path")
if __name__ == '__main__':
app = YoloGui()
app.mainloop()