-
Notifications
You must be signed in to change notification settings - Fork 0
/
tkGUI.py
144 lines (114 loc) · 4.96 KB
/
tkGUI.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import tkinter as tk
import time
from tkinter import ttk
from tkinter import *
from PIL import Image, ImageTk
import cv2
# Set up the main window
root = tk.Tk()
root.geometry("1024x768") # Increased width to accommodate sidebar
# Left Sidebar for Object Class Toggles
left_sidebar = tk.Frame(root)
left_sidebar.pack(side="left", fill="y", padx=10)
# Add toggles for object classes to the sidebar
object_classes = ["Class 1", "Class 2", "Class 3", "Class 4"]
toggle_switches = []
for obj_class in object_classes:
toggle_label = tk.Label(left_sidebar, text=obj_class)
toggle_label.pack(pady=2, padx=10)
toggle = tk.Checkbutton(left_sidebar)
toggle.pack(pady=2, padx=10)
toggle_switches.append(toggle)
# Right Sidebar for Saving Objects of Interest
right_sidebar = tk.Frame(root)
right_sidebar.pack(side="right", fill="y", padx=10)
# Timer
timer_label = tk.Label(right_sidebar, text="00:00:00.00")
timer_label.pack(pady=2, padx=10)
timer_running = False
start_time = 0
def update_timer():
if not timer_running:
return
elapsed_time = time.time() - start_time
hours, remainder = divmod(elapsed_time, 3600)
minutes, seconds = divmod(remainder, 60)
milliseconds = int((seconds - int(seconds)) * 100)
seconds = int(seconds)
timer_label.configure(text=f"{hours:02}:{minutes:02}:{seconds:02}.{milliseconds:02}")
root.after(50, update_timer)
def start_timer():
global timer_running, start_time
if not timer_running:
timer_running = True
start_time = time.time()
update_timer()
def stop_timer():
global timer_running
timer_running = False
# Define a video capture object
vid = cv2.VideoCapture(0)
def open_camera():
_, frame = vid.read()
opencv_image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGBA)
captured_image = Image.fromarray(opencv_image)
photo_image = ImageTk.PhotoImage(image=captured_image)
video_label.photo_image = photo_image
video_label.configure(image=photo_image)
video_label.after(10, open_camera)
def save_results():
ret, frame = vid.read()
if ret:
current_time = time.strftime("%Y-%m-%d %H:%M:%S")
filename = f"saved_frame_{current_time}.png".replace(':', '-')
cv2.imwrite(filename, frame)
opencv_image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGBA)
captured_image = Image.fromarray(opencv_image)
photo_image = ImageTk.PhotoImage(image=captured_image.resize((100, 75)))
label = tk.Label(right_sidebar, text=current_time)
label.pack()
image_label = tk.Label(right_sidebar, image=photo_image)
image_label.image = photo_image
image_label.pack()
# Main Frame for the rest of the UI
main_frame = tk.Frame(root)
main_frame.pack(side="right", fill="both", expand=True)
# Title
title_label = tk.Label(main_frame, text="Columbia University MicroG NeXT YOLO Model", font=("Roboto Medium", 16))
title_label.pack(pady=12, padx=10)
# Upper Frame for Input and Controls
upper_frame = tk.Frame(main_frame)
upper_frame.pack(side="top", fill="x", padx=20, pady=10)
# Input Controls in the Upper Frame
input_label = tk.Label(upper_frame, text="Input")
input_label.grid(row=0, column=0, pady=10, padx=10)
input_entry = tk.Entry(upper_frame)
input_entry.grid(row=0, column=1, pady=10, padx=10)
checkbox = tk.Checkbutton(upper_frame, text="Checkbox")
checkbox.grid(row=1, column=0, pady=10, padx=10)
toggle_label = tk.Label(upper_frame, text="Toggle")
toggle_label.grid(row=2, column=0, pady=10, padx=10)
toggle_switch = tk.Checkbutton(upper_frame)
toggle_switch.grid(row=2, column=1, pady=10, padx=10)
dropdown_label = tk.Label(upper_frame, text="Dropdown Box")
dropdown_label.grid(row=1, column=1, pady=10, padx=10)
dropdown = ttk.Combobox(upper_frame, values=["Option 1", "Option 2", "Option 3"])
dropdown.grid(row=1, column=2, pady=10, padx=10)
# Video Feed Frame
video_frame = tk.Frame(main_frame, height=300)
video_frame.pack(side="top", fill="both", expand=True, padx=20, pady=10)
# Label as a placeholder for video feed
video_label = tk.Label(video_frame, text="Live Video Feed")
video_label.pack(side="top", fill="both", expand=True)
# Bottom Frame for Buttons
bottom_frame = tk.Frame(main_frame)
bottom_frame.pack(side="top", fill="x", padx=20, pady=10)
start_button = tk.Button(bottom_frame, text="Start Analysis", command=start_timer)
start_button.pack(side="left", fill="x", expand=True, padx=10, pady=10)
stop_button = tk.Button(bottom_frame, text="Stop Analysis", command=stop_timer)
stop_button.pack(side="left", fill="x", expand=True, padx=10, pady=10)
save_button = tk.Button(bottom_frame, text="Save Results", command=save_results)
save_button.pack(side="left", fill="x", expand=True, padx=10, pady=10)
open_camera_button = tk.Button(bottom_frame, text="Open Camera", command=open_camera)
open_camera_button.pack(side="left", fill="x", expand=True, padx=10, pady=10)
root.mainloop()