-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclassify1.py
61 lines (55 loc) · 1.57 KB
/
classify1.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
from keras.preprocessing.image import img_to_array
from keras.models import load_model
import numpy as np
import argparse
import imutils
import pickle
import cv2
import os
import copy
import operator
dicto = {}
dicto["A"] = 0
dicto["B"] = 0
dicto["C"] = 0
dicto["G"] = 0
dicto["O"] = 0
dicto["P"] = 0
dicto["Q"] = 0
dicto["V"] = 0
dicto["W"] = 0
dicto["Y"] = 0
count = [0]
class Classify:
@staticmethod
def outputclass(InputImage,Model,Lb):
image = InputImage
cv2.imshow("received image",image)
image = cv2.resize(image, (160, 160))
L1 = cv2.Canny(image,50,280,L2gradient=False)
cv2.imshow("canny",L1)
image = L1.astype("float") / 255.0
image = img_to_array(image)
image = np.expand_dims(image, axis=0)
model = Model
lb = Lb
proba = model.predict(image)[0]
idx = np.argmax(proba)
label = lb.classes_[idx]
dicto[str(label)] = dicto[str(label)]+1
count[0] = count[0]+1
if(count[0]==20):
print("[INFO] classifying image...")
print(max(dicto.keys(),key = (lambda k: dicto[k])))
count[0] = 0
dicto["A"] = 0
dicto["B"] = 0
dicto["C"] = 0
dicto["G"] = 0
dicto["O"] = 0
dicto["P"] = 0
dicto["Q"] = 0
dicto["V"] = 0
dicto["W"] = 0
dicto["Y"] = 0
return label