Skip to content

Commit

Permalink
Various small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
davidpagnon committed Dec 5, 2024
1 parent ff64d93 commit 685f3e0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 25 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,9 @@ Will be much faster, with no impact on accuracy. However, the installation takes
<br>

#### Customize your output:
- Choose whether you want video, images, trc pose file, and angle mot file:
- Choose whether you want video, images, trc pose file, angle mot file, and real-time display:
```cmd
sports2d --save_vid false --save_img true --save_trc false --save_mot true
sports2d --save_vid false --save_img true --save_pose false --save_angles true --show_realtime_results false
```
- Choose which angles you need:
```cmd
Expand Down Expand Up @@ -415,7 +415,7 @@ If you want to contribute to Sports2D, please follow [this guide](https://docs.g
- [x] Run again without pose estimation with the option `--load_trc` for px .trc file.
- [x] **Convert positions to meters** by providing the person height, a calibration file, or 3D points [to click on the image](https://stackoverflow.com/questions/74248955/how-to-display-the-coordinates-of-the-points-clicked-on-the-image-in-google-cola)
- [ ] Perform **Inverse kinematics and dynamics** with OpenSim (cf. [Pose2Sim](https://github.com/perfanalytics/pose2sim), but in 2D). Update [this model](https://github.com/davidpagnon/Sports2D/blob/main/Sports2D/Utilities/2D_gait.osim) (add arms, markers, remove muscles and contact spheres). Add pipeline example.
- [ ] Run with the options `--load_trc` and `--compare` to visually compare motion with a trc file. If run with a webcam input, the user can follow the motion of the trc file. Further calculation can then be done to compare specific variables.
- [ ] Run with the option `--compare_to` to visually compare motion with a trc file. If run with a webcam input, the user can follow the motion of the trc file. Further calculation can then be done to compare specific variables.
- [ ] **Colab version**: more user-friendly, usable on a smartphone.
- [ ] **GUI applications** for Windows, Mac, and Linux, as well as for Android and iOS.

Expand Down
40 changes: 19 additions & 21 deletions Sports2D/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -1559,10 +1559,10 @@ def process_fun(config_dict, video_file, time_range, frame_rate, result_dir):
if save_img:
cv2.imwrite(str((img_output_dir / f'{output_dir_name}_{frame_count:06d}.png')), img)

if save_pose:
all_frames_X.append(np.array(valid_X))
all_frames_Y.append(np.array(valid_Y))
all_frames_scores.append(np.array(valid_scores))
all_frames_X.append(np.array(valid_X))
all_frames_Y.append(np.array(valid_Y))
all_frames_scores.append(np.array(valid_scores))

if save_angles and calculate_angles:
all_frames_angles.append(np.array(valid_angles))
if video_file=='webcam' and save_vid: # To adjust framerate of output video
Expand All @@ -1587,26 +1587,25 @@ def process_fun(config_dict, video_file, time_range, frame_rate, result_dir):


# Post-processing: Interpolate, filter, and save pose and angles
all_frames_X_homog = make_homogeneous(all_frames_X)
all_frames_X_homog = all_frames_X_homog[...,keypoints_ids]
all_frames_Y_homog = make_homogeneous(all_frames_Y)
all_frames_Y_homog = all_frames_Y_homog[...,keypoints_ids]
all_frames_Z_homog = pd.DataFrame(np.zeros_like(all_frames_X_homog)[:,0,:], columns=keypoints_names)
all_frames_scores = make_homogeneous(all_frames_scores)

frame_range = [0,frame_count] if video_file == 'webcam' else frame_range
all_frames_time = pd.Series(np.linspace(frame_range[0]/fps/slowmo_factor, frame_range[1]/fps/slowmo_factor, frame_count+1), name='time')

if not multiperson:
detected_persons = [get_personID_with_highest_scores(all_frames_scores)]
else:
detected_persons = range(all_frames_X_homog.shape[1])

# Post-processing pose
if save_pose:
logging.info('\nPost-processing pose:')
# Select only the keypoints that are in the model from skeletons.py, invert Y axis, divide pixel values by 1000
all_frames_X_homog = make_homogeneous(all_frames_X)
all_frames_X_homog = all_frames_X_homog[...,keypoints_ids]
all_frames_Y_homog = make_homogeneous(all_frames_Y)
all_frames_Y_homog = all_frames_Y_homog[...,keypoints_ids]
all_frames_scores = make_homogeneous(all_frames_scores)

all_frames_Z_homog = pd.DataFrame(np.zeros_like(all_frames_X_homog)[:,0,:], columns=keypoints_names)

# Process pose for each person
if not multiperson:
detected_persons = [get_personID_with_highest_scores(all_frames_scores)]
else:
detected_persons = range(all_frames_X_homog.shape[1])

# Process pose for each person
trc_data = []
trc_data_unfiltered = []
for i in detected_persons:
Expand Down Expand Up @@ -1706,7 +1705,6 @@ def process_fun(config_dict, video_file, time_range, frame_rate, result_dir):
cx, cy = xy_origin_estim
else:
cx, cy = xy_origin
print(xy_origin_estim, xy_origin)
logging.info(f'Using height of person #{calib_on_person_id} ({person_height_m}m) to convert coordinates in meters. '
f'Floor angle: {np.degrees(-floor_angle_estim) if not floor_angle=="auto" else f"auto (estimation: {round(np.degrees(-floor_angle_estim),2)}°)"}, '
f'xy_origin: {xy_origin if not xy_origin=="auto" else f"auto (estimation: {[round(c,2) for c in xy_origin_estim]})"}.')
Expand Down Expand Up @@ -1775,7 +1773,7 @@ def process_fun(config_dict, video_file, time_range, frame_rate, result_dir):



# Angles post-processing
# Post-processing angles
if save_angles and calculate_angles:
logging.info('\nPost-processing angles:')
all_frames_angles = make_homogeneous(all_frames_angles)
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = sports2d
version = 0.5.0
version = 0.5.1
author = David Pagnon
author_email = [email protected]
description = Detect pose and compute 2D joint angles from a video.
Expand Down

0 comments on commit 685f3e0

Please sign in to comment.