Giter Club home page Giter Club logo

sports2d's Introduction

Continuous integration PyPI version
Downloads GitHub issues GitHub issues-closed
DOI License

Open In Colab

Sports2D

Sports2D automatically computes 2D joint positions, as well as joint and segment angles from a video.


Announcement:
User-friendly Colab version released! (and latest issues fixed, too)
Works on any smartphone!

Open In Colab

Batch processing enabled: process multiple videos at once!


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, from right to left or from left to right.
If you need research-grade markerless joint kinematics, consider using several cameras, and constraining angles to a biomechanically accurate model. See Pose2Sim for example.
Warning: Google Colab does not follow the European GDPR requirements regarding data privacy. Install locally if this matters.

Know issue: Results won't be good with some iPhone videos in portrait mode (unless you are working on Colab). This is solved by priorly converting them with ffmpeg -i video_input.mov video_output.mp4, or even more simply with any random online video converter such as https://video-converter.com.

Contents

  1. Installation and Demonstration
    1. Installation
    2. Demonstration: Detect pose and compute 2D angles
  2. Go further
    1. Use on your own videos
    2. Use OpenPose for multi-person, more accurate analysis
    3. Advanced-settings
    4. How it works
  3. How to cite and how to contribute

Installation and Demonstration

Installation

  • OPTION 0: Use Colab
    User-friendly (but full) version, also works on a phone or a tablet.
    Open In Colab
    YouTube tutorial:

  • OPTION 1: Quick install
    Open a terminal. Type python -V to make sure python '>=3.7 <=3.11' is installed, and then:

    pip install sports2d
  • OPTION 2: Safer install with Anaconda
    Install Miniconda:
    Open an Anaconda prompt and create a virtual environment by typing:

    conda create -n Sports2D python=3.10 -y
    conda activate Sports2D
    pip install sports2d
  • OPTION 3: Build from source and test the last changes
    Open a terminal in the directory of your choice and clone the Sports2D repository.

    git clone https://github.com/davidpagnon/sports2d.git
    cd sports2d
    pip install .

Demonstration: Detect pose and compute 2D angles

If you did the conda install, type conda activate Sports2D in the Anaconda prompt. Otherwise, skip to the next line.
Open a terminal, enter pip show sports2d, check sports2d package location.
Copy this path and go to the Demo folder by typing cd <path>\Sports2D\Demo.
Type ipython, and test the following code:

from Sports2D import Sports2D
Sports2D.detect_pose('Config_demo.toml')
Sports2D.compute_angles('Config_demo.toml')

You should obtain a video with the overlaid 2D joint positions, and angle text values. This output is also provided as an image folder.
You should additionally obtain the same information as time series, stored in .csv files. These files can be opened with any spreadsheet software, or with the Pandas Python library for example.
In addition, you will get the original OpenPose-like json coordinates files.

Go further

Use on your own videos

  1. Copy-paste Config_demo.toml in the directory of your videos.

  2. Open it with any text editor.
    Replace the video_files value with the name of your videos.

  3. Open a terminal or an Anaconda prompt, type:

    cd path/to/video/directory
    conda activate Sports2D &:: skip if you did not install with Anaconda
    ipython
    from Sports2D import Sports2D
    Sports2D.detect_pose('Config_demo.toml')
    Sports2D.compute_angles('Config_demo.toml')

Optionally: If your videos are not in the same folder as Config_demo.toml, specify their location in video_dir.
Similarly, if you launch Sports2D in an other directory, specify the location of the config file this way: Sports2D.detect_pose(<path_to_Config_demo.toml>)
In pose, specify the use of BlazePose or OpenPose as joint detectors: this will be detailed in the next section.
In compute_angles, select your angles of interest.

Use OpenPose for multi-person, more accurate analysis

OpenPose is slower than BlazePose, but usually more accurate. It also allows for the detection of multiple persons, whose indices are consistent across frames.

  1. Install OpenPose (instructions there).
    Windows portable demo works fine.

  2. If you want even more accurate results, use the BODY_25B experimental model instead of the standard BODY_25 one. This requires manually downloading the model. You can optionally download from there the BODY_135 model which will let you compute wrist flexion and hand segment angle, however this will be much slower.

  3. In Config_demo.tomlpose.OPENPOSE, specify your OpenPose model, and the path where you downloaded OpenPose.

N.B.: If you want to benefit from the capabilities of OpenPose but do not manage to install it, you can use the Colab notebook version. Note that your data will be sent to the Google servers, which do not follow the European GDPR requirements regarding privacy. Open In Colab

