Skip to content

Camera Calibration - Estimate a camera's intrinisic parameters and undistort videos.

Notifications You must be signed in to change notification settings

rfayat/camera_calibration_intrinsic

Repository files navigation

Camera calibration intrinsic

Code for estimating a camera's intrinisic properties and using it to undistort videos using aniposelib and opencv.

For the board detection, will simply rewamp the parts of code of anipose (Karashchuk et al., Cell Reports, 2021, doi:10.1016/j.celrep.2021.109730) that takes care it.

The calibration estimate and undistortion are wrappers of the opencv functions designed for this purpose, the full pipeline we use is detailed here.

Example result, note that the curved aluminum bars in the original frame (left) are straight after the processing (right): before_after

Installation

Clone the repository and install the requirements:

$ git clone https://github.com/rfayat/camera_calibration_intrinsic
$ cd camera_calibration_intrinsic
$ pip install -r requirements.txt

Generating the calibration board

Configuration file

Parameters for the size, type of board, number of rows and columns in stored in the config.toml file which can be edited.

See anipose documentation on the content of this configuration file.

Saving the board as a png

From the camera_calibration_intrinsic folder, simply run the generate_board.py script:

$ python -m generate_board

The calibration board is saved in the Desktop folder (this can be edited in the script).

Processing pipeline

Grab the camera properties (calibration)

Here we simplify the anipose calibration script for detecting the boards and combine it with bits of opencv code for the actual calibration part.

You'll need to record a calibration video using the calibration board generated at the previous step. Try to cover the full field of view of the camera and to show the board with diffent orientations. An example calibration video is available here.

$ python -m calibrate path/to/calibration_video.avi path/to/output/calibration.toml

Warning Make sure that the config.toml file in your local repository folder matches the one you used to generate the board.

Process a video (undistortion)

We can now simply use the precomputed camera distortion parameters to undistort a video:

$ python -m undistort path/to/calibration.toml path/to/distorted_video.avi path/to/output.avi

Warning This will consume a lot of RAM for large videos (cf undistort.py documentation).

TODO for polishing

  • Download links to video examples
  • Argument parsers for the scripts using argparse
  • Gif on the readme

About

Camera Calibration - Estimate a camera's intrinisic parameters and undistort videos.

Topics

Resources

Stars

Watchers

Forks

Languages