Repository navigation
Expand file tree
/
Copy pathtest.py
More file actions
53 lines (46 loc) · 1.38 KB
/
Copy pathtest.py
File metadata and controls
53 lines (46 loc) · 1.38 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
import numpy as np
import cv2
import pickle
from keras.models import load_model
########### PARAMETERS ##############
width = 640
height = 480
threshold = 0.55 # MINIMUM PROBABILITY TO CLASSIFY
cameraNo = 0
#####################################
#### CREATE CAMERA OBJECT
cap = cv2.VideoCapture(cameraNo)
cap.set(3,width)
cap.set(4,height)
#### LOAD THE TRAINNED MODEL
# pickle_in = open("model_trained_10.p","rb")
# model = pickle.load(pickle_in)
model = load_model('model.h5')
#### PREPORCESSING FUNCTION
def preProcessing(img):
img = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
img = cv2.equalizeHist(img)
img = img/255
return img
while True:
success, imgOriginal = cap.read()
# imgOriginal = cv2.imread('10.png')
img = np.asarray(imgOriginal)
img = cv2.resize(img,(32,32))
img = preProcessing(img)
cv2.imshow("Processsed Image",img)
img = img.reshape(1,32,32,1)
#### PREDICT
classIndex = int(model.predict_classes(img))
#print(classIndex)
predictions = model.predict(img)
#print(predictions)
probVal= np.amax(predictions)
print(classIndex,probVal)
if probVal> threshold:
cv2.putText(imgOriginal,str(classIndex) + " "+str(probVal),
(50,50),cv2.FONT_HERSHEY_COMPLEX,
1,(0,0,255),1)
cv2.imshow("Original Image",imgOriginal)
if cv2.waitKey(1) and 0xFF == 27 :
break