-
Notifications
You must be signed in to change notification settings - Fork 1
/
util.py
49 lines (39 loc) · 1.46 KB
/
util.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
import cv2
import numpy as np
import winsound
from datetime import datetime
# Determine the center point of the given shape
def calc_center(indexes, points, img, draw=False):
(cx, cy), radius = cv2.minEnclosingCircle(
points[indexes])
center = np.array([cx, cy], dtype=np.int32)
if draw:
cv2.circle(img, center, int(radius),
(0, 0, 255), 1, cv2.LINE_AA)
return center
# Determine the direction of the eye
def eye_direction(iris_center, eye_center):
if abs(iris_center[0] - eye_center[0]) < 5:
return "CENTER"
elif iris_center[0] - eye_center[0] < 0:
return "LEFT"
elif iris_center[0]-eye_center[0] > 0:
return "RIGHT"
# Play the audio file
def play_sound():
audio_file = "warning.wav"
winsound.PlaySound(audio_file, winsound.SND_FILENAME)
# Warn the user and the supervisor that their attention is elsewhere
# and should pay attention to the screen
def warn(img):
h, w, c = img.shape
cv2.rectangle(img, (0,0), (w, h), (0, 0, 255), -1)
cv2.putText(img, "You have lost focus", (150, 250), cv2.FONT_HERSHEY_PLAIN, 2, (255, 255, 255), 4)
cv2.imshow("ADHD Aid", img)
cv2.waitKey(1)
play_sound()
# Record when the user first loses focus into log.txt
now = datetime.now()
cur_time = now.strftime("%H:%M:%S")
with open("log.txt", "a") as f:
f.write("User has lost focus from " + cur_time + " to ")