Ivan Kirigin
{ Computer Vision Specialist }

{ Research} Advised by Sanjiv Singh at the Robotics Institute, Carnegie Mellon University

{Camera Calibration}

Camera Calibration
Tutorial

This project entailed creating a simple and fast way of performing camera calibration for Athena Controls. An
implementation existed for a number of calibration utility functions, but using the given interface was very inefficient. Here, I made a wrapper around these utility functions and designed the interface to allow for intuitive and swift calibration. The base code case for the calibration is supported by Jean-Yves Bougue here. It implements the method by Heikkilä & Silvén, which is described here with a more technical paper here.

My biggest contributions were a very intuitive interface for selection of images and a fast method to go about the iterative steps to reducing error. My code is available here. The simplest way to learn more about it is to read the following “how-to” tutorial:

Contents
1) Taking an Image set
2) Installing the software
3) Starting a calibration procedure
4) Choosing images
5) Marking Corners
6) Performing Calibration
7) Saving a Calibration procedure

1) Taking an Image set
Intrinsic camera calibration is based on finding parameters describing how a camera does not fit an ideal projective model. There are many papers on the meaning of the parameters (here), and on how the calibration procedure works (here).

This section will focus on how to take a reasonable image set to perform calibration. First, a target should be made, consisting of a black & white checkerboard on a flat background. The target should not be flexible, because any warping in the target will appear to come from the camera. Making the target bigger will reduce the weight of any small apparent warping.

Here is an example of a target:

Note that the aspect ratio should be similar to the images you wish to take, e.g. 4x3 for 640x480. This is merely a practical matter of being able to fit the entire target in the image. The number of square does not matter. What is essential in creating the target is that the squares are actually squares, a not stretched into rectangles because of a faulty printing process.

Capture images of this target under nice, bright lighting conditions, from different view points. This can be done by moving the camera or the target, but the latter is probably easier. To get good coverage of possible viewing angles, start with three views: with the target’s top oriented forward, with the target flat, and with the target’s bottom oriented forward. From these three, rotate left-right a few times. For instance, with each of these three, orient the left side greatly forward, slightly forward, flat, slightly backward, and completely backward.

There are two specific images you should include. The first is where the side of the target is along the edge of the image, so that you can measure radial distortion. In another, there should be a noticeable projective depth to the target.

This should produce approximately 15-20 images. On the next page, there is an example set of images. Note that having many more images will not increase the accuracy of your calibration significantly. Also, all the images should have the same aspect ratio, and preferably the same size, e.g. 640x480.

Example of a image set

Back to top

2) Installing the software
Note that you should have the latest version of MATLAB available. This was tested and written using MATLAB version 6.5. The two files associated with the calibration procedure are calibration.zip and TOOLBOX_calib.zip.

The installation procedure follows:

• Extract TOOLBOX_calib.zip to the toolbox folder under MATLAB, e.g. C:\MATLAB6p5\toolbox.

• Add the sub-directory containing *.m files to the path. To add a directory to the path, hit File?Set Path…, click Add Folder, browse for and select the relevant directory, click Save, and finally click close

• Extract calibration.zip to the work directory, e.g. C:\MATLAB6p5\work.

• To access the toolkit, under the command prompt in Matlab, type ‘calibration’ while in the extract directory containing *.m files. This command is not case sensitive. To access the toolkit from any directory, add this directory to your path as described above.

Back to top

3) Starting a calibration procedure
Running “calibration” will produce the GUI window to the right. This will be referred to as the “root” calibration GUI for the remainder of the tutorial.

To start a new calibration procedure, click “New”. To load a previously saved procedure, click “load”.

Starting a New procedure
Clicking “New” from the Calibration menu will produce the window below from which you may choose a directory where your calibration image set is located.

The default directory is the present working directory in the MATLAB command prompt environment. This is probably the calibration directory, unless you added this directory to your path. If your images are located in a sub-directory, or in a separate directory all together, then clicking “Choose and image directory”.

This will cause a standard window to appear from where you can choose the directory:

Upon selection of a directory, the path will be displayed in Choose_Directory text section. Note that if there are no images in this directory, you cannot continue to the next step of choosing images. Also, do not choose a directory which has many images, e.g. more than 30. Rather, create an image directory that just contains the images you will likely include. This will save you time later.

Loading a previously saved procedure
To load a saved procedure, click the “Load” button from the root Calibration GUI. This will open a standard open-file window, where you can navigate through your directory structure to find the previously saved calibration procedure. This will abandon any unsaved work, and load the state previously saved. Note that if any of the images that were used previously have been moved or renamed, this will cause an error. The load file window is shown below.

Back to top

4) Choosing images
Upon choosing a directory, hitting the “Choose Images” button on the root Calibration GUI will allow you to choose the images in the directory you would like to use in calibration. The interface is shown below.

Note again that if the directory chosen in the previous step does not contain any images, you will not be allowed to move to this step. Also note that the directory you choose shouldn’t contain too many images, because choosing them will be difficult. This is because all the images in the directory will be loaded and displayed. If you have insufficient memory to load all the images, problems might arise, or if you have too many images, choosing the correct ones will be difficult because they are resized down so all images can be displayed, as can be seen below.


All the images on the left will be included in the calibration. All the images in the right will not be included. To exclude an image, effectively moving it from the left to the right, click on “Click to Exclude”, then click on the image you wish to exclude. The default is to include all images, so the excluded image group on the right starts empty. To include an excluded image, click “Click to Include”, and then click on the image in the right side to include it.

If you click on a black or blank area, nothing will happen. But, if you click on the wrong side, then you might get undesirable results. Clicking “Click to Exclude”, then clicking on an image that is already excluded, will cause the image which is at that same relative location in the include image group to be excluded. This can be reversed easily by clicking on the correct side. Following the written instructions should make this interface intuitive and straight forward.

Below is an example with 4 images excluded, while in the process of excluding another image.


Click “Done” to finish this process.

Back to top

5) Marking Corners
The target in each image must be located for calibration to work. The four external corners of the target are marked by hand, and then the internal corners are found automatically. To mark corners in your included images, click “Extract Corners” from the root Calibration GUI. The following interface will appear:

Tracking the images which have been marked is done by the text areas with the headings “Images Marked:”, “Current Image:”, and “Images NOT Marked:”

Their meaning is self-explanatory, but keep in mind that the numbers are only place holders, and do not correspond to the image names. They are simply the order in which the images were loaded into memory from the image directory. To navigate through this index to mark new images, so see past markings, the button on the bottom provide, again, self explanatory functionality, with “First”, “Previous”, “Next”, and “Last”. To stop marking corners at any time, press “Done”.

To mark the external corners of an image, press “Mark Corners”. An “external” corner is one which is on the barrier between the last complete square and the partial squares. Internal corners are the corners that are inside the rectangle made by the external corners.

Below is an image of the target, with the external and internal corners identified.


When “Mark Corners” is clicked, the message “Click the 4 external corners clockwise from top left” will appear. It is important to do this every time. Try to start from the same point in the target, and move clockwise to the next external corner. It is also important to make this accurate by trying to click what appears to be the exact location of the corner. After the forth corner is marked, an image will appear on the right with the internal and internal corners marked. Below is what it should look like:

The red crosses in the left image are the initial guesses for the image corners. For each corner, within windows marked in blue in the right image, the exact location of the corner is found using a method which finds the center of a saddle-point. The final locations of the corners are marked in the red crosses on the right image.
Note that the final location of the internal corners may be wrong because either the external corners were improperly marked, or because of distortion in the image (which is what you are trying to calibrate). In the first case, simply remark the corners by clicking “Mark Corners” again.


Precise Corner Marking
In the second case, slightly more complicated steps must be taken. You will notice that the radial distortion will affect the image which has a target edge close to the image edge. In such a case, it is important to look closely at the marked image on the right to see that the red crosses find the right location.

Below is an example where the final location for the image corners is clearly wrong:

Note how the highlighted red crosses on the right do not correspond to the target corners. This is because of the radial distortion. To properly adjust for this issue, press the ‘+’ or ‘-’ buttons next to the “Estimate distortion” field until the red crosses in the right image appear over the target corners. This will adjust the guess of radial distortion, which is initially zero. In the case of these example images, the solution comes after pressing the ‘-’ twice. Below is the result:

This process might seem difficult because the error is actually only a few pixels. This is balanced by the fact that adjusting for one image will make the same adjustment for all the images. Also, this one image can be found easily by finding the image where the edge of the target is closest to the edge of the image. When you have marked the corners for all the images, and are satisfied with the estimates for the internal corner location, it is recommended that you cycle through the images, because internal corners are recalculated with new parameters each time the image is viewed. So, for example, if you change the radial distortion estimate mid-way through the procedure, you should view the previous images to force a recalculation. When you are done marking corners, click the “Done” button.

