forked from thillai-c/AI-Fitness-trainer
-
Notifications
You must be signed in to change notification settings - Fork 2
/
types_of_exercise.py
102 lines (82 loc) · 3.21 KB
/
types_of_exercise.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import numpy as np
from body_part_angle import BodyPartAngle
from utils import *
class TypeOfExercise(BodyPartAngle):
def __init__(self, landmarks):
super().__init__(landmarks)
def push_up(self, counter, status):
left_arm_angle = self.angle_of_the_left_arm()
right_arm_angle = self.angle_of_the_left_arm()
avg_arm_angle = (left_arm_angle + right_arm_angle) // 2
if status:
if avg_arm_angle < 70:
counter += 1
status = False
else:
if avg_arm_angle > 160:
status = True
return [counter, status]
def pull_up(self, counter, status):
nose = detection_body_part(self.landmarks, "NOSE")
left_elbow = detection_body_part(self.landmarks, "LEFT_ELBOW")
right_elbow = detection_body_part(self.landmarks, "RIGHT_ELBOW")
avg_shoulder_y = (left_elbow[1] + right_elbow[1]) / 2
if status:
if nose[1] > avg_shoulder_y:
counter += 1
status = False
else:
if nose[1] < avg_shoulder_y:
status = True
return [counter, status]
def squat(self, counter, status):
left_leg_angle = self.angle_of_the_right_leg()
right_leg_angle = self.angle_of_the_left_leg()
avg_leg_angle = (left_leg_angle + right_leg_angle) // 2
if status:
if avg_leg_angle < 70:
counter += 1
status = False
else:
if avg_leg_angle > 160:
status = True
return [counter, status]
def walk(self, counter, status):
right_knee = detection_body_part(self.landmarks, "RIGHT_KNEE")
left_knee = detection_body_part(self.landmarks, "LEFT_KNEE")
if status:
if left_knee[0] > right_knee[0]:
counter += 1
status = False
else:
if left_knee[0] < right_knee[0]:
counter += 1
status = True
return [counter, status]
def sit_up(self, counter, status):
angle = self.angle_of_the_abdomen()
if status:
if angle < 55:
counter += 1
status = False
else:
if angle > 105:
status = True
return [counter, status]
def calculate_exercise(self, exercise_type, counter, status):
if exercise_type == "push-up":
counter, status = TypeOfExercise(self.landmarks).push_up(
counter, status)
elif exercise_type == "pull-up":
counter, status = TypeOfExercise(self.landmarks).pull_up(
counter, status)
elif exercise_type == "squat":
counter, status = TypeOfExercise(self.landmarks).squat(
counter, status)
elif exercise_type == "walk":
counter, status = TypeOfExercise(self.landmarks).walk(
counter, status)
elif exercise_type == "sit-up":
counter, status = TypeOfExercise(self.landmarks).sit_up(
counter, status)
return [counter, status]