-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui.py
106 lines (82 loc) · 3.69 KB
/
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 matplotlib.pyplot as plt
import tkinter as tk
import logging
from collections import deque
from ttkthemes import ThemedTk
from tkinter import ttk
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
logging.getLogger("matplotlib.font_manager").setLevel(logging.ERROR)
logging.getLogger("PIL").setLevel(logging.WARNING)
# Use a deque to store historical execution times for each iteration
historical_execution_times = {}
# Function for monitoring the status of the camera processes
def process_status_gui(shared_dict, monitor):
"""
Monitor the status of the camera processes.
Args:
shared_dict: The shared dictionary containing camera stream information.
monitor: A boolean value indicating whether to display monitoring information.
Returns:
None
Continuously monitors and displays the status of the camera processes in the terminal.
"""
def update_gui():
if monitor:
for widget in frame.winfo_children():
widget.destroy()
header_labels = [
"ID",
"Camera Name",
"Stream Name",
"Execution Time",
"Faces Detected",
]
for idx, label in enumerate(header_labels):
ttk.Label(frame, text=label, font=("Arial", 12, "bold")).grid(
row=0, column=idx, padx=5, pady=5
)
fig, ax = plt.subplots()
for key, value in shared_dict.items():
# Plot historical execution times specific to each row
execution_time = float(value["execution_time"])
if key not in historical_execution_times:
historical_execution_times[key] = deque(maxlen=10)
# Append the execution time to the deque
historical_execution_times[key].append(execution_time)
# Plot the historical execution times for each row
ax.plot(
list(historical_execution_times[key]), marker="o", label=str(key)
)
ttk.Label(frame, text=str(key)).grid(
row=key + 1, column=0, padx=5, pady=5
)
ttk.Label(
frame, text=value["camera_name"], anchor="w", justify="left"
).grid(row=key + 1, column=1, padx=5, pady=5)
ttk.Label(
frame, text=value["stream_name"], anchor="w", justify="left"
).grid(row=key + 1, column=2, padx=5, pady=5)
ttk.Label(frame, text=value["execution_time"]).grid(
row=key + 1, column=3, padx=5, pady=5
)
ttk.Label(frame, text=str(value["faces_detected"])).grid(
row=key + 1, column=4, padx=5, pady=5
)
ax.set_title("Historical Execution Times")
ax.set_xlabel("Iteration")
ax.set_ylabel("Execution Time (s)")
ax.legend()
# Create a Tkinter canvas to embed the Matplotlib plot
canvas = FigureCanvasTkAgg(fig, master=root)
canvas_widget = canvas.get_tk_widget()
canvas_widget.grid(row=1, column=0)
# Update every 100 milliseconds
root.after(100, update_gui)
if monitor:
root = ThemedTk(theme="")
root.title("Camera Process Status")
frame = ttk.Frame(root, padding=(5, 5, 5, 5))
frame.grid(row=0, column=0, sticky="nsew")
frame.pack_propagate(0) # Disable propagation
update_gui()
root.mainloop()