Table of Contents

This tutorial focuses on pinhole camera calibration. The goal of the calibration is here to estimate some camera parameters that allows to make the relation between camera's natural units (pixel positions in the image) and real world units (normalized position in meters in the image plane).

Introduction

If we denote the position of a pixel in the digitized image, this position is related to the corresponding coordinates in the normalized space.

In ViSP we consider two unit conversions:

From meters to pixels we consider the following formula:

with

From pixels to meters we consider the following formula:

with

In this model we consider the parameters where:

are the coordinates of the principal point in pixel;

are the ratio between the focal length and the size of a pixel;

are the parameters used to correct the distortion.

Note

It may be useful to make a tour in Tutorial: Bridge over OpenCV that makes in relation the camera model used in ViSP with the one proposed by OpenCV.

Note also that the container dedicated to camera parameters is implemented in the vpCameraParameters class. It allows to consider two kind of models; with or without distortion.

The calibration process allows to estimate the values of these parameters. To this end, one of the following calibration grid can be used:

To calibrate your camera you need to take snapshots of one of these two patterns with your camera. At least 5 good snapshots of the input pattern acquired at different positions are requested for good results.

Source code

All the material (source code and images) described in this tutorial is part of ViSP source code and could be downloaded using the following command:

the estimation of the parameters is done using a virtual visual servoing scheme;

the calibration tool takes as input a configuration file that allows to precise the kind of pattern used in the images (chessboard or circles grid), and the location of the images used as input. If libjpeg and libpng 3rd party libraries are installed and detected during ViSP configuration, you may consider .pgm, .ppm, .jpg, .png images. Default configuration files are provided in example/calibration folder;

the resulting parameters are saved in camera.xml file.

Calibration from a chessboard

In this section we consider the OpenCV chessboard pattern that has a size of 9 by 6. Each square of the chessboard is 0.025 meters large. We took 5 images called chessboard-01.png, chessboard-02.png, ..., chessboard-05.png. Hereafter we give an example of one of these images.

Snapshot example of the chessboard used to calibrate the camera.

Before starting the calibration we need to create a configuration file. We create default-chessboard.cfg with the following content:

# Number of inner corners per a item row and column. (square, circle)

BoardSize_Width: 9

BoardSize_Height: 6

# The size of a square in meters

Square_Size: 0.025

# The type of pattern used for camera calibration.

# One of: CHESSBOARD or CIRCLES_GRID

Calibrate_Pattern: CHESSBOARD

# The input image sequence to use for calibration

Input: chessboard-%02d.png

# Tempo in seconds between two images. If > 10 wait a click to continue

Tempo: 1

Note

The images and the configuration file used in this tutorial are available in ViSP source code and copied in the same folder than the camera_calibration binary.

To estimate the camera parameters, just enter in ViSP <binary_dir>/examples/calibration and run:

Calibration from a circles grid

In this section we consider the ViSP symmetric circles grid pattern that has a size of 6 by 6. Each circle center of gravity is 0.034 meters distant from it's horizontal or vertical neighbor. We took 5 images called circles-01.pgm, circles-02.pgm, ..., circles-05.pgm. Hereafter we give an example of such an image.

Snapshot example of the symmetric circles grid used to calibrate the camera.

Before starting the calibration we need to create a configuration file. We create circles-grid.cfg with the following content:

# Number of inner corners per a item row and column. (square, circle)

BoardSize_Width: 6

BoardSize_Height: 6

# The size of a square in meters

Square_Size: 0.034

# The type of pattern used for camera calibration.

# One of: CHESSBOARD or CIRCLES_GRID

Calibrate_Pattern: CIRCLES_GRID

# The input image sequence to use for calibration

Input: circles-%02d.pgm

# Tempo in seconds between two images. If > 10 wait a click to continue

Tempo: 1

Note

The images and the configuration file used in this tutorial are available in ViSP source code and copied in the same folder than the camera_calibration binary.

To estimate the camera parameters, just enter in ViSP <binary_dir>/examples/calibration and run: