Skip to content

Commit 5047010

Browse files
authored
Add files via upload
1 parent eedc61b commit 5047010

20 files changed

+103490
-2
lines changed

CNN_predict.py

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
from keras.models import load_model
2+
import cv2
3+
import numpy as np
4+
import tkinter as tk
5+
from PIL import ImageTk, Image
6+
from tkinter import filedialog
7+
from tkinter import StringVar
8+
from tkinter import Entry
9+
10+
#This creates the main window of an application
11+
window = tk.Tk()
12+
window.title("Join")
13+
window.geometry("900x900")
14+
window.configure(background='grey')
15+
16+
frame = tk.Frame(window, bg='black')
17+
frame.pack(fill='both', expand='yes')
18+
19+
path = filedialog.askopenfilename()
20+
img = ImageTk.PhotoImage(Image.open(path))
21+
22+
#The Label widget is a standard Tkinter widget used to display a text or image on the screen.
23+
panel = tk.Label(frame, image = img)
24+
panel.place(x=100,y=20)
25+
#The Pack geometry manager packs widgets in rows or columns.
26+
#panel.pack(side = "bottom", fill = "both", expand = "yes")
27+
#mainFrame = tk.Frame(window)
28+
#mainFrame.grid()
29+
#entryFrame = tk.Frame(mainFrame, width=454, height=20)
30+
#entryFrame.grid(row=0, column=1)
31+
32+
33+
34+
#v = StringVar()
35+
#e = Entry(frame, textvariable=v, width=200)
36+
#e.place(x=20,y=700)
37+
#e.pack(ipady=3)
38+
39+
model = load_model('model3.h5')
40+
41+
model.compile(loss='categorical_crossentropy',
42+
optimizer='rmsprop',
43+
metrics=['accuracy'])
44+
45+
# Set the path of the image to be classified
46+
img1 = cv2.imread(path)
47+
font = cv2.FONT_HERSHEY_SIMPLEX
48+
49+
while True:
50+
cv2.namedWindow("show",0)
51+
new_img = img1.copy()
52+
new_img = cv2.resize(new_img,(150,150))
53+
new_img = np.reshape(new_img,[1,150,150,3])
54+
cv2.putText(img1,'OpenCV',(5,160), font, 0.5,(255,0,0),1,cv2.LINE_AA)
55+
cla = model.predict_classes(new_img)
56+
#v.set("a default value")
57+
print (cla[0])
58+
if(cla[0] == 1):
59+
label = tk.Label(frame, text="Alert! You're turning towards the right & texting instead of concentrating on driving straight. ")
60+
label.place(x=100, y=600)
61+
#v.set ("This image can be described as a bar chart which represents data with rectangular bars with heights proportional to the values that they represent.")
62+
elif(cla[0] == 2):
63+
label = tk.Label(frame, text="Alert! You're turning towards the right & talking over phone instead of concentrating on driving straight.")
64+
label.place(x=100, y=600)
65+
#v.set ("This image is a graph of a function. It has x and y axes with curves and lines depicting a function.")
66+
elif(cla[0] == 3):
67+
label = tk.Label(frame, text="Alert! You're turning towards the left & texting instead of concentrating on driving straight.")
68+
label.place(x=100, y=600)
69+
#v.set ("This image has a geometrical figure.")
70+
elif(cla[0] == 4):
71+
label = tk.Label(frame, text="Alert! You're turning towards the left & talking over phone instead of concentrating on driving straight.")
72+
label.place(x=100, y=600)
73+
#v.set ("This image is a line graph in which information is displayed as a series of data points connected by straight line segments.")
74+
elif(cla[0] == 5):
75+
label = tk.Label(frame, text="Alert! You're operating on the radio instead of concentrating on driving straight. ")
76+
label.place(x=100,y=600)
77+
#v.set ("This image is a mapping of function which shows the relations of inputs and output in form of ordered pair. ")
78+
elif(cla[0] == 6):
79+
label = tk.Label(frame, text="Alert! You're drinking instead of concentrating on driving straight.")
80+
label.place(x=100, y=600)
81+
#v.set ("This image doesnot belong to any mathematical representation or figures.")
82+
elif(cla[0] == 7):
83+
label = tk.Label(frame, text="Alert! You're reaching behind instead of concentrating on driving straight.")
84+
label.place(x=100, y=600)
85+
#v.set ("This image is a pie chart, a circle which is divided into sectors that each represent a proportion of the whole.")
86+
elif(cla[0] == 8):
87+
label = tk.Label(frame, text="Alert! You're preoccupied with the mirror instead of concentrating on driving straight.")
88+
label.place(x=100, y=600)
89+
#v.set ("This image is a graph with x and y axes where points are plotted and drawn.")
90+
elif(cla[0] == 9):
91+
label = tk.Label(frame, text="You're driving attentively.")
92+
label.place(x=350, y=600)
93+
elif(cla[0] == 0):
94+
label = tk.Label(frame, text="You're driving attentively.")
95+
label.place(x=350, y=600)
96+
#v.set ("This image is a venn diagram in which logical sets represented as circles or closed curves within an enclosing rectangle,the universal set.")
97+
cv2.imshow("show",img1)
98+
99+
#Start the GUI
100+
window.mainloop()
101+
if cv2.waitKey(0) & 0xFF == ord('q'):
102+
break
103+
104+
def write(string):
105+
text_box.config(state=Tkinter.NORMAL)
106+
text_box.insert("end", string + "\n")
107+
text_box.see("end")
108+
text_box.config(state=Tkinter.DISABLED)

CNN_predict1.py

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
from keras.models import load_model
2+
import cv2
3+
import numpy as np
4+
import tkinter as tk
5+
from PIL import ImageTk, Image
6+
from tkinter import filedialog
7+
from tkinter import StringVar
8+
from tkinter import Entry
9+
10+
#This creates the main window of an application
11+
window = tk.Tk()
12+
window.title("Join")
13+
window.geometry("900x900")
14+
window.configure(background='grey')
15+
16+
frame = tk.Frame(window, bg='black')
17+
frame.pack(fill='both', expand='yes')
18+
19+
path = filedialog.askopenfilename()
20+
img = ImageTk.PhotoImage(Image.open(path))
21+
22+
#The Label widget is a standard Tkinter widget used to display a text or image on the screen.
23+
panel = tk.Label(frame, image = img)
24+
panel.place(x=100,y=20)
25+
#The Pack geometry manager packs widgets in rows or columns.
26+
#panel.pack(side = "bottom", fill = "both", expand = "yes")
27+
#mainFrame = tk.Frame(window)
28+
#mainFrame.grid()
29+
#entryFrame = tk.Frame(mainFrame, width=454, height=20)
30+
#entryFrame.grid(row=0, column=1)
31+
32+
33+
34+
#v = StringVar()
35+
#e = Entry(frame, textvariable=v, width=200)
36+
#e.place(x=20,y=700)
37+
#e.pack(ipady=3)
38+
39+
model = load_model('model3.h5')
40+
41+
model.compile(loss='categorical_crossentropy',
42+
optimizer='rmsprop',
43+
metrics=['accuracy'])
44+
45+
# Set the path of the image to be classified
46+
img1 = cv2.imread(path)
47+
font = cv2.FONT_HERSHEY_SIMPLEX
48+
49+
while True:
50+
cv2.namedWindow("show",0)
51+
new_img = img1.copy()
52+
new_img = cv2.resize(new_img,(150,150))
53+
new_img = np.reshape(new_img,[1,150,150,3])
54+
cv2.putText(img1,'OpenCV',(5,160), font, 0.5,(255,0,0),1,cv2.LINE_AA)
55+
cla = model.predict_classes(new_img)
56+
#v.set("a default value")
57+
print (cla[0])
58+
if(cla[0] == 1):
59+
label = tk.Label(frame, text="Alert! You're turning towards the right & texting instead of concentrating on driving straight. ")
60+
label.place(x=100, y=600)
61+
#v.set ("This image can be described as a bar chart which represents data with rectangular bars with heights proportional to the values that they represent.")
62+
elif(cla[0] == 2):
63+
label = tk.Label(frame, text="Alert! You're turning towards the right & talking over phone instead of concentrating on driving straight.")
64+
label.place(x=100, y=600)
65+
#v.set ("This image is a graph of a function. It has x and y axes with curves and lines depicting a function.")
66+
elif(cla[0] == 3):
67+
label = tk.Label(frame, text="Alert! You're turning towards the left & texting instead of concentrating on driving straight.")
68+
label.place(x=100, y=600)
69+
#v.set ("This image has a geometrical figure.")
70+
elif(cla[0] == 4):
71+
label = tk.Label(frame, text="Alert! You're turning towards the left & talking over phone instead of concentrating on driving straight.")
72+
label.place(x=100, y=600)
73+
#v.set ("This image is a line graph in which information is displayed as a series of data points connected by straight line segments.")
74+
elif(cla[0] == 5):
75+
label = tk.Label(frame, text="Alert! You're operating on the radio instead of concentrating on driving straight. ")
76+
label.place(x=100,y=600)
77+
#v.set ("This image is a mapping of function which shows the relations of inputs and output in form of ordered pair. ")
78+
elif(cla[0] == 6):
79+
label = tk.Label(frame, text="Alert! You're drinking instead of concentrating on driving straight.")
80+
label.place(x=100, y=600)
81+
#v.set ("This image doesnot belong to any mathematical representation or figures.")
82+
elif(cla[0] == 7):
83+
label = tk.Label(frame, text="Alert! You're reaching behind instead of concentrating on driving straight.")
84+
label.place(x=100, y=600)
85+
#v.set ("This image is a pie chart, a circle which is divided into sectors that each represent a proportion of the whole.")
86+
elif(cla[0] == 8):
87+
label = tk.Label(frame, text="Alert! You're preoccupied with the mirror instead of concentrating on driving straight.")
88+
label.place(x=100, y=600)
89+
#v.set ("This image is a graph with x and y axes where points are plotted and drawn.")
90+
elif(cla[0] == 9):
91+
label = tk.Label(frame, text="Alert! You're turning towards the right & texting instead of concentrating on driving straight.")
92+
label.place(x=100, y=600)
93+
elif(cla[0] == 0):
94+
label = tk.Label(frame, text="You're driving attentively.")
95+
label.place(x=350, y=600)
96+
#v.set ("This image is a venn diagram in which logical sets represented as circles or closed curves within an enclosing rectangle,the universal set.")
97+
cv2.imshow("show",img1)
98+
99+
#Start the GUI
100+
window.mainloop()
101+
if cv2.waitKey(0) & 0xFF == ord('q'):
102+
break
103+
104+
def write(string):
105+
text_box.config(state=Tkinter.NORMAL)
106+
text_box.insert("end", string + "\n")
107+
text_box.see("end")
108+
text_box.config(state=Tkinter.DISABLED)

CNN_predict2.py

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
from keras.models import load_model
2+
import cv2
3+
import numpy as np
4+
import tkinter as tk
5+
from PIL import ImageTk, Image
6+
from tkinter import filedialog
7+
from tkinter import StringVar
8+
from tkinter import Entry
9+
10+
#This creates the main window of an application
11+
window = tk.Tk()
12+
window.title("Join")
13+
window.geometry("900x900")
14+
window.configure(background='grey')
15+
16+
frame = tk.Frame(window, bg='black')
17+
frame.pack(fill='both', expand='yes')
18+
19+
path = filedialog.askopenfilename()
20+
img = ImageTk.PhotoImage(Image.open(path))
21+
22+
#The Label widget is a standard Tkinter widget used to display a text or image on the screen.
23+
panel = tk.Label(frame, image = img)
24+
panel.place(x=100,y=20)
25+
#The Pack geometry manager packs widgets in rows or columns.
26+
#panel.pack(side = "bottom", fill = "both", expand = "yes")
27+
#mainFrame = tk.Frame(window)
28+
#mainFrame.grid()
29+
#entryFrame = tk.Frame(mainFrame, width=454, height=20)
30+
#entryFrame.grid(row=0, column=1)
31+
32+
33+
34+
#v = StringVar()
35+
#e = Entry(frame, textvariable=v, width=200)
36+
#e.place(x=20,y=700)
37+
#e.pack(ipady=3)
38+
39+
model = load_model('model3.h5')
40+
41+
model.compile(loss='categorical_crossentropy',
42+
optimizer='rmsprop',
43+
metrics=['accuracy'])
44+
45+
# Set the path of the image to be classified
46+
img1 = cv2.imread(path)
47+
font = cv2.FONT_HERSHEY_SIMPLEX
48+
49+
while True:
50+
cv2.namedWindow("show",0)
51+
new_img = img1.copy()
52+
new_img = cv2.resize(new_img,(150,150))
53+
new_img = np.reshape(new_img,[1,150,150,3])
54+
cv2.putText(img1,'OpenCV',(5,160), font, 0.5,(255,0,0),1,cv2.LINE_AA)
55+
cla = model.predict_classes(new_img)
56+
#v.set("a default value")
57+
print (cla[0])
58+
if(cla[0] == 1):
59+
label = tk.Label(frame, text="Alert! You're turning towards the right & texting instead of concentrating on driving straight. ")
60+
label.place(x=100, y=600)
61+
#v.set ("This image can be described as a bar chart which represents data with rectangular bars with heights proportional to the values that they represent.")
62+
elif(cla[0] == 2):
63+
label = tk.Label(frame, text="Alert! You're turning towards the right & talking over phone instead of concentrating on driving straight.")
64+
label.place(x=100, y=600)
65+
#v.set ("This image is a graph of a function. It has x and y axes with curves and lines depicting a function.")
66+
elif(cla[0] == 3):
67+
label = tk.Label(frame, text="Alert! You're turning towards the left & texting instead of concentrating on driving straight.")
68+
label.place(x=100, y=600)
69+
#v.set ("This image has a geometrical figure.")
70+
elif(cla[0] == 4):
71+
label = tk.Label(frame, text="Alert! You're turning towards the left & talking over phone instead of concentrating on driving straight.")
72+
label.place(x=100, y=600)
73+
#v.set ("This image is a line graph in which information is displayed as a series of data points connected by straight line segments.")
74+
elif(cla[0] == 5):
75+
label = tk.Label(frame, text="Alert! You're operating on the radio instead of concentrating on driving straight. ")
76+
label.place(x=100,y=600)
77+
#v.set ("This image is a mapping of function which shows the relations of inputs and output in form of ordered pair. ")
78+
elif(cla[0] == 6):
79+
label = tk.Label(frame, text="Alert! You're drinking instead of concentrating on driving straight.")
80+
label.place(x=100, y=600)
81+
#v.set ("This image doesnot belong to any mathematical representation or figures.")
82+
elif(cla[0] == 7):
83+
label = tk.Label(frame, text="Alert! You're reaching behind instead of concentrating on driving straight.")
84+
label.place(x=100, y=600)
85+
#v.set ("This image is a pie chart, a circle which is divided into sectors that each represent a proportion of the whole.")
86+
elif(cla[0] == 8):
87+
label = tk.Label(frame, text="Alert! You're preoccupied with the mirror instead of concentrating on driving straight.")
88+
label.place(x=100, y=600)
89+
#v.set ("This image is a graph with x and y axes where points are plotted and drawn.")
90+
elif(cla[0] == 9):
91+
label = tk.Label(frame, text="Alert! You're turning towards the right & talking over phone instead of concentrating on driving straight.")
92+
label.place(x=100, y=600)
93+
elif(cla[0] == 0):
94+
label = tk.Label(frame, text="You're driving attentively.")
95+
label.place(x=350, y=600)
96+
#v.set ("This image is a venn diagram in which logical sets represented as circles or closed curves within an enclosing rectangle,the universal set.")
97+
cv2.imshow("show",img1)
98+
99+
#Start the GUI
100+
window.mainloop()
101+
if cv2.waitKey(0) & 0xFF == ord('q'):
102+
break
103+
104+
def write(string):
105+
text_box.config(state=Tkinter.NORMAL)
106+
text_box.insert("end", string + "\n")
107+
text_box.see("end")
108+
text_box.config(state=Tkinter.DISABLED)

0 commit comments

Comments
 (0)