-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGUI_Master_plant.py
274 lines (192 loc) · 8.46 KB
/
GUI_Master_plant.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
268
269
270
271
272
273
274
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 CNNModelp
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("Crop Disease and Pest Identification System")
#430
#++++++++++++++++++++++++++++++++++++++++++++
#####For background Image
image2 =Image.open('ff.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="Crop Disease & Pest Identification System", font=('times', 35,' bold '), height=1, width=32,bg="#7a3b2e",fg="white")
lbl.place(x=300, y=20)
frame_alpr = tk.LabelFrame(root, text=" --Process-- ", width=220, height=350, bd=5, font=('times', 14, ' bold '),bg="grey")
frame_alpr.grid(row=0, column=0, sticky='nw')
frame_alpr.place(x=10, y=90)
###########################################################################
def train_model():
update_label("Model Training Start...............")
start = time.time()
X= CNNModelp.main()
end = time.time()
ET="Execution Time: {0:.4} seconds \n".format(end-start)
msg="Model Training Completed.."+'\n'+ X + '\n'+ ET
print(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
#from keras.optimizers import Adam
# global fn
IMAGE_SIZE = 64
LEARN_RATE = 1.0e-4
CH=3
print(fn)
if fn!="":
# Model Architecture and Compilation
model = load_model('Plant_model.h5')
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))
plant=np.argmax(prediction)
print(plant)
if plant == 0:
Cd="Disease:Apple___Apple_scab \n Pest= Venturia inaequalis. "
elif plant == 8:
Cd="Disease:Apple___Black_rot \n Pest =xanthomonas campestris ,"
elif plant == 9:
Cd="Disease:Apple___Cedar_apple_rust \n Pest=gymnosporangium juniperi-virginianae"
elif plant == 10:
Cd="Apple___healthy"
elif plant == 11:
Cd="Disease:Corn_(maize)___Cercospora_leaf_spot Gray_leaf_spot \n Pest=Cercospora zeae-maydis."
elif plant == 12:
Cd="Disease:Corn_(maize)___Common_rust \n Pest=Puccinia sorghi."
elif plant == 13:
Cd="Corn_(maize)___healthy"
elif plant == 14:
Cd="Disease:Corn_(maize)___Northern_Leaf_Blight \n Pest=Bipolaris zeicola."
elif plant == 15:
Cd="Disease:Grape___Black_rot \n Pest=Guignardia bidwellii. "
elif plant == 1:
Cd="Disease:Grape___Esca_(Black_Measles) \n Pest= Phaeoacremonium aleophilum."
elif plant == 2:
Cd="Grape___healthy"
elif plant == 3:
Cd=" Disease:Grape___Leaf_blight_(Isariopsis_Leaf_Spot), \n Pest=Pseudocercospora vitis."
elif plant == 4:
Cd="Disease:Peach___Bacterial_spot \n Pest=Xanthomonas arboricola pv. pruni."
elif plant == 5:
Cd="Peach___healthy"
elif plant == 6:
Cd="Strawberry___healthy"
elif plant == 7:
Cd="Disease:Strawberry___Leaf_scorch, \n Pest=Diplocarpon earliana ."
A=Cd
return A
############################################################
def update_label(str_T):
#clear_img()
result_label = tk.Label(root, text=str_T, width=60, font=("bold", 20), bg='bisque2', fg='black')
result_label.place(x=250, y=400)
###############################################################################
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)
x2=format(X)+"\n Diesease is detected"
end = time.time()
ET="Execution Time: {0:.4} seconds \n".format(end-start)
msg="Image Testing Completed.."+'\n'+ x2 + '\n'+ ET
fn=""
else:
msg="Please Select Image For Prediction...."
update_label(msg)
#############################################################################
def openimage():
global fn
fileName = askopenfilename(initialdir='E:/Incource Ravina work/All code/100% code Plant Leaf Disease 2/Plant Leaf Disease', 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])
im = Image.fromarray(img)
imgtk = ImageTk.PhotoImage(im)
img = tk.Label(root, image=imgtk, height=250, width=250)
img.image = imgtk
img.place(x=300, y=100)
#############################################################################
def convert_grey():
global 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, image=imgtk, height=250, width=250,bg='white')
img2.image = imgtk
img2.place(x=580, y=100)
im = Image.fromarray(threshold)
imgtk = ImageTk.PhotoImage(image=im)
img3 = tk.Label(root, image=imgtk, 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 window():
root.destroy()
button1 = tk.Button(frame_alpr, text=" Select_Image ", command=openimage,width=15, height=1, font=('times', 15, ' bold '),bg="green",fg="white")
button1.place(x=10, y=40)
button2 = tk.Button(frame_alpr, text="Image_preprocess", command=convert_grey, width=15, height=1, font=('times', 15, ' bold '),bg="green",fg="white")
button2.place(x=10, y=100)
# 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=150)
#
button4 = tk.Button(frame_alpr, text="CNN_Prediction", command=test_model,width=15, height=1,bg="green",fg="white", font=('times', 15, ' bold '))
button4.place(x=10, y=160)
#
#
#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=220)
root.mainloop()