xmrt commited on
Commit
b18c135
1 Parent(s): d7219e1
Files changed (1) hide show
  1. main_noweb.py +75 -73
main_noweb.py CHANGED
@@ -112,30 +112,33 @@ def show_tracking(video_content):
112
  return out_file
113
 
114
 
115
- def pose3d(video):
116
  video = check_extension(video)
117
  print(device)
118
  temp_3d = human3d
119
 
120
-
121
  # Define new unique folder
122
  add_dir = str(uuid.uuid4())
123
  vis_out_dir = os.path.join("/".join(video.split("/")[:-1]), add_dir)
124
- os.makedirs(vis_out_dir)
125
 
 
 
126
  result_generator = temp_3d(video,
127
- vis_out_dir = vis_out_dir,
128
- thickness=4,
129
- radius = 5,
130
- return_vis=True,
131
- kpt_thr=0.3,
132
- rebase_keypoint_height=True,
133
- device=device)
 
 
134
 
135
  result = [result for result in result_generator] #next(result_generator)
136
 
137
- out_file = glob.glob(os.path.join(vis_out_dir, "*.mp4")) #+ glob.glob(os.path.join(vis_out_dir, "*.webm"))
138
-
 
139
  # Reinitialize
140
  return "".join(out_file)
141
 
@@ -223,47 +226,47 @@ with block:
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,
@@ -287,27 +290,26 @@ with block:
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
 
@@ -318,7 +320,7 @@ with block:
318
  queue=True)
319
 
320
  submit_pose3d_file.click(fn=pose3d,
321
- inputs= video_input,
322
  outputs = video_output2,
323
  queue=True)
324
 
 
112
  return out_file
113
 
114
 
115
+ def pose3d(video, kpt_threshold):
116
  video = check_extension(video)
117
  print(device)
118
  temp_3d = human3d
119
 
 
120
  # Define new unique folder
121
  add_dir = str(uuid.uuid4())
122
  vis_out_dir = os.path.join("/".join(video.split("/")[:-1]), add_dir)
 
123
 
124
+ os.makedirs(add_dir)
125
+ print(check_fps(video))
126
  result_generator = temp_3d(video,
127
+ vis_out_dir = add_dir,
128
+ #return_vis=True,
129
+ radius = 5,
130
+ thickness=4,
131
+ rebase_keypoint_height=True,
132
+ kpt_thr=kpt_threshold,
133
+ device=device,
134
+ pred_out_dir = add_dir
135
+ )
136
 
137
  result = [result for result in result_generator] #next(result_generator)
138
 
139
+ out_file = glob.glob(os.path.join(add_dir, "*.mp4")) #+ glob.glob(os.path.join(vis_out_dir, "*.webm"))
140
+ kpoints = glob.glob(os.path.join(add_dir, "*.json"))
141
+ print(kpoints)
142
  # Reinitialize
143
  return "".join(out_file)
144
 
 
226
  \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'. """)
227
  gr.Code(
228
  value="""
229
+ # Importing packages needed
230
+ import json
231
+ import numpy as np
232
+
233
+ kpointlist=[]
234
+
235
+ # First we load the data
236
+ with open(file_path, 'r') as json_file:
237
+ data = json.load(json_file)
238
+
239
+ # The we define a function for calculating angles
240
+ def calculate_angle(a, b, c):
241
+ a = np.array(a) # First point
242
+ b = np.array(b) # Middle point
243
+ c = np.array(c) # End point
244
+
245
+ radians = np.arctan2(c[1]-b[1], c[0]-b[0]) - np.arctan2(a[1]-b[1], a[0]-b[0])
246
+ angle = np.abs(radians*180.0/np.pi)
247
+
248
+ if angle >180.0:
249
+ angle = 360-angle
250
 
251
+ return angle
252
+
253
+ # We select the first identified person in the first frame (zero index) as an example
254
+ # 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)
255
+ predictions = data['predictions'][0] # Assuming batch_size is 1
256
+
257
+ # COCO keypoint indices
258
+ shoulder_index = 6
259
+ elbow_index = 8
260
+ wrist_index = 9
261
+
262
+ shoulder_point = data[0]['instances'][0]['keypoints'][shoulder_index]
263
+ elbow_point = data[0]['instances'][0]['keypoints'][elbow_index]
264
+ wrist_point = data[0]['instances'][0]['keypoints'][wrist_index]
265
+
266
+ angle = calculate_angle(shoulder_point, elbow_point, wrist_point)
267
+ print("Angle is: ", angle)
268
+
269
+ """,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
270
  language="python",
271
  interactive=False,
272
  show_label=False,
 
290
 
291
  \n The keypoints in the 2D pose model has the following order:
292
 
293
+ \n ```
294
+ 0: Nose
295
+ 1: Left Eye
296
+ 2: Right Eye
297
+ 3: Left Ear
298
+ 4: Right Ear
299
+ 5: Left Shoulder
300
+ 6: Right Shoulder
301
+ 7: Left Elbow
302
+ 8: Right Elbow
303
+ 9: Left Wrist
304
+ 10: Right Wrist
305
+ 11: Left Hip
306
+ 12: Right Hip
307
+ 13: Left Knee
308
+ 14: Right Knee
309
+ 15: Left Ankle
310
+ 16: Right Ankle
311
+ ```
312
  """)
 
313
 
314
 
315
 
 
320
  queue=True)
321
 
322
  submit_pose3d_file.click(fn=pose3d,
323
+ inputs= [video_input, file_kpthr],
324
  outputs = video_output2,
325
  queue=True)
326