Skip to content

Python module for multitracking objects over any given video using OpenCV. Mainly tested on tracking players over a football field.

Notifications You must be signed in to change notification settings

julianpalladino/football_tracking

Repository files navigation

OpenCV tracking

Python module for multitracking objects over any given video. Mainly tested on tracking players over a football field.

Usage

After cloning the repo just build the docker image

docker build . -t tracker

and run it with the desired parameters

docker run -v "$PWD":/host_volume -w /app tracker:latest \
        -input_path <input video filepath> \
        -input_bbox_path <input bbox json filepath> \
        -output_path <output video filepath> \
        -method <tracking method>

In which

  • <input video filepath>: filepath for a mp4 video to annotate.
  • <input bbox json filepath>: filepath for a json file with initial bbox information. The json is expected to be a list of dictionaries with the following keys:
    • Name: String. Name of the object to track. i.e 'player'
    • Id: Int. Id of the object to track.
    • Coords: List of 4 ints determining the bounding box position and size: x, y, width, height
  • <output video filepath>: filepath for the output mp4 file to save.
  • <tracking method>: tracking method, should be one of the following ['dasiamrpn', 'tld', 'kcf', 'goturn', 'csrt', 'mil', 'boosting', 'mosse', 'medianflow']

** Note: ** The volume /host_volume is mounted to allow input and output paths from outside the container. See this for more info.

For example:

docker run -v "$PWD":/app tracker:latest \
        -input_path /app/data/messi1.mp4 \
        -input_bbox_path /app/data/messi1_initial_conditions.json \
        -output_path /app/output/messi1_tracked.mp4 \
        -method csrt

Note: The recommended method for the given test files is CSRT.

Testing

To test the script with all 4 available videos and all available methods, build the docker image

docker build . -t tracker

and run it with the -test flag, which executes the pytest module

docker run -v "$PWD":/app tracker:latest -test

Note: When a tracking method fails to track an objet at least 70% of the frames, pytest will issue a warning. This can happen for less accurate methods like MedianFlow.

Supported methods

Comparative examples: Boosting vs CSRT vs MedianFlow

We test a small subset of all methods over three videos.

Example 1: Multiple tracking

Method: Boosting

boosting

Method: CSRT

csrt

Method: MedianFlow

medianflow

Example 2: Managing occlusions

Method: Boosting

boosting

Method: CSRT

csrt

Method: MedianFlow

medianflow

Example: Managing occlusions, grainy picture and zoom

Method: Boosting

boosting

Method: CSRT

csrt

Method: MedianFlow

medianflow

About

Python module for multitracking objects over any given video using OpenCV. Mainly tested on tracking players over a football field.

Topics

Resources

Stars

Watchers

Forks