Konda.eu

Building OpenCV Stereo Vision - Calibration

No comments

Building OpenCV Stereo Vision - Calibration

Once the hardware is set up, entire rig must be calibrated. Cheap cameras have a lot of distortion. Two major distortions are radial and tangential. Radial is usually noticed on the edge of the screen where image is slightly curved. Edges that should be perfectly straight are suddenly slightly bended. With tangential distortion the problem is somewhat similar, only that certain points on the image appear closer than their neighbors, even though they are not.

In order to overcome this problems cameras must be calibrated. Therefore, a series of images is taken with a well know pattern. OpenCV uses chessboard as shown below.

chessboard

I recommend taking as much images as possible under different angles, position and distance from cameras. Make sure pattern is always fully visible on both of the cameras. For capturing images I made a quick helper program available here on Github.

When calibrating I didn't want to wrap OpenCV function in my own program as OpenCV already provides one. It can be found in bin folder as stereo_calib.exe or under samples/cpp/stereo_calib.cpp in Github repository. When all images were captured, I generated the following XML file:

<?xml version="1.0"?>
<opencv_storage>
<imagelist>
"../data/0000L.png"
"../data/0000R.png"
"../data/0001L.png"
"../data/0001R.png"
...
</imagelist>
</opencv_storage>

Calibration program searches for chessboard on every image and calculates distortion and projection matrices for each camera. If chessboard isn't found on both images, entire pair is skipped. Below are marked points that are used for calculation.

chessboard_full

When calibration is done, two files are outputted. The first is intrinsics.yml, where camera matrix is written and the seconds one is extrinsics.yml, where rotation and translation are specified. Both are needed to create a depth map.

When calibration finished, it outputs and RMS error. I got an RMS of 0.3 which is pretty good for VGA cameras, but it could be better. If RMS is anything above 0.5, I'd advise that you repeat the process.

Cameras should now be calibrated! Now don't go near the cameras and don't even breath near them. Every movement will cause errors when calculating depth maps therefore the entire calibration process needs to be repeated.

Leave a Reply

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.