How to calibrate a camera
By Anthony Glynn
In a previous post we introduced camera calibration, its purpose, and the parameters that are calculated. Here we will delve a bit deeper, and look at how a camera is calibrated, as well as how to obtain a good calibration.
Camera calibration requires two things: a physical calibration pattern and a software tool which estimates the parameters. Multiple images are taken of the pattern, and these are then fed to the calibration tool as input. Different kinds of patterns exist, and the type used will depend on what the software tool supports. The most common pattern is a black and white chessboard printed on a flat surface.
The purpose of having a calibration pattern is to start with a physical object with known 3D geometry. The combination of known geometry and 2D images allows us to infer the calibration parameters, in a very similar manner to how geometry can be inferred from the combination of images and known calibration parameters.
Along with the captured images, we provide some additional details about the pattern as input to the calibration tool. In the case of a chessboard pattern, these usually consist of: the number of squares (or internal corners) in the pattern along both horizontal and vertical axes, as well as the size of an individual square in a physical unit such as millimetres. The purpose of providing the square/corner count is usually to aid the software's chessboard detector to find the pattern in the image. An accurate measurement of the physical size of a chessboard square is only necessary if the final application will be required to output the inferred geometry in a physical unit.
Kudan's camera calibration tool operates as follows: first the chessboard calibration pattern is detected in each image, along with the location of the pattern's internal corners. An initial estimate for the camera pose relative to the pattern is then computed using the perspective-3-point (P3P) pose estimation algorithm. An optimisation problem is subsequently constructed where we minimise the reprojection error of the chessboard corners. In the calibration optimisation, the 3D locations of the chessboard corners are held fixed, and the camera poses and calibration parameters are free parameters to be refined. This can be contrasted with our SLAM system which also minimises reprojection error: the calibration parameters are fixed, and the 3D locations of features and camera poses are the free parameters.
To obtain a measure of how good the estimated calibration parameters are, we compute the root mean square (RMS) reprojection error over a set of images. Ideally this ought to be a separate set of images from those used to calibrate the camera. As a rule of thumb, an RMS error of less than 0.5 pixels can be considered a good calibration.
Tips for obtaining a good calibration
- Use a large chessboard pattern, with as many internal corners as possible.
- Print the chessboard calibration pattern onto a flat surface which isn't glossy.
- Try to ensure the lighting is fairly constant across the chessboard pattern. Not too dark, or too bright, and avoid capturing any reflected glare from light sources.
- Avoid any background clutter in the images, as this may interfere with the chessboard detector.
- Ensure the whole calibration pattern is visible in all the images.
- Try to have the calibration pattern occupy a large portion of the image. Taking images from far away will generally not be particularly useful, and would require a very large number of images to obtain a decent calibration.
- Perspective is required for focal length estimation; capture some of the images at a bit of an angle. A very low angle is not necessary.
- To estimate the distortion parameters, ensure that the calibration pattern has covered the majority of the image, across the whole set of calibration images.
- Aim to capture at least 30 images for a good calibration.
Some of the images that were used the calibrate a camera: