-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGUI_Master_old.py
More file actions
335 lines (219 loc) · 9.86 KB
/
GUI_Master_old.py
File metadata and controls
335 lines (219 loc) · 9.86 KB
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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
import tkinter as tk
from tkinter import ttk, LEFT, END
from PIL import Image , ImageTk
from tkinter.filedialog import askopenfilename
import cv2
import numpy as np
import time
import CNNModel
import sqlite3
#import tfModel_test as tf_test
global fn
fn=""
##############################################+=============================================================
root = tk.Tk()
root.configure(background="seashell2")
#root.geometry("1300x700")
w, h = root.winfo_screenwidth(), root.winfo_screenheight()
root.geometry("%dx%d+0+0" % (w, h))
root.title("Road Damage Detection")
#430
#++++++++++++++++++++++++++++++++++++++++++++
#####For background Image
image2 =Image.open('s1.jpg')
image2 =image2.resize((w,h), Image.ANTIALIAS)
background_image=ImageTk.PhotoImage(image2)
background_label = tk.Label(root, image=background_image)
background_label.image = background_image
background_label.place(x=0, y=0) #, relwidth=1, relheight=1)
#
lbl = tk.Label(root, text="Road Damage detection", font=('times', 35,' bold '), width=65,height=1,bg="Red3",fg="white")
lbl.place(x=0, y=0)
#frame_display = tk.LabelFrame(root, text=" --Display-- ", width=900, height=250, bd=5, font=('times', 14, ' bold '),bg="lightblue4")
#frame_display.grid(row=0, column=0, sticky='nw')
#frame_display.place(x=300, y=100)
#frame_display1 = tk.LabelFrame(root, text=" --Result-- ", width=900, height=200, bd=5, font=('times', 14, ' bold '),bg="lightblue4")
#frame_display1.grid(row=0, column=0, sticky='nw')
#frame_display1.place(x=300, y=430)
#frame_display2 = tk.LabelFrame(root, text=" --Calaries-- ", width=900, height=50, bd=5, font=('times', 14, ' bold '),bg="lightblue4")
#frame_display2.grid(row=0, column=0, sticky='nw')
#frame_display2.place(x=300, y=380)
frame_alpr = tk.LabelFrame(root, text=" --Process-- ", width=220, height=350, bd=5, font=('times', 14, ' bold '),bg="SeaGreen1")
frame_alpr.grid(row=0, column=0, sticky='nw')
frame_alpr.place(x=10, y=100)
def update_label1(str_T):
#clear_img()
result_label = tk.Label(root, text=str_T, width=40, font=("bold", 25), bg='bisque2', fg='black')
result_label.place(x=300, y=650)
################################$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
def update_cal(str_T):
#clear_img()
result_label = tk.Label(root, text=str_T, width=40, font=("bold", 25), bg='bisque2', fg='black')
result_label.place(x=350, y=350)
###########################################################################
def train_model():
update_label("Model Training Start...............")
start = time.time()
X= CNNModel.main()
print(X)
end = time.time()
ET="Execution Time: {0:.4} seconds \n".format(end-start)
msg="Model Training Completed.."+'\n'+ X + '\n'+ ET
update_label(msg)
import functools
import operator
def convert_str_to_tuple(tup):
s = functools.reduce(operator.add, (tup))
return s
def test_model_proc(fn):
from keras.models import load_model
IMAGE_SIZE = 64
LEARN_RATE = 1.0e-4
CH=3
print(fn)
if fn!="":
# Model Architecture and Compilation
model = load_model('road_model.h5')
# adam = Adam(lr=LEARN_RATE, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0)
# model.compile(optimizer=adam, loss='categorical_crossentropy', metrics=['accuracy'])
img = Image.open(fn)
img = img.resize((IMAGE_SIZE,IMAGE_SIZE))
img = np.array(img)
img = img.reshape(1,IMAGE_SIZE,IMAGE_SIZE,3)
img = img.astype('float32')
img = img / 255.0
print('img shape:',img)
prediction = model.predict(img)
print(np.argmax(prediction))
yoga=np.argmax(prediction)
print(yoga)
# myfile = open("1.txt")
# txt = myfile.read()
# print(txt)
# myfile.close()
if yoga == 0:
Cd="Road Damage Not Detected"
elif yoga == 1:
Cd="Road Damage Detected"
A=Cd
return A
img = open(fn)
myfile = open("D:/Code/Road Damage Detection/testing")
if img == myfile:
print(myfile)
# def clear_img():
# img11 = tk.Label(frame_display, background='lightblue4',width=160,height=120)
# img11.place(x=0, y=0)
def update_label(str_T):
#clear_img()
result_label = tk.Label(root, text=str_T, width=40, font=("bold", 25), bg='bisque2', fg='black')
result_label.place(x=300, y=420)
# def train_model():
# update_label("Model Training Start...............")
# start = time.time()
# X=Model_frm.main()
# end = time.time()
# ET="Execution Time: {0:.4} seconds \n".format(end-start)
# msg="Model Training Completed.."+'\n'+ X + '\n'+ ET
# update_label(msg)
def test_model():
global fn
if fn!="":
update_label("Model Testing Start...............")
start = time.time()
X=test_model_proc(fn)
X1="Selected Image is {0}".format(X)
end = time.time()
ET="Execution Time: {0:.4} seconds \n".format(end-start)
msg="Image Testing Completed.."+'\n'+ X1 + '\n'+ ET
fn=""
else:
msg="Please Select Image For Prediction...."
update_label(msg)
def openimage():
global fn
print(fn)
fileName = askopenfilename(initialdir='D:/Code/Road Damage Detection/testing', title='Select image for Aanalysis ',
filetypes=[("all files", "*.*")])
IMAGE_SIZE=200
imgpath = fileName
fn = fileName
# img = Image.open(imgpath).convert("L")
img = Image.open(imgpath)
img = img.resize((IMAGE_SIZE,200))
img = np.array(img)
# img = img / 255.0
# img = img.reshape(1,IMAGE_SIZE,IMAGE_SIZE,3)
x1 = int(img.shape[0])
y1 = int(img.shape[1])
#
# gs = cv2.cvtColor(cv2.imread(imgpath, 1), cv2.COLOR_RGB2GRAY)
#
# gs = cv2.resize(gs, (x1, y1))
#
# retval, threshold = cv2.threshold(gs, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)
im = Image.fromarray(img)
imgtk = ImageTk.PhotoImage(im)
img = tk.Label(root,text='Original',font=('times new roman', 20 ,'bold'), image=imgtk,compound='bottom', height=250, width=250)
#result_label1 = tk.Label(root, image=imgtk, width=250,height=250)
#result_label1.place(x=300, y=100)
img.image = imgtk
img.place(x=300, y=100)
# out_label.config(text=imgpath)
def convert_grey():
global fn
print(fn)
IMAGE_SIZE=200
img = Image.open(fn)
img = img.resize((IMAGE_SIZE,200))
img = np.array(img)
x1 = int(img.shape[0])
y1 = int(img.shape[1])
gs = cv2.cvtColor(cv2.imread(fn, 1), cv2.COLOR_RGB2GRAY)
gs = cv2.resize(gs, (x1, y1))
retval, threshold = cv2.threshold(gs, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)
print(threshold)
im = Image.fromarray(gs)
imgtk = ImageTk.PhotoImage(image=im)
#result_label1 = tk.Label(root, image=imgtk, width=250, font=("bold", 25), bg='bisque2', fg='black',height=250)
#result_label1.place(x=300, y=400)
img2 = tk.Label(root,text='Gray',font=('times new roman', 20 ,'bold'), image=imgtk,compound='bottom', height=250, width=250,bg='white')
img2.image = imgtk
img2.place(x=580, y=100)
#label_l1 = tk.Label(root, text='Gray' ,compound='bottom', width=4, height=1)
#label_l1.place(x=690, y=110)
im = Image.fromarray(threshold)
imgtk = ImageTk.PhotoImage(image=im)
img3 = tk.Label(root,text='Binary',font=('times new roman', 20 ,'bold'), image=imgtk,compound='bottom', height=250, width=250)
img3.image = imgtk
img3.place(x=880, y=100)
#result_label1 = tk.Label(root, image=imgtk, width=250,height=250, font=("bold", 25), bg='bisque2', fg='black')
#result_label1.place(x=300, y=400)
# def percentage(Width, Depth):
# return 100 * float(Width)/float(Depth)
# print(percentage(5, 7))
# # If you want to limit the number of decimal to 2, change the number in {:.2f} as you wish;
# print('{:.2f}'.format(percentage(5, 7)))
# your_value = 1/3.0
# print('{:.1%}'.format(your_value)) # Change the "1" to however many decimal places you need
# # Result:
# # '33.3%'
#################################################################################################################
def window():
root.destroy()
button1 = tk.Button(frame_alpr, text=" Select_Image ", command=openimage,width=15, height=1, font=('times', 15, ' bold '),bg="white",fg="black")
button1.place(x=10, y=50)
button2 = tk.Button(frame_alpr, text="Image_preprocess", command=convert_grey, width=15, height=1, font=('times', 15, ' bold '),bg="white",fg="black")
button2.place(x=10, y=120)
#button3 = tk.Button(frame_alpr, text="Train Model", command=train_model, width=12, height=1, font=('times', 15, ' bold '),bg="white",fg="black")
#button3.place(x=10, y=160)
#
button4 = tk.Button(frame_alpr, text="CNN_Prediction", command=test_model,width=15, height=1,bg="white",fg="black", font=('times', 15, ' bold '))
button4.place(x=10, y=190)
#
#
#button5 = tk.Button(frame_alpr, text="button5", command=window,width=8, height=1, font=('times', 15, ' bold '),bg="yellow4",fg="white")
#button5.place(x=450, y=20)
exit = tk.Button(frame_alpr, text="Exit", command=window, width=15, height=1, font=('times', 15, ' bold '),bg="red",fg="white")
exit.place(x=10, y=260)
root.mainloop()