From 685f3e0af5edf51206ded811babae1abd14580da Mon Sep 17 00:00:00 2001 From: davidpagnon Date: Thu, 5 Dec 2024 14:55:16 +0100 Subject: [PATCH] Various small fixes --- README.md | 6 +++--- Sports2D/process.py | 40 +++++++++++++++++++--------------------- setup.cfg | 2 +- 3 files changed, 23 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 61e5a36..6561dc5 100644 --- a/README.md +++ b/README.md @@ -237,9 +237,9 @@ Will be much faster, with no impact on accuracy. However, the installation takes
#### 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 @@ -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. diff --git a/Sports2D/process.py b/Sports2D/process.py index d6a835c..506b5f2 100644 --- a/Sports2D/process.py +++ b/Sports2D/process.py @@ -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 @@ -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: @@ -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]})"}.') @@ -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) diff --git a/setup.cfg b/setup.cfg index 2eadb33..604b8a0 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = sports2d -version = 0.5.0 +version = 0.5.1 author = David Pagnon author_email = contact@david-pagnon.com description = Detect pose and compute 2D joint angles from a video.