Piarasingh85 commited on
Commit
a53f6f6
·
verified ·
1 Parent(s): 8ef424c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -25
app.py CHANGED
@@ -60,7 +60,6 @@ def classifyPose(landmarks, output_image, display=False):
60
  Returns:
61
  output_image: The image with the detected pose landmarks drawn and pose label written.
62
  label: The classified pose label of the person in the output_image.
63
-
64
  '''
65
 
66
  # Initialize the label of the pose. It is not known at this stage.
@@ -103,67 +102,61 @@ def classifyPose(landmarks, output_image, display=False):
103
  landmarks[mp_pose.PoseLandmark.RIGHT_ANKLE.value])
104
 
105
  #----------------------------------------------------------------------------------------------------------------
106
- # Check for Five-Pointed Star Pose
 
107
  if abs(landmarks[mp_pose.PoseLandmark.LEFT_WRIST.value].y - landmarks[mp_pose.PoseLandmark.LEFT_HIP.value].y) < 100 and \
108
  abs(landmarks[mp_pose.PoseLandmark.RIGHT_WRIST.value].y - landmarks[mp_pose.PoseLandmark.RIGHT_HIP.value].y) < 100 and \
109
  abs(landmarks[mp_pose.PoseLandmark.LEFT_ANKLE.value].x - landmarks[mp_pose.PoseLandmark.RIGHT_ANKLE.value].x) > 200 and \
110
  abs(landmarks[mp_pose.PoseLandmark.LEFT_WRIST.value].x - landmarks[mp_pose.PoseLandmark.RIGHT_WRIST.value].x) > 200:
111
  label = "Five-Pointed Star Pose"
112
-
 
 
 
 
 
 
 
113
  # Check if it is the warrior II pose or the T pose.
114
- if left_elbow_angle > 165 and left_elbow_angle < 195 and right_elbow_angle > 165 and right_elbow_angle < 195:
115
  if left_shoulder_angle > 80 and left_shoulder_angle < 110 and right_shoulder_angle > 80 and right_shoulder_angle < 110:
116
- if left_knee_angle > 165 and left_knee_angle < 195 or right_knee_angle > 165 and right_knee_angle < 195:
117
- if left_knee_angle > 90 and left_knee_angle < 120 or right_knee_angle > 90 and right_knee_angle < 120:
118
- label = 'Warrior II Pose'
119
- if left_knee_angle > 160 and left_knee_angle < 195 and right_knee_angle > 160 and right_knee_angle < 195:
120
  label = 'T Pose'
121
 
122
  # Check if it is the tree pose.
123
- if left_knee_angle > 165 and left_knee_angle < 195 or right_knee_angle > 165 and right_knee_angle < 195:
124
  if left_knee_angle > 315 and left_knee_angle < 335 or right_knee_angle > 25 and right_knee_angle < 45:
125
  label = 'Tree Pose'
126
 
127
  # Check for Upward Salute Pose
128
- if abs(landmarks[mp_pose.PoseLandmark.LEFT_WRIST.value].x - landmarks[mp_pose.PoseLandmark.LEFT_HIP.value].x) < 100 and \
129
  abs(landmarks[mp_pose.PoseLandmark.RIGHT_WRIST.value].x - landmarks[mp_pose.PoseLandmark.RIGHT_HIP.value].x) < 100 and \
130
  landmarks[mp_pose.PoseLandmark.LEFT_WRIST.value].y < landmarks[mp_pose.PoseLandmark.LEFT_SHOULDER.value].y and \
131
  landmarks[mp_pose.PoseLandmark.RIGHT_WRIST.value].y < landmarks[mp_pose.PoseLandmark.RIGHT_SHOULDER.value].y and \
132
  abs(landmarks[mp_pose.PoseLandmark.LEFT_SHOULDER.value].y - landmarks[mp_pose.PoseLandmark.RIGHT_SHOULDER.value].y) < 50:
133
  label = "Upward Salute Pose"
134
-
135
- # Check for Hands Under Feet Pose
136
- if landmarks[mp_pose.PoseLandmark.LEFT_WRIST.value].y > landmarks[mp_pose.PoseLandmark.LEFT_KNEE.value].y and \
137
- landmarks[mp_pose.PoseLandmark.RIGHT_WRIST.value].y > landmarks[mp_pose.PoseLandmark.RIGHT_KNEE.value].y and \
138
- abs(landmarks[mp_pose.PoseLandmark.LEFT_WRIST.value].x - landmarks[mp_pose.PoseLandmark.LEFT_ANKLE.value].x) < 50 and \
139
- abs(landmarks[mp_pose.PoseLandmark.RIGHT_WRIST.value].x - landmarks[mp_pose.PoseLandmark.RIGHT_ANKLE.value].x) < 50:
140
- label = "Hands Under Feet Pose"
141
-
142
 
143
  #----------------------------------------------------------------------------------------------------------------
144
 
145
  # Check if the pose is classified successfully
146
  if label != 'Unknown Pose':
147
-
148
  # Update the color (to green) with which the label will be written on the image.
149
  color = (0, 255, 0)
150
 
151
  # Write the label on the output image.
152
- cv2.putText(output_image, label, (220, 30),cv2.FONT_HERSHEY_PLAIN, 2, color, 2)
153
 
154
  # Check if the resultant image is specified to be displayed.
155
  if display:
156
-
157
  # Display the resultant image.
158
  plt.figure(figsize=[10,10])
159
- plt.imshow(output_image[:,:,::-1]);plt.title("Output Image");plt.axis('off');
160
-
161
  else:
162
-
163
  # Return the output image and the classified label.
164
  return output_image, label
165
 
166
-
167
  def run(
168
  image: np.ndarray,
169
  model_complexity: int,
 
60
  Returns:
61
  output_image: The image with the detected pose landmarks drawn and pose label written.
62
  label: The classified pose label of the person in the output_image.
 
63
  '''
