forked from fchrgrib/Algeo02-21015
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Geo Face.py
267 lines (228 loc) · 5.92 KB
/
Geo Face.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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# Import modules -------------------------------------------
import os
from tkinter import *
from tkinter import filedialog
from tkinter.messagebox import showerror
from PIL import ImageTk, Image
import time
# Import custom modules ------------------------------------
import src.backend.calculateFace as searchFace
# Initialization -------------------------------------------
window = Tk()
window.configure(bg="white")
window.geometry("1040x720")
window.resizable(False, False)
window.title("GeoFace")
window.iconbitmap("src/frontend/img/geoface.ico")
# Variables ------------------------------------------------
# 1. Dataset
DATASET = StringVar()
DATASET.set("")
DATASET_PLACEHOLDER = StringVar()
DATASET_PLACEHOLDER.set("No data chosen")
# 2. Image input
YOUR_IMAGE_PATH = StringVar()
YOUR_IMAGE_PATH.set("")
YOUR_IMAGE_PLACEHOLDER = StringVar()
YOUR_IMAGE_PLACEHOLDER.set("No file chosen")
# 3. Result Percent
RESULT_STR = StringVar()
RESULT_STR.set("0% Similar")
# 4. Counter
total_counter = 0
COUNTER_STR = StringVar()
COUNTER_STR.set(f"{total_counter:.2f} seconds")
# 5. Result Image
RESULT_IMG_PATH = StringVar()
RESULT_IMG_PATH.set("")
# Functions ------------------------------------------------
def openFolder():
DATASET_STR = filedialog.askdirectory(
initialdir=".\\",
title = "Choose data set",
)
if DATASET_STR:
DATASET.set(DATASET_STR)
DATASET_PLACEHOLDER.set(os.path.basename(DATASET_STR))
def openFile():
YOUR_IMAGE_STR = filedialog.askopenfilename(
initialdir=".\\",
title = "Choose file",
filetypes = (("jpg files", "*.jpg"),
("png files", "*.png"),
("all files", "*.*"))
)
if YOUR_IMAGE_STR:
YOUR_IMAGE_PATH.set(YOUR_IMAGE_STR)
YOUR_IMAGE_PLACEHOLDER.set(os.path.basename(YOUR_IMAGE_STR))
yourImage_img = Image.open(YOUR_IMAGE_PATH.get()).resize((280, 280))
yourImage_img = ImageTk.PhotoImage(yourImage_img)
yourImage_label.configure(image = yourImage_img)
yourImage_label.image = yourImage_img
def calculateFace():
if (DATASET.get() != "") & (YOUR_IMAGE_PATH.get() != ""):
# Start timer
start_counter = time.time()
# Loading (not working)
counter_label.config(text="Loading...")
# Call main backend
print("Calculating face...")
print("*do not minimize the program*")
TEMP, SIMILARITY = searchFace.main(DATASET.get(), YOUR_IMAGE_PATH.get())
RESULT_IMG_PATH.set(TEMP)
# Configure similarity label
RESULT_STR.set(f"{SIMILARITY:.2f}% Similar")
# Configure output iamge label
resultImage_img = Image.open(RESULT_IMG_PATH.get()).resize((280, 280))
resultImage_img = ImageTk.PhotoImage(resultImage_img)
resultImage_label.configure(image = resultImage_img)
resultImage_label.image = resultImage_img
# End timer
end_counter = time.time()
total_counter = end_counter - start_counter
COUNTER_STR.set(f"{total_counter:.2f} seconds")
else:
showerror(title="Error", message="Data set and Image are invalid")
# Components -----------------------------------------------
# 1. Canvas
canvas = Canvas(
window,
bg = "#fff",
height = 720,
width = 1080,
bd = 0,
highlightthickness = 0,
relief = "ridge"
)
canvas.place(x=0,y=0)
# 2. Background
background_img = PhotoImage(file = f"src/frontend/img/main-background.png")
background = canvas.create_image(
540.0, 360.0,
image = background_img
)
# 3. Buttons
button1_img = PhotoImage(file = f"src/frontend/img/button1.png")
button1_entry = Button(
image = button1_img,
borderwidth = 0,
highlightthickness = 0,
command = openFolder,
relief = "flat"
)
button1_entry.place(
x = 76, y = 270,
width = 115,
height = 40
)
button2_img = PhotoImage(file = f"src/frontend/img/button2.png")
button2_entry = Button(
image = button2_img,
borderwidth = 0,
highlightthickness = 0,
command = openFile,
relief = "flat"
)
button2_entry.place(
x = 76, y = 375,
width = 100,
height = 40
)
button3_img = PhotoImage(file = f"src/frontend/img/search.png")
button3_entry = Button(
image = button3_img,
borderwidth = 0,
highlightthickness = 0,
command = calculateFace,
relief = "flat"
)
button3_entry.place(
x = 76, y = 475,
width = 210,
height = 35
)
# 4. Labels
label1_label = Label(
canvas,
textvariable = DATASET_PLACEHOLDER,
font = ("Poppins", 11),
fg = "#8B8B8B",
borderwidth = 0,
background = "#fff",
highlightthickness= 0,
anchor = "w",
padx = 10
)
label1_label.place(
x = 190, y = 270,
width = 190,
height = 40,
)
label2_label = Label(
canvas,
textvariable = YOUR_IMAGE_PLACEHOLDER,
font = ("Poppins", 11),
fg = "#8B8B8B",
borderwidth = 0,
background = "#fff",
highlightthickness= 0,
anchor = "w",
padx = 10
)
label2_label.place(
x = 180, y = 375,
width = 190,
height = 40,
)
result_label = Label(
canvas,
textvariable= RESULT_STR,
font = ("Poppins", 14, "bold"),
fg = "#86FFA8",
borderwidth = 0,
background = "#fff",
highlightthickness= 0,
anchor = "w",
padx = 10
)
result_label.place(
x = 68, y = 555,
width = 190,
height = 40,
)
counter_label = Label(
canvas,
textvariable = COUNTER_STR,
font = ("Poppins", 14),
fg = "#000",
borderwidth = 0,
background = "#fff",
highlightthickness = 0,
anchor= "w",
padx = 10
)
counter_label.place(
x = 400, y = 555,
width = 190,
height = 40
)
# 5. Image Label
yourImage_label = Label(
canvas,
width = 280, height = 280
)
yourImage_label.place(
x = 408, y = 235,
width = 280,
height = 280
)
resultImage_label = Label(
canvas,
width = 280, height = 280
)
resultImage_label.place(
x = 714, y = 235,
width = 280,
height = 280
)
window.mainloop()