The Advanced menu
In some cases, the Advanced menu will be needed to properly set the parameters for the calibration. To access it, click “Advanced”. Note that at times, this might cause a pop-under, rather than a pop-up. Simply navigate the task bar to find the Advanced window. The interface to the right will appear. Note that this shows the advanced parameters for the current image, and not the entire set.

“Window X” and “Window Y” are the dimensions, in pixels, of the window in the image where corners are localized with the saddle-point finder. The default settings are probably good for most cases, but might need to be adjusted if the target is very close, or very far away from the camera.

“Box Size X” and “Box Size Y” are the physical size, in millimeters, of each square in the target. This is used only in extrinsic calibration, which is calculated but not accessible with the current interface. This need not be changed from the default for intrinsic calibration.

“Square Count X” and “Square Count Y” are the number of square in the horizontal and vertical direction in the target. It is very important to set this properly because the number of internal corners is assumed to correspond to the number of squares in your target.

Radial distortion is what was estimated before when the final internal corner locations were wrong. Pressing ‘+’ or ‘-’ in the Mark_Corners GUI changed this parameter by +/- 0.05.

The “Default” button will return all the parameters to their default values. The “Set for All” button sets these parameters for all images, because each image’s advanced settings are unique, with the exception of radial distortion, which is a property of the camera and not the image. Note that you should not have different targets using in a single calibration run, so the square count should not change between images. Press “Done” to close the Advanced menu.

Back to top

6) Performing Calibration
After marking the corners of all the images you wish to include, press the “Done” button, and then the “Calibrate” button in the root calibration GUI. To proceed, you must have marked at least a few images in order to perform calibration.

The following GUI window will appear, which is very similar to the “Choose Images” interface seen before:

The image group on the left is the group of images which will be included for the calibration procedure, i.e. those that have been chosen and marked. The group on the right, empty by default, is the group of images which will be excluded from the calibration.

To calibrate, press the “Calibrate” button. This procedure takes some time, as there is a good deal of computation which is hidden from the user. When the calibration has completed, the results will be printed to the light-grey area on the bottom of the window.

Error Reduction
Also, the errors associated with each image will be projected on top of the images included in calibration on the left in a green font, and the maximum error will be in yellow. Below is an example:

To reduce the error, which is the last item listed on the light gray area, there are a number of methods.
First, you can adjust which parameters you are calibrating. This is done by clicking the “Advanced” button, where the following window will appear:

The skew is a measure of how far the horizontal and vertical axes are from being orthogonal. The radial distortion should always be estimated, but the only question is to what order. A higher order estimation will probably yield better results. As a general caveat, if the error associated with a term is on the same order of magnitude as the term being calculated, then including that term in the calculation will probably increase the error. This information is contained in the results printed in the light grey area.

A second way to reduce error is to change the window size used to find internal corners for a specific image. This is done by pressing the “+” or “-” button below the “Exclude” button, then clicking on an image in the left group. This will recalibrate entirely, so this will be a time consuming effort. Generally, you should stop when a minimum has been reached for each image. You might then notice that the error for that image is not the maximum image error, and this process will be iterative for each image which has high error.

The third method to reduce error is to include or exclude images from the calibration. The images with the greatest error are prime candidates. This is done in exactly the same manner as choosing which images in the directory to include. To exclude an image, press “Exclude”, then an image on the left to exclude. To include an image, press “Include”, then an image on the right to include.

Saving Results
When you are satisfied that you have properly calibrated the image set and reduced the error, press the “Save” button to export the results. The following window will appear:

The default names are those used by the other vision software in the package, and the format is that which that code can read. You can change the name here as desired, and change the format manually as needed after saving. The results are saved to calibration directory.

Back to top

7) Saving a Calibration procedure
At any point in calibration procedure, you can save the current state by clicking “Save” from the root calibration menu.

The following window will appear:

Edit the name or directory as needed. To change the directory, click the “Choose directory” button, where the standard folder window will appear:

After creating a name, and choosing a directory, click the “Save” button to save the state. This will take some time because the internal state of the program is quite large.

Back to top

 

Professional
{ Research }
{ I-Kbot }