A calibration of the cameras is very important if you want to make full use of the stereo cameras. A well executed camera calibration can produce an accurate disparity image that brings depth information to the image and enable us to work with stereo processing. The disparity image is then used by some other applications, such as the qbo_stereo_selector node that detects close objects. Therefore, a badly executed calibration of the cameras can produce a malfunctioning of many nodes that Q.bo uses.
The qbo_camera package contains the stereo_calibration node that you can use to calibrate your cameras. This tutorial will show you how to correctly calibrate your cameras using this node and how to check the quality of your disparity image.
The calibration pattern needed for this calibration is a 7×9 checkerboard in which the length of every square is 2,84cm (1.12''). This calibration pattern comes with the Q.bo robot. You can also download it here.
For for a correct camera calibration, you must have proper light conditions in the room. Make sure that both cameras are not pointing directly to a light source (window, lamp, a bright reflection) and that the room has sufficient light.
This is more a suggestion than a requisite. Placing a Q.bo on top of a table puts it's cameras at the level of your shoulders if you are seated on a chair. This makes the procedure more comfortable, since you can easily show him the calibration pattern and at the same time press the keyboard that you will have on top of the table.
You must execute the stereo_calibration node from within the robot. For that you will need to connect Q.bo as a desktop, by plugging a monitor, keyboard and a mouse.
There are two ways of launching the stereo calibration node:
- Access the Q.bo Webi from within the robot and log in. The open the “Config Wizard” tab and click on the “Launch Stereo Camera Calibration” button.
- Open a terminal and execute:
roslaunch qbo_camera qbo_cameras_stereo_calibration.launch
The stereo_calibration node executes 3 stages of calibration:
- Calibration of the left camera
- Calibration of the right camera
- Calibration of the stereo
For each stage, this node will require 9 images to be captured. So, 27 images will have to be captured in total, in the process of calibration. To capture an image, you can press any key on the keyboard (for example, the 'n' key).
After launching the stereo_calibration node, it will firstly execute the calibration of the left camera. For that, 9 images are needed to be captured.
You will immediately see two Display Windows on the top. On the left Display Window you will see the image of the camera to be calibrated (in this case, the left camera's image). The right Display Window will show the detected corners of the calibration pattern after an image capture. Make sure that the image you see on the left Display Window correspond to the correct camera.
Before capturing an image (by pressing any key on the keyboard), make sure that the calibration pattern is well visible. For good result, there are 3 great tips that you need to follow:
- Show the calibration pattern in the portrait orientation.
- Try to position the calibration pattern as close as possible to the camera without hiding any interior corner.
- Try changing the inclination and position of the calibration pattern as much as possible, i.e., avoid capturing two identical images.
If any of the interior corners of the calibration pattern is not visible in the image, the stereo_calibration will make you repeat the capture.
Good positioning of the calibration pattern:
Bad positioning of the calibration pattern:
After a successful capture of 9 images, the calibration_node will show you the result of the undistorted image on the left Display Window:
The undistorted image must eliminate the radial distortions of the original image. To verify this, you must see, in the undistorted image, only straight lines in the calibration pattern, while in the original image (raw image), the straight lines must present a soft bending due to the image distortion.
To continue to the next stage - calibration of the right camera - press “Enter” or press “r” to repeat the left calibration process.
The steps to calibrate the right camera are identical to the calibration of the left camera. Just make sure the image you see on the left Display Window corresponds to the right camera image. You can then proceed with its calibration, by correctly showing the calibration pattern and capturing the image pressing any key on the keyboard. After 9 successful captures, the node will show you the resultant undistorted image. You can click “Enter” to continue to the stereo calibration or “r” to repeat the right camera calibration process.
Stereo calibration implies capturing simultaneous images of both left and right cameras. So you have to be extra careful while showing the calibration pattern to make sure all inner corners are visible in both images at the same time. For that, it may be necessary to slightly move away the calibration pattern from the cameras. In this stage, four Display Windows will appear: 2 for the cameras' images and 2 for the camera's corner detections. Once again, press any key to capture. After 9 successful capture, you should see the result rectified images in the top Display Windows.
If you want to submit the calibration, i.e., make it permanent even if you reboot the robot, just press “Enter” when the rectified images are being shown. If you want to repeat your calibration, press 'r', and you will repeat the last calibration stage (stereo calibration). You can abort the calibration at any time by pressing Ctrl+C.
The best way to check the calibration you just made is to view the disparity image. For that, execute in the console:
rosrun image_view disparity_view image:=/stereo/disparity
You will immediately see the disparity image. In this viewer of the disparity image, hotter colors (red, yellow, etc.) correspond to closer points, while colder colors (violet, blue, etc.) correspond to farther points. The grey points correspond to points where the stereo could not compute their depths. You will always have grey points in the disparity image (specially on one side of the image and on the upper and lower parts), but the golden rule is: The lesser grey points you have, the better is the quality of the disparity image.
Here is an example of a good disparity image (left image) and bad disparity image (right image):