Camera Calibration Tool


Description

The camera calibration tool lets you calibrate any video camera very accurately and in few seconds.

The user presents a flat checkerboard pattern in front of the camera, and the program automatically acquires a number of images and uses them to compute the intrinsic camera parameters (focal length, principal point, distortion coefficients) as well as the extrinsic parameters (3D position of the pattern for each image).

Since the corners of the pattern are located automatically on each image, the entire procedure is fully automatic. Once calibration is done, the program lets you undistort the video images in real time (at frame rate). The lens distortion model consists of two terms: a radial distortion term (up to the fourth order) and a tangential distortion term (two scalars for encoding the angular orientation of the focal plane with respect to the sensor plane). Consequently, the lens distortion model is parameterized using four scalar coefficients.

A complete tutorial of the algorithm with matlab code is provided, see
Tutorial Section below.

DirectShow Filter Application

Note that this filter requires that you have DirectShow 6.0 or greater installed with graphedt.exe  (DirectShow 6.0 for NT4.0, DirectShow 7.0 for Win 98 or Win2000) (http://www.microsoft.com/downloads/release.asp?ReleaseID=16927 ~128MB[!]). You will also need a video camera source filter which should be supplied by your USB camera vendor. Microsoft* Windows* 2000 may be the most suitable operating system for development since many vendors do not supply filters for Windows NT 4.0. However, Windows 98 will be adequate for just running the filter graph

An example filter graph is shown below. It is running our own calibration filter that processes a video source from a Matrox Meteor II card and then passes the output to a video renderer.


Right clicking on the CalibFilter brings up its property control page as follows:

Controls

[1] Enter the number of columns (Squares per row)in your calibration checkerboard. Click "Apply" [12] to enter.
[2] Enter the number of rows (Squares per column)in your calibration checkerboard. Click "Apply" [12] to enter.
[3] Actual size of squares in your calibration checkerboard (in whatever units -- say cm). Click "Apply" [12] to enter.
[4] Start automatic collection of calibration frames.
[5] Save current set of calibration parameters to disk.
[6] Load previously saved calibration parameters.
[7] If you've just calibrated the camera, or have loaded [6] previous calibration parameters, checking this box causes the computation of the undistorted image in real time. If this box is not checked, the raw video frames are displayed. You must click "Apply" [12] to register the check.
[8] Checking this box causes an OpenGL display to show the tracking of the calibration checkerboard. You must click "Apply" [12] to register the check.
[9] Set how many frames of the calibration checkerboard you want to collect before performing calibration (between 10 and 20 is usually enough, use more only if high accuracy is desired). Click "Apply" [12] to enter.
[10] Set how number of miliseconds of delay between collecting frames of the calibration checkerboard when you start [4] calibration. This allows you as much time as desired to move the calibration checkerboard around the video scene before the next frame is taken during calibration. Click "Apply" [12] to enter.
[11] The current calibration parameters are displayed in this box.
[12] You must click "Apply" after setting any or all of [1], [2], [3], [9] and/or [10].

How To...

Calibrate a camera

(a) Get or make a black and white checkerboard calibration object as shown in the images above or animated gif's below.
(b) Enter the number of columns ("squares per row") in [1] and number of rows (squares per column) in [2]; Enter the size of a square in whatever units in [3] (optional) ; Enter the number of frames that you want to collect in [9] (10-20 usually suffices); Enter the minimum time between capturing frames to allow you time to move the calibration object.
(c) Click "Apply" [12].
(d) Click "Start" [4].
(e) Move the checkerboard around. The number of frames collected will display in [11]. When all frames are collected it will solve for the calibration parameters and display them in [11].
(f) Checking [7] followed by clicking "Apply" [12] causes the rectified video image to be displayed as shown in the second example below.

Notes: When calibrating, the video image flashes when a frame is captured. It won't capture unless the colored lines are drawn on the checkerboard as shown in the examples below. You must move the calibration object around -- if your views are too much alike, you will get an ill-conditioned matrix with resultant divide by zero when the filter solves for the camera calibration parameters.

Save calibration parameters to a file:

(a) Click "Save" [5] and a dialog box will prompt you for saving the calibration parameters under a text file. Click this
link for information on the camera model, and the content of the text file.

Load previously stored calibration parameters:

(a) Click "Load" [6] and a dialog box will allow you to select a calibration parameter file.
(b) Calibration parameters will appear in [11].

Turn image rectification on and off:

(a) On: Check the "Undistortion" box [7]. Click "Apply" [12].
(b) Off: Un-check the "Undistortion" box [7]. Click "Apply" [12].

Turn the 3D OpenGL window on and off:

(a) On: Check the "Show 3D window" box [8]. Click "Apply" [12].
(b) Off: Un-check the "Show 3D window" box [8]. Click "Apply" [12].

Examples

The following movie shows the 3D pose of the calibration object being computed in real time after the camera has been calibrated.


The next picture shows image undistortion performed by the filter.

Tutorial and calibration toolbox

In addition to the OpenCV implementation of the calibration functions and tool, we provide a complete tutorial and calibration toolbox for MATLAB. It can be downloaded from OpenCV page at Source Forge