How to calibrate camera using chessboard

Whether you are using a RGB or a depth camera in your setup, you will first need to calibrate it to be able to undistort the resulting image and to obtain 3D coordinates of depth values. These are the steps I follow to do this:

  • If you are using a depth camera, it should have an accompanying RGB camera. Make sure that the depth camera is setup to be registered with the RGB camera. For example, this can be done in OpenNI using setImageRegistrationMode(IMAGE_REGISTRATION_DEPTH_TO_COLOR).

  • Prepare the setup you will use for capturing RGB or depth images. The placement of the camera and the objects should not be disturbed during calibration and later during capture.

  • Print out a chessboard image to A4 paper. For example, I use this chessboard image that is available with OpenCV documentation files. Paste or fix the printed chessboard to a board or pad.

  • Hold or place this board in various orientations and positions in the view of the camera. Take one image for each position. Take at least 10 of these images.

  • Go ahead and do the capture of your experiment next. This will result in capturing a lot more images.

  • To obtain the calibration parameters, we use the camera calibration example code provided along with OpenCV. I have created a CMake project of this code here. Build the program.

  • The camera calibration program needs two XML files as input. They can be named anything you wish. I have provided samples of these files in config.xml and images.xml here.

  • config.xml holds the other details for calibration.

    • BoardSize_Width and BoardSize_Height is the number of inner corners along the width and height of the board. For a board with 10x7 squares, the number of inner corners would be 9 and 6.
    • Square_Size is the length (in mm) of the side of a square on the chessboard. You will need to measure this from the printed chessboard.
    • Input specifies the file which has the input images, which is images.xml in our case.
    • Calibrate_NrOfFrameToUse is the number of images to use from that file for calibration.
    • Write_outputFileName is the name of the output XML file from the calibration.
  • images.xml holds the paths to the chessboard calibration images we captured. Even if you intend to capture depth images for your experiment, you need the chessboard images from the RGB camera for the calibration step here.

  • Call the calibration program as:

$ ./calibrate-camera config.xml

The output will be written to output.xml. This file can be used as input in your OpenCV program to reconstruct the data from your captured images.


Tried with: OpenCV 2.4.9 and Ubuntu 14.04

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s