BSuruchi commited on
Commit
7467b09
·
verified ·
1 Parent(s): 4bbe5b0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +76 -2
app.py CHANGED
@@ -1,3 +1,6 @@
 
 
 
1
  # Install mediapipe
2
  !pip install mediapipe
3
 
@@ -8,7 +11,7 @@ import numpy as np
8
  from time import time
9
  import mediapipe as mp
10
  import matplotlib.pyplot as plt
11
-
12
 
13
  #*******************Initialize the Pose Detection Model*****************
14
 
@@ -131,6 +134,68 @@ mp_drawing = mp.solutions.drawing_utils
131
  #cv2.destroyAllWindows()
132
 
133
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
134
  # ********************Pose Classification with Angle Heuristics*****************
135
 
136
  def calculateAngle(landmark1, landmark2, landmark3):
@@ -372,4 +437,13 @@ while camera_video.isOpened():
372
  # Release the VideoCapture object and close the windows.
373
  camera_video.release()
374
  cv2.destroyAllWindows()
375
-
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
  # Install mediapipe
5
  !pip install mediapipe
6
 
 
11
  from time import time
12
  import mediapipe as mp
13
  import matplotlib.pyplot as plt
14
+ from openpose import pyopenpose as op
15
 
16
  #*******************Initialize the Pose Detection Model*****************
17
 
 
134
  #cv2.destroyAllWindows()
135
 
136
 
137
+ #************************Create a Pose Detection Function*******************
138
+ def detectPose(image, pose, display=True):
139
+ '''
140
+ This function performs pose detection on an image.
141
+ Args:
142
+ image: The input image with a prominent person whose pose landmarks needs to be detected.
143
+ pose: The pose setup function required to perform the pose detection.
144
+ display: A boolean value that is if set to true the function displays the original input image, the resultant image,
145
+ and the pose landmarks in 3D plot and returns nothing.
146
+ Returns:
147
+ output_image: The input image with the detected pose landmarks drawn.
148
+ landmarks: A list of detected landmarks converted into their original scale.
149
+ '''
150
+
151
+ # Create a copy of the input image.
152
+ output_image = image.copy()
153
+
154
+ # Convert the image from BGR into RGB format.
155
+ imageRGB = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
156
+
157
+ # Perform the Pose Detection.
158
+ results = pose.process(imageRGB)
159
+
160
+ # Retrieve the height and width of the input image.
161
+ height, width, _ = image.shape
162
+
163
+ # Initialize a list to store the detected landmarks.
164
+ landmarks = []
165
+
166
+ # Check if any landmarks are detected.
167
+ if results.pose_landmarks:
168
+
169
+ # Draw Pose landmarks on the output image.
170
+ mp_drawing.draw_landmarks(image=output_image, landmark_list=results.pose_landmarks,
171
+ connections=mp_pose.POSE_CONNECTIONS)
172
+
173
+ # Iterate over the detected landmarks.
174
+ for landmark in results.pose_landmarks.landmark:
175
+
176
+ # Append the landmark into the list.
177
+ landmarks.append((int(landmark.x * width), int(landmark.y * height),
178
+ (landmark.z * width)))
179
+
180
+ # Check if the original input image and the resultant image are specified to be displayed.
181
+ if display:
182
+
183
+ # Display the original input image and the resultant image.
184
+ plt.figure(figsize=[22,22])
185
+ plt.subplot(121);plt.imshow(image[:,:,::-1]);plt.title("Original Image");plt.axis('off');
186
+ plt.subplot(122);plt.imshow(output_image[:,:,::-1]);plt.title("Output Image");plt.axis('off');
187
+
188
+ # Also Plot the Pose landmarks in 3D.
189
+ mp_drawing.plot_landmarks(results.pose_world_landmarks, mp_pose.POSE_CONNECTIONS)
190
+
191
+ # Otherwise
192
+ else:
193
+
194
+ # Return the output image and the found landmarks.
195
+ return output_image, landmarks
196
+
197
+
198
+
199
  # ********************Pose Classification with Angle Heuristics*****************
200
 
201
  def calculateAngle(landmark1, landmark2, landmark3):
 
437
  # Release the VideoCapture object and close the windows.
438
  camera_video.release()
439
  cv2.destroyAllWindows()
440
+
441
+
442
+ # Create a Gradio interface
443
+ iface = gr.Interface(
444
+ fn=detect_yoga_poses,
445
+ inputs=None,
446
+ outputs=None,
447
+ title="Live Yoga Pose Detection",
448
+ description="This app detects yoga poses from the live camera feed using MediaPipe.",
449
+ )