-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecord_labels.py
166 lines (123 loc) · 5.8 KB
/
record_labels.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
from tkinter import *
from tkinter import messagebox
from tkvideo import tkvideo
from datetime import datetime
from enum import Enum
import os
import sys
import json
import pickle
import random
import sys
class Language(Enum):
ENGLISH = "_EN"
GERMAN = "_DE"
def createStartPage():
frame = Frame(root)
frame.pack(fill=BOTH, expand=True)
label = Label(frame, text="Choose a language / Wähle eine Sprache")
label.place(relx=0.5, rely=0.4, anchor=CENTER)
languageButtonGER = Button(frame, text="German / Deutsch",
command=lambda: (frame.destroy(), createDescriptionWindow(Language.GERMAN)))
languageButtonGER.place(relx=0.5, rely=0.45, anchor=CENTER)
languageButtonEN = Button(frame, text="English / Englisch",
command=lambda: (frame.destroy(), createDescriptionWindow(Language.ENGLISH)))
languageButtonEN.place(relx=0.5, rely=0.5, anchor=CENTER)
def createDescriptionWindow(language: Language):
frame = createFrame(language)
welcomeDescription = Text(frame, wrap='word', font=("Arial", 12))
welcomeDescription.insert(INSERT, json_data.get("glossary").get("glossary" + language.value).get("welcomeMessage"))
welcomeDescription.config(state=DISABLED)
welcomeDescription.place(relx=0.5, rely=0.4, anchor=CENTER)
languageButton = Button(frame, text="Weiter",
command=lambda: (frame.destroy(), createGestureWindowFirst(language)))
languageButton.place(relx=0.5, rely=0.8, anchor=CENTER)
def createGestureWindowFirst(language: Language):
gestures = json_data.get("gestures")
if len(gestures) < 1:
messagebox.showinfo("Missing gestures", "There aren't any gestures defined!")
sys.exit(-1)
createGestureWindowIteration(language, gestures)
def createGestureWindowIteration(language: Language, restOfGestures):
frame = createFrame(language)
if len(restOfGestures) == 0:
frame.destroy()
createLastWindow(language)
else:
random.shuffle(restOfGestures)
gesture = restOfGestures.pop(0)
count = gesture.get("sampleCount")
if count > 1:
gesture["sampleCount"] = count - 1
restOfGestures.append(gesture)
gestureDescription = Text(frame, wrap='word', font=("Arial", 12))
gestureDescription.insert(INSERT, gesture.get("name" + language.value) + "\n\n")
gestureDescription.insert(INSERT, gesture.get("description" + language.value) + "\n\n")
gestureDescription.insert(INSERT, "Repititions / Wiederholungen: {sampleCount}".format(sampleCount=count))
gestureDescription.config(state=DISABLED)
gestureDescription.place(relx=0.5, rely=0.85, anchor=CENTER)
lbl = Label(root)
lbl.pack(pady=20)
path = './mp4s/' + gesture.get("file")
player = tkvideo(path, lbl, loop=1)
player.play()
# Edit the 'load' function in tkvideo.py by adding 'time.sleep(0.06)'
# inside the while loop to fix the speed of the videos
languageButton = Button(frame, text="Start",
command=lambda: createStopButton(language, languageButton, frame, gesture,
restOfGestures, gestureDescription, count,
getCurrentTime(), lbl))
languageButton.place(relx=0.8, rely=0.5, anchor=CENTER)
languageButton.focus_set()
def createStopButton(language: Language, button, frame, gesture, restOfGestures, gestureDescription, count, startTime, lbl):
button.destroy()
button = Button(frame, text="stop",
command=lambda: (addLabel(startTime, getCurrentTime(), gesture.get("label")), print(labelList),
prepareNextGestureWindowIteration(language, frame, restOfGestures, lbl)))
button.place(relx=0.8, rely=0.5, anchor=CENTER)
button.focus_set()
def prepareNextGestureWindowIteration(language: Language, frame, restOfGestures, lbl):
lbl.destroy()
frame.pack_forget()
frame.destroy()
createGestureWindowIteration(language, restOfGestures)
def createLastWindow(language: Language):
frame = createFrame(language)
automaticLabelingText = Text(frame, wrap='word', font=("Arial", 12))
automaticLabelingText.insert(INSERT,
json_data.get("glossary").get("glossary" + language.value).get("goodbyeMessage"))
automaticLabelingText.config(state=DISABLED)
automaticLabelingText.place(relx=0.5, rely=0.4, anchor=CENTER)
languageButton = Button(frame, text="Exit",
command=lambda: (saveLabelList(), sys.exit(0)))
languageButton.place(relx=0.5, rely=0.8, anchor=CENTER)
def saveLabelList():
labeledData = json_data.get("timestampSaveData")
timestampsName = json_data.get("timeStampDataName")
savePath = labeledData + timestampsName + ".pkl"
with open(savePath, 'wb') as output:
pickle.dump(labelList, output, pickle.HIGHEST_PROTOCOL)
def createFrame(language: Language):
frame = Frame(root)
frame.pack(fill=BOTH, expand=True)
root.title(json_data.get("glossary").get("glossary" + language.value).get("title"))
return frame
def chooseLanguage(language: Language, chosenLanguage):
chosenLanguage = language
def addLabel(startTime, endTime, label):
labelList.append((startTime, endTime, label))
def getCurrentTime():
return datetime.utcnow()
if __name__ == '__main__':
language = Language.ENGLISH
with open("dictionary.json", "rb") as json_file:
json_data = json.load(json_file)
startTime = 0
endTime = 0
labelList = []
root = Tk()
root.geometry("1280x720")
root.title("")
root.resizable(False, False)
createStartPage()
root.mainloop()