Skip to content

Commit f195be5

Browse files
authored
Supported marker augmentation and inverse kinematics + others #22
- Depth values in trc files adjusted based on neutral position for the sagittal plane (left and right side) and frontal plane (front and back side) - Supported marker augmentation and inverse kinematics via Pose2Sim - c3d export - renamed a bunch of parameters - fixed whole_body_wrist model - Fixed "load_trc" option - Updated doc
2 parents 3a0e67c + 86c5e55 commit f195be5

File tree

10 files changed

+252
-143
lines changed

10 files changed

+252
-143
lines changed

Content/sports2d_blender.gif

438 KB
Loading

Content/sports2d_opensim.gif

368 KB
Loading

README.md

Lines changed: 45 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,13 @@
2222

2323
> **`Announcement:`\
2424
> Complete rewriting of the code!** Run `pip install sports2d -U` to get the latest version.
25+
> - MarkerAugmentation and Inverse Kinematics for accurate 3D motion with OpenSim. **New in v0.7!**
26+
> - Any detector and pose estimation model can be used. **New in v0.6!**
27+
> - Results in meters rather than pixels. **New in v0.5!**
2528
> - Faster, more accurate
2629
> - Works from a webcam
27-
> - Results in meters rather than pixels. **New in v0.5!**
2830
> - Better visualization output
2931
> - More flexible, easier to run
30-
> - Batch process multiple videos at once
31-
>
32-
> Note: Colab version broken for now. I'll fix it in the next few weeks.
3332
3433
***N.B.:*** As always, I am more than happy to welcome contributions (see [How to contribute](#how-to-contribute-and-to-do-list))!
3534
<!--User-friendly Colab version released! (and latest issues fixed, too)\
@@ -178,10 +177,7 @@ The Demo video is voluntarily challenging to demonstrate the robustness of the p
178177

179178
The OpenSim skeleton is not rigged yet. **[Feel free to contribute!](https://github.com/perfanalytics/pose2sim/issues/40)**
180179

181-
<!-- IMAGE ICI
182-
-->
183-
184-
180+
<img src="Content/sports2d_blender.gif" width="760">
185181

186182
<br>
187183

@@ -196,10 +192,9 @@ The Demo video is voluntarily challenging to demonstrate the robustness of the p
196192
- **File -> Open Model:** Open your scaled model (e.g., `Model_Pose2Sim_LSTM.osim`).
197193
- **File -> Load Motion:** Open your motion file (e.g., `angles.mot`).
198194

199-
<br>
195+
<img src="Content/sports2d_opensim.gif" width="760">
200196

201-
<!-- IMAGE ICI
202-
-->
197+
<br>
203198

204199

205200

@@ -231,21 +226,26 @@ sports2d --time_range 1.2 2.7
231226

232227

233228
#### Get coordinates in meters:
229+
> **N.B.:** Depth is estimated from a neutral pose.
234230
235231
<!-- You either need to provide a calibration file, or simply the height of a person (Note that the latter will not take distortions into account, and that it will be less accurate for motion in the frontal plane).\-->
236232
You may need to convert pixel coordinates to meters.\
237-
Just provide the height of the reference person (and their ID in case of multiple person detection).\
238-
The floor angle and the origin of the xy axis are computed automatically from gait. If you analyze another type of motion, you can manually specify them.\
239-
Note that it does not take distortions into account, and that it will be less accurate for motions in the frontal plane.
233+
Just provide the height of the reference person (and their ID in case of multiple person detection).
240234

241-
``` cmd
235+
You can also specify whether the visible side of the person is left, right, front, or back. Set it to 'auto' if you do not want to find it automatically (only works for motion in the sagittal plane), or to 'none' if you want to keep 2D instead of 3D coordinates (if the person goes right, and then left for example).
236+
237+
The floor angle and the origin of the xy axis are computed automatically from gait. If you analyze another type of motion, you can manually specify them. Note that `y` points down.\
238+
Also note that distortions are not taken into account, and that results will be less accurate for motions in the frontal plane.
239+
240+
<!-- ``` cmd
242241
sports2d --to_meters True --calib_file calib_demo.toml
243-
```
242+
``` -->
244243
``` cmd
245244
sports2d --to_meters True --px_to_m_person_height 1.65 --px_to_m_from_person_id 2
246245
```
247246
``` cmd
248-
sports2d --to_meters True --px_to_m_person_height 1.65 --px_to_m_from_person_id 2 --floor_angle 0 --xy_origin 0 940
247+
sports2d --to_meters True --px_to_m_person_height 1.65 --px_to_m_from_person_id 2 `
248+
--visible_side front none auto --floor_angle 0 --xy_origin 0 940
249249
```
250250

251251
<br>
@@ -254,24 +254,28 @@ sports2d --to_meters True --px_to_m_person_height 1.65 --px_to_m_from_person_id
254254
#### Run inverse kinematics:
255255
> N.B.: [Full install](#full-install) required.
256256
257-
> N.B.: The person needs to be moving on a single plane for the whole selected time range.
258-
259-
Analyzed persons can be showing their left, right, front, or back side. If you want to ignore a certain person, set `--visible_side none`.
260-
261-
262-
263-
264-
Why IK?
265-
Add section in how it works
257+
> **N.B.:** The person needs to be moving on a single plane for the whole selected time range.
266258
259+
OpenSim inverse kinematics allows you to set joint constraints, joint angle limits, to constrain the bones to keep the same length all along the motion and potentially to have equal sizes on left and right side. Most generally, it gives more biomechanically accurate results. It can also give you the opportunity to compute joint torques, muscle forces, ground reaction forces, and more, [with MoCo](https://opensim-org.github.io/opensim-moco-site/) for example.
267260

261+
This is done via [Pose2Sim](https://github.com/perfanalytics/pose2sim).\
262+
Model scaling is done according to the mean of the segment lengths, across a subset of frames. We remove the 10% fastest frames (potential outliers), the frames where the speed is 0 (person probably out of frame), the frames where the average knee and hip flexion angles are above 45° (pose estimation is not precise when the person is crouching) and the 20% most extreme segment values after the previous operations (potential outliers). All these parameters can be edited in your Config.toml file.
268263

269264
```cmd
270-
sports2d --time_range 1.2 2.7 --do_ik true --visible_side front left
265+
sports2d --time_range 1.2 2.7 `
266+
--do_ik true `
267+
--px_to_m_from_person_id 1 --px_to_m_person_height 1.65 `
268+
--visible_side front auto
271269
```
272270

271+
You can optionally use the LSTM marker augmentation to improve the quality of the output motion.\
272+
You can also optionally give the participants proper masses. Mass has no influence on motion, only on forces (if you decide to further pursue kinetics analysis).
273+
273274
```cmd
274-
sports2d --time_range 1.2 2.7 --do_ik true --visible_side front left --use_augmentation True
275+
sports2d --time_range 1.2 2.7 `
276+
--do_ik true --use_augmentation True `
277+
--px_to_m_from_person_id 1 --px_to_m_person_height 1.65 `
278+
--visible_side front left --participant_mass 67.0 55.0
275279
```
276280

277281
<br>
@@ -337,7 +341,9 @@ sports2d --video_input demo.mp4 other_video.mp4 --time_range 1.2 2.7 0 3.5
337341
```
338342
- Choose whether you want video, images, trc pose file, angle mot file, real-time display, and plots:
339343
```cmd
340-
sports2d --save_vid false --save_img true --save_pose false --save_angles true --show_realtime_results false --show_graphs false
344+
sports2d --save_vid false --save_img true `
345+
--save_pose false --save_angles true `
346+
--show_realtime_results false --show_graphs false
341347
```
342348
- Save results to a custom directory, specify the slow-motion factor:
343349
``` cmd
@@ -354,12 +360,12 @@ sports2d --video_input demo.mp4 other_video.mp4 --time_range 1.2 2.7 0 3.5
354360
```
355361
- Use any custom (deployed) MMPose model
356362
``` cmd
357-
sports2d --pose_model BodyWithFeet :
358-
--mode """{'det_class':'YOLOX',
359-
'det_model':'https://download.openmmlab.com/mmpose/v1/projects/rtmposev1/onnx_sdk/yolox_m_8xb8-300e_humanart-c2c7a14a.zip',
360-
'det_input_size':[640, 640],
361-
'pose_class':'RTMPose',
362-
'pose_model':'https://download.openmmlab.com/mmpose/v1/projects/rtmposev1/onnx_sdk/rtmpose-m_simcc-body7_pt-body7-halpe26_700e-256x192-4d3e73dd_20230605.zip',
363+
sports2d --pose_model BodyWithFeet : `
364+
--mode """{'det_class':'YOLOX', `
365+
'det_model':'https://download.openmmlab.com/mmpose/v1/projects/rtmposev1/onnx_sdk/yolox_m_8xb8-300e_humanart-c2c7a14a.zip', `
366+
'det_input_size':[640, 640], `
367+
'pose_class':'RTMPose', `
368+
'pose_model':'https://download.openmmlab.com/mmpose/v1/projects/rtmposev1/onnx_sdk/rtmpose-m_simcc-body7_pt-body7-halpe26_700e-256x192-4d3e73dd_20230605.zip', `
363369
'pose_input_size':[192,256]}"""
364370
```
365371

@@ -376,9 +382,10 @@ sports2d --help
376382

377383
```
378384
'config': ["C", "path to a toml configuration file"],
385+
379386
'video_input': ["i", "webcam, or video_path.mp4, or video1_path.avi video2_path.mp4 ... Beware that images won't be saved if paths contain non ASCII characters"],
380387
'px_to_m_person_height': ["H", "height of the person in meters. 1.70 if not specified"],
381-
'visible_side': ["", "front, back, left, right, auto, or none. 'front auto' if not specified. If 'auto', will be either left or right depending on the direction of the motion. If 'none', no IK for this person"],
388+
'visible_side': ["", "front, back, left, right, auto, or none. 'front none auto' if not specified. If 'auto', will be either left or right depending on the direction of the motion. If 'none', no IK for this person"],
382389
'load_trc_px': ["", "load trc file to avaid running pose estimation again. false if not specified"],
383390
'compare': ["", "visually compare motion with trc file. false if not specified"],
384391
'webcam_id': ["w", "webcam ID. 0 if not specified"],
@@ -412,6 +419,7 @@ sports2d --help
412419
'do_ik': ["", "do inverse kinematics. false if not specified"],
413420
'use_augmentation': ["", "Use LSTM marker augmentation. false if not specified"],
414421
'use_contacts_muscles': ["", "Use model with contact spheres and muscles. false if not specified"],
422+
'participant_mass': ["", "mass of the participant in kg or none. Defaults to 70 if not provided. No influence on kinematics (motion), only on kinetics (forces)"],
415423
'close_to_zero_speed_m': ["","Sum for all keypoints: about 50 px/frame or 0.2 m/frame"],
416424
'multiperson': ["", "multiperson involves tracking: will be faster if set to false. true if not specified"],
417425
'tracking_mode': ["", "sports2d or rtmlib. sports2d is generally much more accurate and comparable in speed. sports2d if not specified"],
@@ -544,7 +552,7 @@ Sports2D:
544552

545553
4. **Chooses the right persons to keep.** In single-person mode, only keeps the person with the highest average scores over the sequence. In multi-person mode, only retrieves the keypoints with high enough confidence, and only keeps the persons with high enough average confidence over each frame.
546554

547-
4. **Converts the pixel coordinates to meters.** The user can provide a calibration file, or simply the size of a specified person. The floor angle and the coordinate origin can either be detected automatically from the gait sequence, or be manually specified.
555+
4. **Converts the pixel coordinates to meters.** The user can provide a calibration file, or simply the size of a specified person. The floor angle and the coordinate origin can either be detected automatically from the gait sequence, or be manually specified. The depth coordinates are set to normative values, depending on whether the person is going left, right, facing the camera, or looking away.
548556

549557
5. **Computes the selected joint and segment angles**, and flips them on the left/right side if the respective foot is pointing to the left/right.
550558

Sports2D/Demo/Config_demo.toml

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ video_input = 'demo.mp4' # 'webcam' or '<video_path.ext>', or ['video1_path.mp
1818
px_to_m_from_person_id = 2 # Person to use for pixels to meters conversion (not used if a calibration file is provided)
1919
px_to_m_person_height = 1.65 # Height of the reference person in meters (for pixels -> meters conversion).
2020
visible_side = ['front', 'none', 'auto'] # Choose visible side among ['right', 'left', 'front', 'back', 'auto', 'none']. String or list of strings.
21-
# if 'auto', will be either 'left', 'right', or 'front' depending on the direction of the motion
22-
# if 'none', no processing will be performed on the corresponding person
21+
# if 'auto', will be either 'left', 'right', or 'front' depending on the direction of the motion
22+
# if 'none', coordinates will be left in 2D rather than 3D
2323
load_trc_px = '' # If you do not want to recalculate pose, load it from a trc file (in px, not in m)
24-
compare = false # Not implemented yet
24+
compare = false # Not implemented yet
2525

2626
# Video parameters
2727
time_range = [] # [] for the whole video, or [start_time, end_time] (in seconds), or [[start_time1, end_time1], [start_time2, end_time2], ...]
@@ -53,7 +53,16 @@ result_dir = '' # If empty, project dir is current dir
5353
slowmo_factor = 1 # 1 for normal speed. For a video recorded at 240 fps and exported to 30 fps, it would be 240/30 = 8
5454

5555
# Pose detection parameters
56-
pose_model = 'Body_with_feet' #With RTMLib: Body_with_feet (default HALPE_26 model), Whole_body (COCO_133: body + feet + hands), Body (COCO_17), CUSTOM (see example at the end of the file), or any from skeletons.py
56+
pose_model = 'Body_with_feet' #With RTMLib:
57+
# - Body_with_feet (default HALPE_26 model),
58+
# - Whole_body_wrist (COCO_133_WRIST: body + feet + 2 hand_points),
59+
# - Whole_body (COCO_133: body + feet + hands),
60+
# - Body (COCO_17). Marker augmentation won't work, Kinematic analysis will work,
61+
# - Hand (HAND_21, only lightweight mode. Potentially better results with Whole_body),
62+
# - Face (FACE_106),
63+
# - Animal (ANIMAL2D_17)
64+
# /!\ Only RTMPose is natively embeded in Pose2Sim. For all other pose estimation methods, you will have to run them yourself, and then refer to the documentation to convert the output files if needed
65+
# /!\ For Face and Animal, use mode="""{dictionary}""", and find the corresponding .onnx model there https://github.com/open-mmlab/mmpose/tree/main/projects/rtmpose
5766
mode = 'balanced' # 'lightweight', 'balanced', 'performance', or """{dictionary}""" (see below)
5867

5968
# A dictionary (WITHIN THREE DOUBLE QUOTES) allows you to manually select the person detection (if top_down approach) and/or pose estimation models (see https://github.com/Tau-J/rtmlib).
@@ -81,7 +90,7 @@ det_frequency = 4 # Run person detection only every N frames, and inbetwee
8190
device = 'auto' # 'auto', 'CPU', 'CUDA', 'MPS', 'ROCM'
8291
backend = 'auto' # 'auto', 'openvino', 'onnxruntime', 'opencv'
8392
tracking_mode = 'sports2d' # 'sports2d' or 'deepsort'. 'deepsort' is slower but more robust in difficult configurations
84-
deepsort_params = """{'max_age':30, 'n_init':3, 'max_cosine_distance':0.3, 'max_iou_distance':0.8, 'embedder_gpu': True, embedder':'torchreid'}""" # """{dictionary between 3 double quotes}"""
93+
# deepsort_params = """{'max_age':30, 'n_init':3, 'max_cosine_distance':0.3, 'max_iou_distance':0.8, 'embedder_gpu': True, embedder':'torchreid'}""" # """{dictionary between 3 double quotes}"""
8594
# More robust in crowded scenes but tricky to parametrize. More information there: https://github.com/levan92/deep_sort_realtime/blob/master/deep_sort_realtime/deepsort_tracker.py#L51
8695
# Requires `pip install torch torchvision torchreid gdown tensorboard`
8796

@@ -105,11 +114,6 @@ xy_origin = ['auto'] # ['auto'] or [px_x,px_y]. N.B.: px_y points downwards.
105114
# If conversion from a calibration file
106115
calib_file = '' # Calibration in the Pose2Sim format. 'calib_demo.toml', or '' if not available
107116

108-
fastest_frames_to_remove_percent = 0.1 # Frames with high speed are considered as outliers
109-
close_to_zero_speed_px = 50 # Sum for all keypoints: about 50 px/frame or 0.2 m/frame
110-
large_hip_knee_angles = 45 # Hip and knee angles below this value are considered as imprecise
111-
trimmed_extrema_percent = 0.5 # Proportion of the most extreme segment values to remove before calculating their mean)
112-
113117

114118
[angles]
115119
display_angle_values_on = ['body', 'list'] # 'body', 'list', ['body', 'list'], 'none'. Display angle values on the body, as a list in the upper left of the image, both, or do not display them.
@@ -147,19 +151,21 @@ filter_type = 'butterworth' # butterworth, gaussian, LOESS, median
147151

148152

149153
[kinematics]
150-
do_ik = false # Do scaling and inverse kinematics?
154+
do_ik = true # Do scaling and inverse kinematics?
151155
use_augmentation = true # true or false (lowercase) # Set to true if you want to use the model with augmented markers
152156
use_contacts_muscles = true # true or false (lowercase) # If true, contact spheres and muscles are added to the model
153-
154-
osim_setup_path = '../OpenSim_setup' # Path to the OpenSim setup folder
157+
participant_mass = [67.0, 55.0] # kg # defaults to 70 if not provided. No influence on kinematics (motion), only on kinetics (forces)
155158
right_left_symmetry = true # true or false (lowercase) # Set to false only if you have good reasons to think the participant is not symmetrical (e.g. prosthetic limb)
156-
# default_height = 1.7 # meters # If automatic height calculation did not work, this value is used to scale the model
157-
remove_individual_scaling_setup = true # true or false (lowercase) # If true, the individual scaling setup files are removed to avoid cluttering
158-
remove_individual_ik_setup = true # true or false (lowercase) # If true, the individual IK setup files are removed to avoid cluttering
159+
160+
# Choosing best frames to scale the model
161+
default_height = 1.7 # meters # If automatic height calculation did not work, this value is used to scale the model
159162
fastest_frames_to_remove_percent = 0.1 # Frames with high speed are considered as outliers
160-
close_to_zero_speed_m = 0.2 # Sum for all keypoints: about 50 px/frame or 0.2 m/frame
163+
close_to_zero_speed_px = 50 # Sum for all keypoints: about 50 px/frame
164+
close_to_zero_speed_m = 0.2 # Sum for all keypoints: 0.2 m/frame
161165
large_hip_knee_angles = 45 # Hip and knee angles below this value are considered as imprecise
162166
trimmed_extrema_percent = 0.5 # Proportion of the most extreme segment values to remove before calculating their mean)
167+
remove_individual_scaling_setup = true # true or false (lowercase) # If true, the individual scaling setup files are removed to avoid cluttering
168+
remove_individual_ik_setup = true # true or false (lowercase) # If true, the individual IK setup files are removed to avoid cluttering
163169

164170

165171
[logging]

0 commit comments

Comments
 (0)