-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
53 lines (45 loc) · 1.21 KB
/
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
44
45
46
47
48
49
50
51
52
53
# %%
import keras
import cv2
import time
from utils.config import project_config as pj
from core import drowsiness_detector
cap = cv2.VideoCapture(0)
model = keras.models.load_model(pj.MODEL_PATH1)
alarm_on = False
show_fps = 1
detector = drowsiness_detector.DrowsinessDetector("yolo", model)
if show_fps:
num_frames = 0
while cap.isOpened():
success, frame = cap.read()
if not success:
print(
"Video frame is empty or video processing has been successfully completed."
)
break
start_time = time.time()
frame = detector.detect_drosiness(frame)
# Caculate FPS
if show_fps:
num_frames += 1
elapsed_time = time.time() - start_time
fps = num_frames / elapsed_time
num_frames = 0
cv2.putText(
frame,
f"FPS: {round(fps, 2)}",
(510, 30),
cv2.FONT_HERSHEY_SIMPLEX,
1,
(0, 255, 0),
1,
cv2.LINE_AA,
)
cv2.imshow("Drowsiness Detector", frame)
key = cv2.waitKey(1) & 0xFF
# Check if user presses "q" key or ESC button, exit while loop
if key == ord("q") or key == 27:
break
cap.release()
cv2.destroyAllWindows()