-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
43 lines (31 loc) · 963 Bytes
/
main.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
# import libraries
import cv2
from src.utils.load_model import load_saved_model
from src.utils.prediction import predict_letter
# load the model
model = load_saved_model('3_sl_aug_model')
# capture the video
cap = cv2.VideoCapture(0)
while True:
ret, frame = cap.read()
# Region of interest
roi = frame[40:300, 50:350]
# draw rectangle
cv2.rectangle(frame, (40, 50), (300, 350), (255, 0, 0), 4)
# convert to grayscale
roi = cv2.cvtColor(roi, cv2.COLOR_BGR2GRAY)
# resize ROI into 28x28
roi = cv2.resize(roi, (28, 28), interpolation=cv2.INTER_AREA)
cv2.imshow('roi', roi)
result = predict_letter(model, roi)
cv2.putText(
frame, result, (300, 100),
cv2.FONT_HERSHEY_COMPLEX, 2, (0, 255, 0),
2)
cv2.imshow('frame', frame)
# close by pressing 'q'
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# release the capture and windows
cap.release()
cv2.destroyAllWindows()