xmrt commited on
Commit
d7219e1
·
1 Parent(s): ae6fd57
Files changed (1) hide show
  1. main_noweb.py +74 -14
main_noweb.py CHANGED
@@ -215,7 +215,60 @@ with block:
215
  video_output2 = gr.PlayableVideo(height=512, label = "Estimate human 3d poses", show_label=True)
216
  video_output3 = gr.PlayableVideo(height=512, label = "Estimate human hand poses", show_label=True)
217
  video_output4 = gr.Video(height=512, label = "Detection and tracking", show_label=True, format="mp4")
 
218
  jsonoutput = gr.File(file_types=[".json"])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
219
 
220
 
221
  with gr.Tab("General information"):
@@ -232,23 +285,30 @@ with block:
232
 
233
  \n The 3D pose model is used for estimating the 3D coordinates of human body joints from an image or a video frame. The model uses a combination of 2D pose estimation and depth estimation to infer the 3D joint locations.
234
 
235
- \n
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
236
 
237
- \n ## Detection and tracking:
238
-
239
- \n The tracking method in the Ultralight's YOLOv8 model is used for object tracking in videos. It takes a video file or a camera stream as input and returns the tracked objects in each frame. The method uses the COCO dataset classes for object detection and tracking.
240
 
241
- \n The COCO dataset contains 80 classes of objects such as person, car, bicycle, etc. See https://docs.ultralytics.com/datasets/detect/coco/ for all available classes. The tracking method uses the COCO classes to detect and track the objects in the video frames. The tracked objects are represented as bounding boxes with labels indicating the class of the object.""")
242
  gr.Markdown("You can load the keypoints in python in the following way: ")
243
- gr.Code(
244
- value="""def hello_world():
245
- return "Hello, world!"
246
-
247
- print(hello_world())""",
248
- language="python",
249
- interactive=False,
250
- show_label=False,
251
- )
252
 
253
 
254
  # From file
 
215
  video_output2 = gr.PlayableVideo(height=512, label = "Estimate human 3d poses", show_label=True)
216
  video_output3 = gr.PlayableVideo(height=512, label = "Estimate human hand poses", show_label=True)
217
  video_output4 = gr.Video(height=512, label = "Detection and tracking", show_label=True, format="mp4")
218
+ gr.Markdown("Download the .json file that contains the keypoint positions for each frame in the video.")
219
  jsonoutput = gr.File(file_types=[".json"])
220
+ gr.Markdown("""There are multiple ways to interact with these keypoints.
221
+ \n The example below shows how you can calulate the angle on the elbow for example.
222
+ \n Copy the code into your own preferred interpreter and experiment with the keypoint file.
223
+ \n If you choose to run the code, start by installing the packages json and numpy. The complete overview of the keypoint indices can be seen in the tab 'General information'. """)
224
+ gr.Code(
225
+ value="""
226
+ # Importing packages needed
227
+ import json
228
+ import numpy as np
229
+
230
+ kpointlist=[]
231
+
232
+ # First we load the data
233
+ with open(file_path, 'r') as json_file:
234
+ data = json.load(json_file)
235
+
236
+ # The we define a function for calculating angles
237
+ def calculate_angle(a, b, c):
238
+ a = np.array(a) # First point
239
+ b = np.array(b) # Middle point
240
+ c = np.array(c) # End point
241
+
242
+ radians = np.arctan2(c[1]-b[1], c[0]-b[0]) - np.arctan2(a[1]-b[1], a[0]-b[0])
243
+ angle = np.abs(radians*180.0/np.pi)
244
+
245
+ if angle >180.0:
246
+ angle = 360-angle
247
+
248
+ return angle
249
+
250
+ # We select the first identified person in the first frame (zero index) as an example
251
+ # To calculate the angle of the right elbow we take the point before and after and according to the indices that will be 6 (right shoulder) and 9 (right wrist)
252
+ predictions = data['predictions'][0] # Assuming batch_size is 1
253
+
254
+ # COCO keypoint indices
255
+ shoulder_index = 6
256
+ elbow_index = 8
257
+ wrist_index = 9
258
+
259
+ shoulder_point = data[0]['instances'][0]['keypoints'][shoulder_index]
260
+ elbow_point = data[0]['instances'][0]['keypoints'][elbow_index]
261
+ wrist_point = data[0]['instances'][0]['keypoints'][wrist_index]
262
+
263
+ angle = calculate_angle(shoulder_point, elbow_point, wrist_point)
264
+ print("Angle is: ", angle)
265
+
266
+ """,
267
+ language="python",
268
+ interactive=False,
269
+ show_label=False,
270
+ )
271
+
272
 
273
 
274
  with gr.Tab("General information"):
 
285
 
286
  \n The 3D pose model is used for estimating the 3D coordinates of human body joints from an image or a video frame. The model uses a combination of 2D pose estimation and depth estimation to infer the 3D joint locations.
287
 
288
+ \n The keypoints in the 2D pose model has the following order:
289
+
290
+ \n ``` 0: Nose
291
+ 1: Left Eye
292
+ 2: Right Eye
293
+ 3: Left Ear
294
+ 4: Right Ear
295
+ 5: Left Shoulder
296
+ 6: Right Shoulder
297
+ 7: Left Elbow
298
+ 8: Right Elbow
299
+ 9: Left Wrist
300
+ 10: Right Wrist
301
+ 11: Left Hip
302
+ 12: Right Hip
303
+ 13: Left Knee
304
+ 14: Right Knee
305
+ 15: Left Ankle
306
+ 16: Right Ankle ```
307
 
 
 
 
308
 
309
+ """)
310
  gr.Markdown("You can load the keypoints in python in the following way: ")
311
+
 
 
 
 
 
 
 
 
312
 
313
 
314
  # From file