Piarasingh85 commited on
Commit
12df91d
·
verified ·
1 Parent(s): 96302ed

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -5
app.py CHANGED
@@ -10,12 +10,59 @@ mp_drawing = mp.solutions.drawing_utils
10
 
11
  # Define a function to classify yoga poses
12
  def classify_pose(landmarks):
13
- # Example logic for classifying poses
14
- if landmarks[mp_pose.PoseLandmark.LEFT_SHOULDER.value].visibility > 0.5 and \
15
- landmarks[mp_pose.PoseLandmark.RIGHT_SHOULDER.value].visibility > 0.5:
16
- return "T-Pose"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  # Add more classification rules here
18
- return "Unknown Pose"
19
 
20
  def detect_and_classify_pose(input_image):
21
  frame = cv2.cvtColor(input_image, cv2.COLOR_BGR2RGB)
 
10
 
11
  # Define a function to classify yoga poses
12
  def classify_pose(landmarks):
13
+ # Check if the both arms are straight.
14
+ if left_elbow_angle > 165 and left_elbow_angle < 195 and right_elbow_angle > 165 and right_elbow_angle < 195:
15
+
16
+ # Check if shoulders are at the required angle.
17
+ if left_shoulder_angle > 80 and left_shoulder_angle < 110 and right_shoulder_angle > 80 and right_shoulder_angle < 110:
18
+
19
+ # Check if it is the warrior II pose.
20
+ #----------------------------------------------------------------------------------------------------------------
21
+
22
+ # Check if one leg is straight.
23
+ if left_knee_angle > 165 and left_knee_angle < 195 or right_knee_angle > 165 and right_knee_angle < 195:
24
+
25
+ # Check if the other leg is bended at the required angle.
26
+ if left_knee_angle > 90 and left_knee_angle < 120 or right_knee_angle > 90 and right_knee_angle < 120:
27
+
28
+ # Specify the label of the pose that is Warrior II pose.
29
+ label = 'Warrior II Pose'
30
+
31
+ #----------------------------------------------------------------------------------------------------------------
32
+
33
+ # Check if it is the T pose.
34
+ #----------------------------------------------------------------------------------------------------------------
35
+
36
+ # Check if both legs are straight
37
+ if left_knee_angle > 160 and left_knee_angle < 195 and right_knee_angle > 160 and right_knee_angle < 195:
38
+
39
+ # Specify the label of the pose that is tree pose.
40
+ label = 'T Pose'
41
+
42
+ #----------------------------------------------------------------------------------------------------------------
43
+
44
+ # Check if it is the tree pose.
45
+ #----------------------------------------------------------------------------------------------------------------
46
+
47
+ # Check if one leg is straight
48
+ if left_knee_angle > 165 and left_knee_angle < 195 or right_knee_angle > 165 and right_knee_angle < 195:
49
+
50
+ # Check if the other leg is bended at the required angle.
51
+ if left_knee_angle > 315 and left_knee_angle < 335 or right_knee_angle > 25 and right_knee_angle < 45:
52
+
53
+ # Specify the label of the pose that is tree pose.
54
+ label = 'Tree Pose'
55
+
56
+ # Check for Upward Salute Pose
57
+ if abs(landmarks[mp_pose.PoseLandmark.LEFT_WRIST.value][0] - landmarks[mp_pose.PoseLandmark.LEFT_HIP.value][0]) < 100 and \
58
+ abs(landmarks[mp_pose.PoseLandmark.RIGHT_WRIST.value][0] - landmarks[mp_pose.PoseLandmark.RIGHT_HIP.value][0]) < 100 and \
59
+ landmarks[mp_pose.PoseLandmark.LEFT_WRIST.value][1] < landmarks[mp_pose.PoseLandmark.LEFT_SHOULDER.value][1] and \
60
+ landmarks[mp_pose.PoseLandmark.RIGHT_WRIST.value][1] < landmarks[mp_pose.PoseLandmark.RIGHT_SHOULDER.value][1] and \
61
+ abs(landmarks[mp_pose.PoseLandmark.LEFT_SHOULDER.value][1] - landmarks[mp_pose.PoseLandmark.RIGHT_SHOULDER.value][1]) < 50:
62
+ label = "Upward Salute Pose"
63
+
64
  # Add more classification rules here
65
+ return "Unknown Pose"
66
 
67
  def detect_and_classify_pose(input_image):
68
  frame = cv2.cvtColor(input_image, cv2.COLOR_BGR2RGB)