-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.py
59 lines (43 loc) · 1.51 KB
/
utils.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
54
55
56
57
58
59
# AS2018946
# Pasindu Udayanga
import numpy as np
# Returns EAR given eye landmarks
def eye_aspect_ratio(eye):
# Compute the euclidean distances between the two sets of
# vertical eye landmarks (x, y)-coordinates
A = np.linalg.norm(eye[1] - eye[5])
B = np.linalg.norm(eye[2] - eye[4])
# Compute the euclidean distance between the horizontal
# eye landmark (x, y)-coordinates
C = np.linalg.norm(eye[0] - eye[3])
# Compute the eye aspect ratio
ear = (A + B) / (2.0 * C)
# Return the eye aspect ratio
return ear
# Returns MAR given eye landmarks
def mouth_aspect_ratio(mouth):
# Compute the euclidean distances between the three sets
# of vertical mouth landmarks (x, y)-coordinates
A = np.linalg.norm(mouth[13] - mouth[19])
B = np.linalg.norm(mouth[14] - mouth[18])
C = np.linalg.norm(mouth[15] - mouth[17])
# Compute the euclidean distance between the horizontal
# mouth landmarks (x, y)-coordinates
D = np.linalg.norm(mouth[12] - mouth[16])
# Compute the mouth aspect ratio
mar = (A + B + C) / (2 * D)
# Return the mouth aspect ratio
return mar
# Return direction given the nose and anchor points.
def direction(nose_point, anchor_point, w, h, multiple=1):
nx, ny = nose_point
x, y = anchor_point
if nx > x + multiple * w:
return 'right'
elif nx < x - multiple * w:
return 'left'
if ny > y + multiple * h:
return 'down'
elif ny < y - multiple * h:
return 'up'
return 'none'