64
 
65
  # Initialize the label of the pose. It is not known at this stage.
 
102
  landmarks[mp_pose.PoseLandmark.RIGHT_ANKLE.value])
103
 
104
  #----------------------------------------------------------------------------------------------------------------
105
+ # Check for more specific poses first
106
+ # Check for Five-Pointed Star Pose
107
  if abs(landmarks[mp_pose.PoseLandmark.LEFT_WRIST.value].y - landmarks[mp_pose.PoseLandmark.LEFT_HIP.value].y) < 100 and \
108
  abs(landmarks[mp_pose.PoseLandmark.RIGHT_WRIST.value].y - landmarks[mp_pose.PoseLandmark.RIGHT_HIP.value].y) < 100 and \
109
  abs(landmarks[mp_pose.PoseLandmark.LEFT_ANKLE.value].x - landmarks[mp_pose.PoseLandmark.RIGHT_ANKLE.value].x) > 200 and \
110
  abs(landmarks[mp_pose.PoseLandmark.LEFT_WRIST.value].x - landmarks[mp_pose.PoseLandmark.RIGHT_WRIST.value].x) > 200:
111
  label = "Five-Pointed Star Pose"
112
+
113
+ # Check for Hands Under Feet Pose
114
+ elif landmarks[mp_pose.PoseLandmark.LEFT_WRIST.value].y > landmarks[mp_pose.PoseLandmark.LEFT_KNEE.value].y and \
115
+ landmarks[mp_pose.PoseLandmark.RIGHT_WRIST.value].y > landmarks[mp_pose.PoseLandmark.RIGHT_KNEE.value].y and \
116
+ abs(landmarks[mp_pose.PoseLandmark.LEFT_WRIST.value].x - landmarks[mp_pose.PoseLandmark.LEFT_ANKLE.value].x) < 50 and \
117
+ abs(landmarks[mp_pose.PoseLandmark.RIGHT_WRIST.value].x - landmarks[mp_pose.PoseLandmark.RIGHT_ANKLE.value].x) < 50:
118
+ label = "Hands Under Feet Pose"
119
+
120
  # Check if it is the warrior II pose or the T pose.
121
+ elif left_elbow_angle > 165 and left_elbow_angle < 195 and right_elbow_angle > 165 and right_elbow_angle < 195:
122
  if left_shoulder_angle > 80 and left_shoulder_angle < 110 and right_shoulder_angle > 80 and right_shoulder_angle < 110:
123
+ if left_knee_angle > 90 and left_knee_angle < 120 or right_knee_angle > 90 and right_knee_angle < 120:
124
+ label = 'Warrior II Pose'
125
+ elif left_knee_angle > 160 and left_knee_angle < 195 and right_knee_angle > 160 and right_knee_angle < 195:
 
126
  label = 'T Pose'
127
 
128
  # Check if it is the tree pose.
129
+ elif left_knee_angle > 165 and left_knee_angle < 195 or right_knee_angle > 165 and right_knee_angle < 195:
130
  if left_knee_angle > 315 and left_knee_angle < 335 or right_knee_angle > 25 and right_knee_angle < 45:
131
  label = 'Tree Pose'
132
 
133
  # Check for Upward Salute Pose
134
+ elif abs(landmarks[mp_pose.PoseLandmark.LEFT_WRIST.value].x - landmarks[mp_pose.PoseLandmark.LEFT_HIP.value].x) < 100 and \
135
  abs(landmarks[mp_pose.PoseLandmark.RIGHT_WRIST.value].x - landmarks[mp_pose.PoseLandmark.RIGHT_HIP.value].x) < 100 and \
136
  landmarks[mp_pose.PoseLandmark.LEFT_WRIST.value].y < landmarks[mp_pose.PoseLandmark.LEFT_SHOULDER.value].y and \
137
  landmarks[mp_pose.PoseLandmark.RIGHT_WRIST.value].y < landmarks[mp_pose.PoseLandmark.RIGHT_SHOULDER.value].y and \
138
  abs(landmarks[mp_pose.PoseLandmark.LEFT_SHOULDER.value].y - landmarks[mp_pose.PoseLandmark.RIGHT_SHOULDER.value].y) < 50:
139
  label = "Upward Salute Pose"
 
 
 
 
 
 
 
 
140
 
141
  #----------------------------------------------------------------------------------------------------------------
142
 
143
  # Check if the pose is classified successfully
144
  if label != 'Unknown Pose':
 
145
  # Update the color (to green) with which the label will be written on the image.
146
  color = (0, 255, 0)
147
 
148
  # Write the label on the output image.
149
+ cv2.putText(output_image, label, (220, 30), cv2.FONT_HERSHEY_PLAIN, 2, color, 2)
150
 
151
  # Check if the resultant image is specified to be displayed.
152
  if display:
 
153
  # Display the resultant image.
154
  plt.figure(figsize=[10,10])
155
+ plt.imshow(output_image[:,:,::-1]); plt.title("Output Image"); plt.axis('off')
 
156
  else:
 
157
  # Return the output image and the classified label.
158
  return output_image, label
159
 
 
160
  def run(
161
  image: np.ndarray,
162
  model_complexity: int,