-
Notifications
You must be signed in to change notification settings - Fork 2
/
Predict.py
36 lines (26 loc) · 812 Bytes
/
Predict.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
import numpy as np
from keras.models import model_save
import operator
import cv2
import sys, os
loaded_model=model_save
cap = cv2.VideoCapture(0)
while True:
_, frame = cap.read()
frame = cv2.flip(frame, 1)
x1 = int(0.5*frame.shape[1])
y1 = 10
x2 = frame.shape[1]-10
y2 = int(0.5*frame.shape[1])
cv2.rectangle(frame, (x1-1, y1-1), (x2+1, y2+1), (255,0,0) ,1)
roi = frame[y1:y2, x1:x2]
roi = cv2.resize(roi, (64, 64))
roi = cv2.cvtColor(roi, cv2.COLOR_BGR2GRAY)
_, test_image = cv2.threshold(roi, 120, 255, cv2.THRESH_BINARY)
cv2.imshow("test", test_image)
result = loaded_model.predict(test_image.reshape(1, 64, 64, 1))
interrupt = cv2.waitKey(10)
if interrupt & 0xFF == 27:
break
cap.release()
cv2.destroyAllWindows()