-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpostureCorrector.py
More file actions
59 lines (46 loc) · 2.22 KB
/
postureCorrector.py
File metadata and controls
59 lines (46 loc) · 2.22 KB
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
import cv2
class postureCorrector():
def __init__(self, landmarks={}, scale=1.0):
self.landmarks = landmarks
self.scale = scale
def setLandmarks(self, landmarks):
self.landmarks = landmarks
def getLandmarks(self):
return self.landmarks
def setMessage(self, message):
self.message = message
def getMessage(self):
return self.message
def setScale(self, scale):
self.scale = scale
def getScale(self):
return self.scale
def checkLeanForward(self):
if "LEFT_SHOULDER" in self.landmarks and "LEFT_EAR" in self.landmarks \
and self.landmarks["LEFT_SHOULDER"].x >= (self.landmarks["LEFT_EAR"].x +
(self.scale * 150)):
return False
if "RIGHT_SHOULDER" in self.landmarks and "RIGHT_EAR" in self.landmarks \
and self.landmarks["RIGHT_SHOULDER"].x >= (self.landmarks["RIGHT_EAR"].x +
(self.scale * 160)):
return False
return True
def checkSlump(self):
if "LEFT_SHOULDER" in self.landmarks and "RIGHT_SHOULDER" in self.landmarks and \
"MOUTH_RIGHT" in self.landmarks and "MOUTH_LEFT" in self.landmarks:
ny = (self.landmarks["LEFT_SHOULDER"].y + self.landmarks["RIGHT_SHOULDER"].y) / 2
my = (self.landmarks["MOUTH_RIGHT"].y + self.landmarks["MOUTH_LEFT"].y) / 2
if ny - my >= self.scale*90:
return False
return True
# def checkHeadDrop(self):
# if "LEFT_EYE" in self.landmarks and "LEFT_EAR" in self.landmarks \
# and self.landmarks["LEFT_EYE"].y > (self.landmarks["LEFT_EAR"].y +
# (self.scale * 15)):
# return False
# if "RIGHT_EYE" in self.landmarks and "RIGHT_EAR" in self.landmarks \
# and self.landmarks["RIGHT_EYE"].y > (self.landmarks["RIGHT_EAR"].y +
# (self.scale * 15)):
# return False
def correctPosture(self):
return all([self.checkLeanForward(), self.checkSlump()])