Wiki

Page

User

Note: This tutorial assumes that you have completed the previous tutorials: ROS Tutorials.

Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags.

How to Calibrate a Monocular Camera

Description: This tutorial cover using the camera_calibration's cameracalibrator.py node to calibrate a monocular camera with a raw image over ROS.

Before Starting

Make sure that you have the following:

a large checkerboard with known dimensions. This tutorial uses a 8x6 checkerboard with 108mm squares. Calibration uses the interior vertex points of the checkerboard, so an "8x6" board is nine squares wide and seven high, like the example below.

a well lit 5m x 5m area clear of obstructions and check board patterns

a monocular camera publishing images over ROS

Compiling

Start by getting the dependencies and compiling the driver.

$ rosdep install camera_calibration
$ rosmake camera_calibration

Camera Publishing

Make sure that your monocular camera is publishing images over ROS. Let's list the topics to check that the images are published:

$ rostopic list

This will show you all the topics published, check to see that there is an image_raw topic. The default topics provided by most ROS camera drivers are:

/camera/camera_info
/camera/image_raw

If you have multiple cameras or are running the driver in its own namespace, your topic names may differ.

Running the Calibration Node

To start the calibration you will need to load the image topics that will be calibrated:

This will open up the calibration window which will highlight the checkerboard:

If it does not open up the window try the following parameter:

--no-service-check

If you can't see any colored dots make sure you count the interior vertex points, not the squares!

Dual Checkerboards

New in D

Starting in Diamondback, you will be able to use multiple size checkerboards to calibrate a camera.

To use multiple checkerboards, give multiple --size and --square options for additional boards. Make sure the boards have different dimensions, so the calibration system can tell them apart.

Moving the Checkerboard

In order to get a good calibration you will need to move the checkerboard around in the camera frame such that:

checkerboard on the camera's left, right, top and bottom of field of view

X bar - left/right in field of view

Y bar - top/bottom in field of view

Size bar - toward/away and tilt from the camera

checkerboard filling the whole field of view

checkerboard tilted to the left, right, top and bottom (Skew)

At each step, hold the checkerboard still until the image is highlighted in the calibration window.

As you move the checkerboard around you will see three bars on the calibration sidebar increase in length. When the CALIBRATE button lights, you have enough data for calibration and can click CALIBRATE to see the results.

Calibration can take about a minute. The windows might be greyed out but just wait, it is working.

Calibration Results

After the calibration is complete you will see the calibration results in the terminal and the calibrated image in the calibration window:

A successful calibration will result in real-world straight edges appearing straight in the corrected image.

A failed calibration usually results in blank or unrecognizable images, or images that do not preserve straight edges.

After a successful calibration, you can use the slider at the top of the calibration window to change the size of the rectified image. A scale of 0.0 means that the image is sized so that all pixels in the rectified image are valid. The rectified image has no border, but some pixels from the original image are discarded. A scale of 1.0 means that all pixels in the original image are visible, but the rectified image has black borders where there are no input pixels in the original image.

If you are satisfied with the calibration, click COMMIT to send the calibration parameters to the camera for permanent storage. The GUI exits and you should see "writing calibration data to ..." in the console.

Creating a yml file

The Camera Calibration Parser helps you to create a yml file, which you can load with nearly all ros camera driver using the camera_info_url parameter.

Rectifying an image

Simply loading a calibration file does not rectify the image. For rectification, use the image_proc package.