Sports2D
Compute 2D human pose and angles from a video or a webcam.
Install / Use
/learn @davidpagnon/Sports2DREADME
Sports2D
Sports2D automatically computes 2D joint positions, as well as joint and segment angles from a video or a webcam.
Announcements:
- Compensate for floor angle, floor height, depth perspective effects, generate a calibration file New in v0.8.25!
- Select only the persons you want to analyze New in v0.8!
- MarkerAugmentation and Inverse Kinematics for accurate 3D motion with OpenSim. New in v0.7!
- Any detector and pose estimation model can be used. New in v0.6!
- Results in meters rather than pixels. New in v0.5!
- Faster, more accurate
- Works from a webcam
- Better visualization output
- More flexible, easier to run
Run
pip install sports2d pose2sim -Uto get the latest version.
N.B.: As always, I am more than happy to welcome contributions (see How to contribute)!
<!--User-friendly Colab version released! (and latest issues fixed, too)\ Works on any smartphone!**\ [](https://bit.ly/Sports2D_Colab)--> </br>https://github.com/user-attachments/assets/2ce62012-f28c-4e23-b3b8-f68931bacb77
<!-- https://github.com/user-attachments/assets/6a444474-4df1-4134-af0c-e9746fa433ad --> <!-- https://github.com/user-attachments/assets/1c6e2d6b-d0cf-4165-864e-d9f01c0b8a0e -->Warning: Angle estimation is only as good as the pose estimation algorithm, i.e., it is not perfect.
Warning: Results are acceptable only if the persons move in the 2D plane (sagittal or frontal). The persons need to be filmed as parallel as possible to the motion plane.
If you need 3D research-grade markerless joint kinematics, consider using several cameras with Pose2Sim.
Contents
- Installation and Demonstration
- Play with the parameters
- Run on a custom video or on a webcam
- Run for a specific time range
- Select the persons you are interested in
- Get coordinates in meters
- Run inverse kinematics
- Run on several videos at once
- Use the configuration file or run within Python
- Get the angles the way you want
- Customize your output
- Use a custom pose estimation model
- All the parameters
- Go further
- How to cite and how to contribute
Installation and Demonstration
Test it on Hugging face
Test an online, limited version on Hugging Face:
Local installation
<!--- OPTION 0: **Use Colab** \ User-friendly (but full) version, also works on a phone or a tablet.\ [](https://bit.ly/Sports2D_Colab)\ YouTube tutorial:\ <a href = "https://www.youtube.com/watch?v=Er5RpcJ8o1Y"><img src="Content/Video_tuto_Sports2D_Colab.png" width="380"></a> -->Quick install
N.B.: Full install is required for OpenSim inverse kinematics.
Open a terminal. Type python -V to make sure python >=3.10 <=3.12 is installed. If not, install it from there.
Run:
pip install sports2d
Alternatively, build from source to test the last changes:
git clone https://github.com/davidpagnon/sports2d.git
cd sports2d
pip install .
<br>
Full install
N.B.: Only needed if you want to run inverse kinematics (
--do_ik True).
N.B.: If you already have a Pose2Sim conda environment, you can skip this step. Just runconda activate Pose2Simandpip install sports2d.
-
Install Anaconda or Miniconda:
Open an Anaconda prompt and create a virtual environment:conda create -n Sports2D python=3.12 -y conda activate Sports2D -
Install OpenSim:
Install the OpenSim Python API (if you do not want to install via conda, refer to this page):conda install -c opensim-org opensim -y -
Install Sports2D with Pose2Sim:
pip install sports2d
Demonstration
Run the demo:
Just open a command line and run:
sports2d
You should see the joint positions and angles being displayed in real time.
Check the folder where you run that command line to find the resulting video, images, TRC pose and MOT angle files (which can be opened with any spreadsheet software), and logs.
Important: If you ran the conda install, you first need to activate the environment: run conda activate sports2d in the Anaconda prompt.
Note:
The Demo video is voluntarily challenging to demonstrate the robustness of the process after sorting, interpolation and filtering. It contains:
- One person walking in the sagittal plane
- One person doing jumping jacks in the frontal plane. This person then performs a flip while being backlit, both of which are challenging for the pose detection algorithm
- One tiny person flickering in the background who needs to be ignored
Visualize in Blender
-
Install the Pose2Sim_Blender add-on.
Follow instructions on the Pose2Sim_Blender add-on page. -
Import the camera and video.
- Cameras -> Import: Open your
demo_calib.tomlfile from yourresult_dirfolder. - Images/Videos -> Show: open your video file (e.g.,
demo_Sports2D.mp4).
-> Other tools -> See through camera
- Cameras -> Import: Open your
-
Open your point coordinates.
OpenSim data -> Markers: Open your trc file(e.g.,demo_Sports2D_m_person00.trc) from yourresult_dirfolder.
This will optionally create an animated rig based on the motion of the captured person. -
Open your animated skeleton:
Make sure you first set--do_ik True(full install required). See inverse kinematics section for more details.- OpenSim data -> Model: Open your scaled model (e.g.,
demo_Sports2D_m_person00_LSTM.osim). - OpenSim data -> Motion: Open your motion file (e.g.,
demo_Sports2D_m_person00_LSTM_ik.mot).
The OpenSim skeleton is not rigged yet. Feel free to contribute! [