Skip to content

cannox227/camera-dewarping

Repository files navigation

Multi-sensor camera dewarping for basketball court view correction

This project involves the development of a Python application using the OpenCV library to reduce artifacts resulting from the mixing of multiple video streams from three multi-sensor cameras in a video recording system within a sports center gymnasium. By defining points of interest, users can establish triangles that can be manipulated to correct distortion caused by the recording system. The mapping between original and new positions is achieved through a technique known as dewarping, which effectively repairs most artifacts caused by object duplication and non-converging lines


Object duplication

Line not convering to the same point
vid-duplication-fixed.mov

The detailed description of the algorithm and workflow used can be found in report.pdf

Install and Run

Requirements

Installation

  1. Install manually the requirements
  2. Clone the repo
git clone https://github.com/cannox227/camera-dewarping
  1. Access the folder
cd camera-dewarping
  1. Download assets (optional)
git lfs pull
  1. Install required packages using poetry
poetry install
  1. Activate Poetry shell
poetry shell
  1. Run the script
  • Option 1: run the script for the first time on a specific video source (to define the transformation)
    dewarp <filename>
    
  • Option 2: run the script using a previously stored transformation matrix (directly picked up from the output folder)
    dewarp <file-name> --load 
    

Run the tool

Here below are reported all the possible flags and keybinding that can be used in the tool

Usage: dewarp [OPTIONS] FILE

  Dewarping tool for cameras
  Keybindings:
      - q: exit                               - s: save configuration
      - c: cancel selected point              - r: release point selection (deselect)
      - p: pop the last point                 - l: load saved data
      - g: create a new group of points       - v: toggle visibility of the warped area
      - Enter: advance to the next state      - d: toggle drawing of points and triangles
      - Arrows: move reference                  - t: toggle reference visibility

Options:
  --load         Load presaved config (from output folder)
  --scale FLOAT  Window scale wrt. video size
  --help         Show this message and exit.
workflow-warping

Triangle definition and warping

When interacting with the video source it is possible to define three or more points from which one or more triangle will be defined using the Delaunay trianglulation technique. After having defined the triangles (with blue lines), by pressing Enter key we can start moving the triangles to the new positions. In this phase we can move the triangleses (with gray lines), then when we are happy with the configuration we can press again Enter and effectively apply the warping.


Triangle definition

Triangle can be moved to new position

New position selected

Warping applied
Final result
Final result
vid1-warping.mp4

Handling different groups of triangles

Considering the fact that Delaunay triangulation returns a group of triangles that share the same points (some of which are indeed common vertices) and artifacts don't always occur in nearby areas of the court, it's necessary to ensure the user can define more than one group of triangles.

By pressing the g key, it's possible to define additional groups of triangles, thus applying more than one Delaunay triangulation completely independently.

vid-groups.mov

Erasing a specific point / Erasing the last added point

Another proposed feature involves deleting a specific point by selecting it and pressing the c key (cancel), or deleting the last added point with the p key (pop).

vid-cancel-pop.mov

Saving the transformation

After having defined the new triangles and having applied the warping, it is possible to store the information regarding each group of old and new triangles and the correspective transformation matrix. This can be achieved by pressing the key s. The files are stored as pickle objects in the output folder in .pkl format

About

Camera dewarping for top-view court stitching

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages