-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.py
152 lines (117 loc) · 3.48 KB
/
script.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
import os
import cv2
from tensorflow.keras.models import load_model
import matplotlib.pyplot as plt
import numpy as np
from PIL import Image
import time
import collections
import win32com.client as winc1
v = winc1.Dispatch("SAPI.SpVoice")
# Loading the model
model = load_model('hack36_2.h5')
def max_char(text):
return collections.Counter(text).most_common(1)[0][0]
# Don't touch this cell
video = cv2.VideoCapture(0)
text=''
flag=[]
frame_count = 0
while True:
_, frame = video.read()
cv2.rectangle(frame,pt1=(100,100),pt2=(300,300),color=(0,255,0),thickness=6)
frame_count += 1
if frame_count%150 == 0:
im = Image.fromarray(frame, 'RGB')
img_array = np.asarray(frame)
clone = img_array[100:300, 100:300].copy()
clone_resized = cv2.resize(clone, (64,64))
img_array=clone_resized/255
img_final = np.expand_dims(img_array, axis=0)
prediction = model.predict(img_final)
label = np.argmax(prediction)
if label == 0:
ch = 'A'
elif label == 1:
ch = 'B'
elif label == 2:
ch = 'C'
elif label == 3:
ch = 'D'
elif label == 4:
ch = 'E'
elif label == 5:
ch = 'F'
elif label == 6:
ch = 'G'
elif label == 7:
ch = 'H'
elif label == 8:
ch = 'I'
elif label == 9:
ch = 'J'
elif label == 10:
ch = 'K'
elif label == 11:
ch = 'L'
elif label == 12:
ch = 'M'
elif label == 13:
ch = 'N'
elif label == 14:
ch = 'O'
elif label == 15:
ch = 'P'
elif label == 16:
ch = 'Q'
elif label == 17:
ch = 'R'
elif label == 18:
ch = 'S'
elif label == 19:
ch = 'T'
elif label == 20:
ch = 'U'
elif label == 21:
ch = 'V'
elif label == 22:
ch = 'W'
elif label == 23:
ch = 'X'
elif label == 24:
ch = 'Y'
elif label == 25:
ch = 'Z'
elif label == 26:
# m = max_char(text)
# text=m
# flag=flag+text
# text=''
# Delete
ch=''
# text = ''
elif label == 27:#Nothing
# m = max_char(text)
# flag = flag + m
ch=''
elif label == 28: # Space
ch = ' '
print('space')
flag.append(ch)
print(ch)
cv2.imshow("Capturing", frame)
key=cv2.waitKey(1)
if key == ord('q'):
break
text=''
for i in flag:
text+=i
# for i in range(len(flag)):
# if (i==0 and flag[i] == '*'):
# continue
# elif(flag[i]=='*'):
# text=text+flag[i-1]
video.release()
cv2.destroyAllWindows()
print(text)
v.Speak(text)