Advanced settings

  1. Config_demo.tomlpose_advanced: These settings are only taken into account if OpenPose is used.

    1. load_pose: If you need to change some settings but have already run a pose estimation, you can set this to true in order to not regenerate the json pose files.

    2. save_vid and save_img: You can choose whether you want to save the resulting video and images. If set to false, only pose and angle .csv files will be generated.

    3. interp_gap_smaller_than: Gaps are interpolated only if they are not too wide.

    4. filter: true or false. If true, you can choose among Butterworth, Gaussian, LOESS, or Median, and specify their parameters.
      Beware that the appearance of the unfiltered skeleton may not match the filtered coordinates and angles.

    5. show_plots: Displays a window with tabs corresponding to the coordinates of each detected point. This may cause Python to crash.

  2. Config_demo.tomlcompute_angles_advanced: These settings are taken into account both with BlazePose and OpenPose.

    1. save_vid and save_img: Cf pose_advanced.

    2. filter: Cf pose_advanced.

    3. show_plots: Cf pose_advanced.

N.B.: The settings and results of all analyses are stored int the logs.txt file, which can be found in in the sports2d installation folder (pip show sports2d to find the path).

How it works

Pose detection:

BlazePose or OpenPose are used to detect joint centers from a video.

  • If BlazePose is used, only one person can be detected.
    No interpolation nor filtering options are available. Not plotting available.

  • If OpenPose is used, multiple persons can be consistently detected across frames. A person is associated to another in the next frame when they are at a small distance.
    Sequences of missing data are interpolated if they are less than N frames long.
    Resulting coordinates can be filtered with Butterworth, gaussian, median, or loess filter. They can also be plotted.

Angle computation:

Joint and segment angles are computed from csv position files.
If a person suddenly faces the other way, this change of direction is taken into account.
Resulting angles can be filtered in the same way as point coordinates, and they can also be plotted.

Joint angle conventions:

  • Ankle dorsiflexion: Between heel and big toe, and ankle and knee
  • Knee flexion: Between hip, knee, and ankle
  • Hip flexion: Between knee, hip, and shoulder
  • Shoulder flexion: Between hip, shoulder, and elbow
  • Elbow flexion: Between wrist, elbow, and shoulder

Segment angle conventions:
Angles are measured anticlockwise between the horizontal and the segment.

  • Foot: Between heel and big toe
  • Shank: Between knee and ankle
  • Thigh: Between hip and knee
  • Arm: Between shoulder and elbow
  • Forearm: Between elbow and wrist
  • Trunk: Between shoulder midpoint and hip midpoint

How to cite and how to contribute

How to cite

If you use Sports2D, please cite [Pagnon, 2023].

 @misc{Pagnon2023,
   author = {Pagnon, David},
   title = {Sports2D - Angles from video},
   year = {2023},
   doi= {10.5281/zenodo.7903963},
   publisher = {GitHub},
   journal = {GitHub repository},
   howpublished = {\url{https://github.com/davidpagnon/Sports2D}},
 }

How to contribute

I would happily welcome any proposal for new features, code improvement, and more!
If you want to contribute to Sports2D, please follow this guide on how to fork, modify and push code, and submit a pull request. I would appreciate it if you provided as much useful information as possible about how you modified the code, and a rationale for why you're making this pull request. Please also specify on which operating system and on which python version you have tested the code.

Here is a to-do list: feel free to complete it:

  • Compute segment angles.
  • Multi-person detection, consistent over time.
  • Only interpolate small gaps.
  • Filtering and plotting tools.
  • Handle sudden changes of direction.
  • Colab version for those who cannot install OpenPose.
  • Colab version more user-friendly, usable on a smartphone.
  • Batch processing for the analysis of multiple videos at once.
  • Convert positions to meters by providing the distance between two clicked points
  • Implement AlphaPose which might be more accurate on broadcasted videos.
  • Perform Inverse kinematics and dynamics with OpenSim (cf. Pose2Sim, but in 2D). Update this model (add arms, markers, remove muscles and contact spheres). Add pipeline example.

  • Track other points and angles with classic tracking methods (cf. Kinovea), or by training a model (cf. DeepLabCut).
  • Pose refinement. Click and move badly estimated 2D points. See DeepLabCut for inspiration.
  • Add tools for annotating images, undistort them, take perspective into account, etc. (cf. Kinovea).
  • Check other methods for sorting people across frames (STAF or LivePoseTracker.
  • GUI applications for Windows, Mac, and Linux, as well as for Android and iOS (minimal version on mobile device, with only BlazePose). Code with Kivy.
  • Include OpenPose in Sports2D executable files. Dockerize it?
  • Full test on MacOS.

sports2d's People

Contributors

davidpagnon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

milanhofmann

sports2d's Issues

ERROR Colab

Hello Guys, before I could run in Colab but now they are giving the following errors.

could you help me please?

update-alternatives: using /usr/bin/python3.10 to provide /usr/bin/python3 (python3) in auto mode Connecting to Google Drive... Mounted at /content/drive Installing Sports2D in Google Drive... Collecting Sports2D Downloading sports2d-0.2.5-py3-none-any.whl (2.6 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.6/2.6 MB 10.8 MB/s eta 0:00:00 Requirement already satisfied: ipython in /usr/local/lib/python3.10/dist-packages (from Sports2D) (7.34.0) Requirement already satisfied: toml in /usr/local/lib/python3.10/dist-packages (from Sports2D) (0.10.2) Requirement already satisfied: numpy in /usr/local/lib/python3.10/dist-packages (from Sports2D) (1.23.5) Requirement already satisfied: pandas>=1.5 in /usr/local/lib/python3.10/dist-packages (from Sports2D) (1.5.3) Requirement already satisfied: scipy in /usr/local/lib/python3.10/dist-packages (from Sports2D) (1.10.1) Collecting anytree (from Sports2D) Downloading anytree-2.9.0-py3-none-any.whl (38 kB) Requirement already satisfied: opencv-python in /usr/local/lib/python3.10/dist-packages (from Sports2D) (4.8.0.76) Collecting mediapipe (from Sports2D) Downloading mediapipe-0.10.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (33.5 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 33.5/33.5 MB 39.3 MB/s eta 0:00:00 Requirement already satisfied: matplotlib in /usr/local/lib/python3.10/dist-packages (from Sports2D) (3.7.1) Collecting PyQt5 (from Sports2D) Downloading PyQt5-5.15.9-cp37-abi3-manylinux_2_17_x86_64.whl (8.4 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 8.4/8.4 MB 82.6 MB/s eta 0:00:00 Requirement already satisfied: statsmodels in /usr/local/lib/python3.10/dist-packages (from Sports2D) (0.14.0) Requirement already satisfied: python-dateutil>=2.8.1 in /usr/local/lib/python3.10/dist-packages (from pandas>=1.5->Sports2D) (2.8.2) Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.10/dist-packages (from pandas>=1.5->Sports2D) (2023.3) Requirement already satisfied: six in /usr/local/lib/python3.10/dist-packages (from anytree->Sports2D) (1.16.0) Requirement already satisfied

Results from Vertical Movement instead of Left to Right

I was also wondering if the Sports2D model can still accurately track and analyze such vertical dynamics (Warning section says it's only lateral). Also are there any specific parameters/settings that I can change to get the accurate coordinates/joint angles from a vertical movement?

Colab wrong command?

Hi @davidpagnon
I've checked your colab notebook placed here
and i found that it might have some wrong command! (not sure if the openpose is checkedout to specific tag or not)

!sed -i 's/execute_process(COMMAND git checkout master WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/3rdparty/caffe)/execute_process(COMMAND git checkout f019d0dfe86f49d1140961f8c7dec22130c83154 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/3rdparty/caffe)/g' openpose/CMakeLists.txt

This line of code do noting actually!

here is my clone of openpose (today) without checkout, and i can see that openpose/CMakeLists.txt containes lines with git checkout master but all of them are commented out!
image

either this command is not needed or needs to be modified for replacing the 1807aad with f019d0d for caffe!

Also does it needs to install opencv as a requirement?( i think the openpose > V1.6.0 do not needs the opencv while with the available code on a native ubuntu system, it askes for opencv while making it with the default CMakeList.txt file!

Thanks
Best regards

Joint Angle Overlay Video Issue

For some reason, the joint angle annotations appear sped up and 'chopped up' during playback. Is there a specific format or setting that optimizes the video output for smooth playback?

Alphapose

Hello, just wondering when will the version of alphapose release?
Sincerely asking, thank you.

Error

Hi!

I'm getting the attached image error when I try to do the analysis in anaconda prompt
Can you help me?

sports 2d error

Face + hands

Hi, your work is much appritiated, but do you plan to add hands + facial keypoints?

or at least guide on how to do it?

Thanks
Best regards

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.