An implementation of Tsai's camera calibration algorithm.
Camera calibration is the process of estimating the parameters of a camera model order to create a model that approximates a physical camera. The resulting model describes the relationship between pixels in the image and rays of light in the real world.
In this implementation a modified pinhole camera model with corrections applied to account for radial lens distortion is used to model the physical camera. Parameters such as focal length and position of the camera are recovered.
The photograph used as input needs to contain points with known geometry. For each of the points the coordinates in the real world (in millimeters) and the corresponding coordinates in the photograph (in pixels) are used as input to the calibration algorithm.
To estimate the parameters, a two-stage optimisation process is used. First, the parameters of a simplified linear model are estimated using a linear optimisation process (Singular Value Decomposition). In the second stage, the model is extended to include non-linear distortions, with a non-linear optimisation process (gradient descent) used provide the final estimates.
In this example a photograph of a calibration object (two checkerboards attached at a right angle) was used to find the coordinates (in pixels) of several points on the obejct. These coordinates, along with their corresponding coordinates in millimeters are used as input to the algorithm.
In the image below the red "actual" points are the input to the algorithm. The resulting model is then used to re-project the points onto the image using only the real-world (millimeter) coordinates - this is shown as the "projected" points. Adding non-linear distortion to the "projected" points results in the "distorted" points.
If the model is accurate the re-projected and distorted points should appear close to their "actual" locations.
With a stereo pair (2 cameras), it's easy to measure the baseline (distance between the center of the cameras). Since the resulting model gives the positions of the cameras relative to the model, this can be calculated to the measurement. If you like looking at numbers I've included some in the table below.
Measured | Calibration Result | |||
---|---|---|---|---|
Left | Right | Stereo | ||
Focal Length (mm) | 3 (approx.) | 1.89 | 1.93 | |
First-order radial distortion (mm^-2) | -0.244 | -0.240 | ||
Baseline (mm) | 33 | 32.50 | ||
Camera-cube distance (mm) | 233 (approx.) | 251.0 |
The source code is available from github.com/bailus/tsai-calibration
The above software by Samuel Bailey is licensed under the GNU General Public License, either version 3 of the Licence, or (at your option) any later version.