-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathrealtimedetection.py
More file actions
37 lines (33 loc) · 1.31 KB
/
realtimedetection.py
File metadata and controls
37 lines (33 loc) · 1.31 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
from keras.models import model_from_json
import cv2
import numpy as np
json_file = open("signlanguagedetectionmodel48x48.json", "r")
model_json = json_file.read()
json_file.close()
model = model_from_json(model_json)
model.load_weights("signlanguagedetectionmodel48x48.h5")
def extract_features(image):
feature = np.array(image)
feature = feature.reshape(1,48,48,1)
return feature/255.0
cap = cv2.VideoCapture(0)
label = ['A', 'M', 'N', 'S', 'T', 'blank']
while True:
_,frame = cap.read()
cv2.rectangle(frame,(0,40),(300,300),(0, 165, 255),1)
cropframe=frame[40:300,0:300]
cropframe=cv2.cvtColor(cropframe,cv2.COLOR_BGR2GRAY)
cropframe = cv2.resize(cropframe,(48,48))
cropframe = extract_features(cropframe)
pred = model.predict(cropframe)
prediction_label = label[pred.argmax()]
cv2.rectangle(frame, (0,0), (300, 40), (0, 165, 255), -1)
if prediction_label == 'blank':
cv2.putText(frame, " ", (10, 30),cv2.FONT_HERSHEY_SIMPLEX,1, (255, 255, 255),2,cv2.LINE_AA)
else:
accu = "{:.2f}".format(np.max(pred)*100)
cv2.putText(frame, f'{prediction_label} {accu}%', (10, 30),cv2.FONT_HERSHEY_SIMPLEX,1, (255, 255, 255),2,cv2.LINE_AA)
cv2.imshow("output",frame)
cv2.waitKey(27)
cap.release()
cv2.destroyAllWindows()