forked from Sentdex/pygta5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_editor.py
218 lines (196 loc) · 8.45 KB
/
data_editor.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
import numpy as np
import cv2
from tkinter import *
from tkinter import filedialog
from PIL import Image, ImageTk
FILE_I_END = 1
data_order = [i for i in range(1, FILE_I_END + 1)]
class Window(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.master = master
self.init_window()
def init_window(self):
self.master.title("Data Approval")
self.pack(fill=BOTH, expand=1)
images_1_2_h_rgb = cv2.cvtColor(images_1_2_h, cv2.COLOR_BGR2RGB)
im = Image.fromarray(images_1_2_h_rgb, 'RGB')
imgtk = ImageTk.PhotoImage(image=im)
label = Label(image=imgtk)
label.image = imgtk
label.pack()
self.approve_button = Button(self, text="Approve!", command=self.approve)
self.approve_button.pack()
self.exclude_button = Button(self, text="Reject!", command=self.exclude)
self.exclude_button.pack()
self.modify_button = Button(self, text="Modify!", command=self.modify)
self.modify_button.pack()
self.choice2 = []
def approve(self):
approved_data.append([img, choice])
print("Data point " + str(data) + " was approved!")
root.destroy()
def approve_mod(self):
approved_data.append([img, self.choice2])
print("Data point " + str(data) + " was modified and approved!")
root.destroy()
def exclude(self):
print("Data point " + str(data) + " will be excluded!")
root.destroy()
def modify(self):
self.approve_button.destroy()
self.exclude_button.destroy()
self.modify_button.destroy()
w_button = Button(self, text="W", command=self.mod_w)
w_button.pack()
s_button = Button(self, text="S", command=self.mod_s)
s_button.pack()
a_button = Button(self, text="A", command=self.mod_a)
a_button.pack()
d_button = Button(self, text="D", command=self.mod_d)
d_button.pack()
aw_button = Button(self, text="AW", command=self.mod_aw)
aw_button.pack()
dw_button = Button(self, text="DW", command=self.mod_dw)
dw_button.pack()
as_button = Button(self, text="AS", command=self.mod_as)
as_button.pack()
ds_button = Button(self, text="DS", command=self.mod_ds)
ds_button.pack()
nk_button = Button(self, text="NK", command=self.mod_nk)
nk_button.pack()
def mod_w(self):
self.choice2 = [1, 0, 0, 0, 0, 0, 0, 0, 0]
message1 = Label(text="Choice changed to: " + str(choice))
message1.pack()
message2 = Label(text="Please Approve or Reject this change.")
message2.pack()
self.approve_button = Button(self, text="Approve!", command=self.approve_mod)
self.approve_button.pack()
self.exclude_button = Button(self, text="Reject!", command=self.exclude)
self.exclude_button.pack()
def mod_s(self):
self.choice2 = [0, 1, 0, 0, 0, 0, 0, 0, 0]
message1 = Label(text="Choice changed to: " + str(choice))
message1.pack()
message2 = Label(text="Please Approve or Reject this change.")
message2.pack()
self.approve_button = Button(self, text="Approve!", command=self.approve_mod)
self.approve_button.pack()
self.exclude_button = Button(self, text="Reject!", command=self.exclude)
self.exclude_button.pack()
def mod_a(self):
self.choice2 = [0, 0, 1, 0, 0, 0, 0, 0, 0]
message1 = Label(text="Choice changed to: " + str(choice))
message1.pack()
message2 = Label(text="Please Approve or Reject this change.")
message2.pack()
self.approve_button = Button(self, text="Approve!", command=self.approve_mod)
self.approve_button.pack()
self.exclude_button = Button(self, text="Reject!", command=self.exclude)
self.exclude_button.pack()
def mod_d(self):
self.choice2 = [0, 0, 0, 1, 0, 0, 0, 0, 0]
message1 = Label(text="Choice changed to: " + str(choice))
message1.pack()
message2 = Label(text="Please Approve or Reject this change.")
message2.pack()
self.approve_button = Button(self, text="Approve!", command=self.approve_mod)
self.approve_button.pack()
self.exclude_button = Button(self, text="Reject!", command=self.exclude)
self.exclude_button.pack()
def mod_aw(self):
self.choice2 = [0, 0, 0, 0, 1, 0, 0, 0, 0]
message1 = Label(text="Choice changed to: " + str(choice))
message1.pack()
message2 = Label(text="Please Approve or Reject this change.")
message2.pack()
self.approve_button = Button(self, text="Approve!", command=self.approve_mod)
self.approve_button.pack()
self.exclude_button = Button(self, text="Reject!", command=self.exclude)
self.exclude_button.pack()
def mod_dw(self):
self.choice2 = [0, 0, 0, 0, 0, 1, 0, 0, 0]
message1 = Label(text="Choice changed to: " + str(choice))
message1.pack()
message2 = Label(text="Please Approve or Reject this change.")
message2.pack()
self.approve_button = Button(self, text="Approve!", command=self.approve_mod)
self.approve_button.pack()
self.exclude_button = Button(self, text="Reject!", command=self.exclude)
self.exclude_button.pack()
def mod_as(self):
self.choice2 = [0, 0, 0, 0, 0, 0, 1, 0, 0]
message1 = Label(text="Choice changed to: " + str(choice))
message1.pack()
message2 = Label(text="Please Approve or Reject this change.")
message2.pack()
self.approve_button = Button(self, text="Approve!", command=self.approve_mod)
self.approve_button.pack()
self.exclude_button = Button(self, text="Reject!", command=self.exclude)
self.exclude_button.pack()
def mod_ds(self):
self.choice2 = [0, 0, 0, 0, 0, 0, 0, 1, 0]
message1 = Label(text="Choice changed to: " + str(choice))
message1.pack()
message2 = Label(text="Please Approve or Reject this change.")
message2.pack()
self.approve_button = Button(self, text="Approve!", command=self.approve_mod)
self.approve_button.pack()
self.exclude_button = Button(self, text="Reject!", command=self.exclude)
self.exclude_button.pack()
def mod_nk(self):
self.choice2 = [0, 0, 0, 0, 0, 0, 0, 0, 1]
message1 = Label(text="Choice changed to: " + str(choice))
message1.pack()
message2 = Label(text="Please Approve or Reject this change.")
message2.pack()
self.approve_button = Button(self, text="Approve!", command=self.approve_mod)
self.approve_button.pack()
self.exclude_button = Button(self, text="Reject!", command=self.exclude)
self.exclude_button.pack()
try:
root = Tk()
file_name = filedialog.askopenfilename(filetypes=[("Numpy Files", "*.npy")])
root.destroy()
train_data = np.load(file_name, allow_pickle=True)
approved_data = []
for data in train_data:
img = data[0]
choice = data[1]
if choice == [1, 0, 0, 0, 0, 0, 0, 0, 0]:
choice_img = 'key_images/w.png'
elif choice == [0, 1, 0, 0, 0, 0, 0, 0, 0]:
choice_img = 'key_images/s.png'
elif choice == [0, 0, 1, 0, 0, 0, 0, 0, 0]:
choice_img = 'key_images/a.png'
elif choice == [0, 0, 0, 1, 0, 0, 0, 0, 0]:
choice_img = 'key_images/d.png'
elif choice == [0, 0, 0, 0, 1, 0, 0, 0, 0]:
choice_img = 'key_images/aw.png'
elif choice == [0, 0, 0, 0, 0, 1, 0, 0, 0]:
choice_img = 'key_images/dw.png'
elif choice == [0, 0, 0, 0, 0, 0, 1, 0, 0]:
choice_img = 'key_images/as.png'
elif choice == [0, 0, 0, 0, 0, 0, 0, 1, 0]:
choice_img = 'key_images/ds.png'
elif choice == [0, 0, 0, 0, 0, 0, 0, 0, 1]:
choice_img = 'key_images/nk.png'
else:
print('no matches')
img2 = cv2.imread(choice_img)
img2 = cv2.resize(img2, (250, 270))
images_1_2_h = np.concatenate((img, img2), axis=1)
if cv2.waitKey(25) & 0xFF == ord('q'):
cv2.destroyAllWindows()
break
root = Tk()
root.geometry("+1000+500")
app = Window(root)
root.mainloop()
root = Tk()
save_file_name = filedialog.asksaveasfilename(filetypes=[("Numpy Files", "*.npy")])
root.destroy()
np.save(save_file_name, approved_data)
except Exception as e:
print(str(e))