forked from natdebru/OpenCV-Video-Label
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoption_frame.py
126 lines (106 loc) · 6.22 KB
/
option_frame.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
import tkinter as tk
from constants import GUI_BG, GUI_GRAYD, GUI_SHADOW, GUI_BLUE, STORE_N, button_config
LABEL_TITLE = {"bg": GUI_BG, "fg": GUI_GRAYD, "font": "Arial 9 bold"}
SLEEP_SCALE = {"from_": 2, "to": 100, "width": 10, "resolution": 2, "border": 0,
"highlightbackground": GUI_BG, "showvalue": False, "bg": GUI_BLUE, "orient": tk.HORIZONTAL,
"cursor": "hand2", "troughcolor": GUI_SHADOW, "sliderrelief": tk.FLAT, "activebackground": GUI_BLUE}
class TkOptionFrame:
def __init__(self, parent):
self.parent = parent
self.frame = tk.Frame(self.parent.video_miner, bg=GUI_BG, bd=10)
self.frame.pack(side="top", fill="x", padx=0, pady=0)
# variable to prevent pause/play toggling while editing object class
self.changing_object = False
# create a frame to center entry fields
self.entry_grid = tk.Frame(self.frame)
self.entry_grid.pack(side="top")
tk.Grid.rowconfigure(self.entry_grid, 0, weight=1, minsize=15)
tk.Grid.columnconfigure(self.entry_grid, 0, weight=1)
# the frame that holds the actual fields (possibly redundant)
self.entry_grid_fields = tk.Frame(self.entry_grid, bg=GUI_BG)
self.entry_grid_fields.grid(row=0)
tk.Grid.rowconfigure(self.entry_grid_fields, 0, weight=1)
# entry for object class' name
self.object_class = tk.StringVar()
# entry to edit the export interval value n
tk.Label(self.entry_grid_fields, LABEL_TITLE, text="Export interval:").grid(column=1, row=0)
self.n = tk.StringVar()
e = tk.Entry(self.entry_grid_fields, textvariable=self.n, fg=GUI_GRAYD, font=("Arial", 11, "bold"))
e.grid(column=1, row=2, padx=30, sticky=tk.N)
e.insert(0, STORE_N)
# option menu to select which tracking algorithm is used
tk.Label(self.entry_grid_fields, LABEL_TITLE, text="Tracking algorithm:").grid(column=0, row=0)
self.algorithm_selection = tk.Listbox(self.entry_grid_fields, selectmode=tk.BROWSE)
self.algorithm_selection.configure(relief="flat", cursor="hand2", takefocus=0, activestyle='none', bd=0,
height=2,
highlightcolor=GUI_BG, highlightbackground=GUI_BG,
font=("Arial", 11, "bold"),
selectbackground=GUI_SHADOW, fg=GUI_GRAYD, listvariable=0,
selectforeground=GUI_GRAYD,
exportselection=False)
self.algorithm_selection.bind('<<ListboxSelect>>', self.update_algorithm)
# TODO change to for loop over algorithm folder/list
self.algorithm_selection.insert(0, " Re3 (default)")
self.algorithm_selection.insert(1, " CMT ")
self.algorithm_selection.select_set(0)
self.algorithm_selection.grid(column=0, row=2, sticky=tk.NSEW)
# scale to control sleep time between two frames while playing
self.speed_scale_string = tk.StringVar()
self.speed_scale_string.set("Sleep time \nregular playback: ({}) ".format(self.parent.speed))
self.speed_label = tk.Label(self.entry_grid_fields, LABEL_TITLE, textvariable=self.speed_scale_string).grid(
column=3, row=0)
self.speed_scale = tk.Scale(self.entry_grid_fields, SLEEP_SCALE)
self.speed_scale.grid(button_config, column=3, row=2, padx=30)
self.speed_scale.bind("<ButtonRelease-1>", self.update_speed)
# scale to control sleep time between two frames while tracking
self.track_scale_string = tk.StringVar()
self.track_scale_string.set("Sleep time \ntracking: ({}) ".format(self.parent.track_speed))
self.track_label = tk.Label(self.entry_grid_fields, LABEL_TITLE, textvariable=self.track_scale_string)
self.track_label.grid(column=4, row=0)
self.track_scale = tk.Scale(self.entry_grid_fields, SLEEP_SCALE)
self.track_scale.grid(button_config, column=4, row=2)
self.track_scale.bind("<ButtonRelease-1>", self.update_track_speed)
# Fixes bug where Listbox options were stacking on top of each other.
def reset_list(self):
self.algorithm_selection.delete(0, 'end')
self.algorithm_selection.insert(0, " Re3 (default)")
self.algorithm_selection.insert(1, " CMT ")
self.algorithm_selection.select_set(0)
self.algorithm_selection.grid(column=0, row=2, sticky=tk.NSEW)
# updates playback sleep time and label
def update_speed(self, _):
self.parent.speed = self.speed_scale.get()
self.speed_scale_string.set("Sleep time \nregular playback: ({}) ".format(self.parent.speed))
# updates tracking sleep time and label
def update_track_speed(self, _):
self.parent.track_speed = self.track_scale.get()
self.track_scale_string.set("Sleep time \ntracking: ({}) ".format(self.parent.track_speed))
# updates which tracking algorithm is used
def update_algorithm(self, _):
index = self.algorithm_selection.curselection()[0]
self.parent.tracking = False
self.parent.tracker = self.parent.tracker_list[index]
self.parent.video_loop(True)
self.parent.control_panel.pause_playing()
# function to prevent spacebar from pausing while typing object class
def callback_entry1_nofocus(self, _):
self.changing_object = False
# function to prevent spacebar from pausing while typing object class
def callback_entry1_focus(self, _):
self.changing_object = True
# returns the value of the object class which is used to store in the dataset
def get_object_class(self):
string = self.object_class.get().strip().replace(" ", "_")
self.object_class.set(string)
return string
# this changes the object class in the e1 text entry.
def set_object_class(self, name):
self.object_class.set(name)
# returns the interval value n which determines how often a frame is stored to the dataset
def get_n(self):
try:
return int(self.n.get())
# if it is not possible convert value to int set value to default value
except ValueError:
self.n.set(STORE_N)
return STORE_N