Consists of two USB Web Cameras connected one next to another:




Source code available here:



- OpenCV Library (* At the time of this article I was using  Version 1.1pre1, October, 2008)


Once you have instaleld the libraries and downloaded the code open in QT Creator.

Update the paths to where your OpenCV library is installed (replace every occurrence of  C:\SDK\OpenCV\  to the path where you installed OpenCV).

It is assumed that you have 2 USB cameras connected to your PC and there are no other cameras connected to computer. If this is not the case then you might want to have a look at  StereoCamera::setup()  in stereocamera.cpp.

It is assumed your cameras can capture 640×480 images.

If you don't have the cameras yet, but would like to test the sofware using the included images sets (see /images/ folder). Open mainwindow.cpp and comment out  timer.start(50); while uncommenting one of the 2 lines:

  //stereoVisionTest("../images/set1/",7,4);  //run test1
  //stereoVisionTest("../images/set2/",9,6);  //run test2

If you get any compiler errors make sure your Qt and OpenCV libraries are installed correctly. For that matter try to create a new test QT project and make sure it compiles.



Before your cameras can see in 3D you need to perform a calibration sequence.

- print out the following PDF : ChessBoard – Stereo Calibration.pdf and tape it to a solid piece of wood, plastic or fiber glass (make sure the image is not bent or calibration will not work).

- focus your cameras so that the text on the chessboard is readable, make sure you don't modify the focus of cameras after calibration or during calibration since the focus is an important factor in calibration .

- start calibration by clicking on Start Calibration button in software, place the chessboard in front of the cameras so that it is completely visible in both cameras.

-software will take samples every 5 seconds , until the specified number of samples has been taken (10 by default).

-once calibration is complete click "Save Calibration" to save calibration data to a file (calibration will be reloaded next time you start the program automatically).

-if you modify position or focus of cameras you will need to calibrate.

-pay attention to 'rectified' image , if a line intersects an object or a spot on the left image it should intersect same object or spot on the right image. This is an indicator that your calibration is correct.

-if you have valid calibration data you should see the normalized depth image in the "Depth" window


Updated code to work with  OpenCV-2.0.0a-win32.exe   (will no longer work with older versions, unless you modify the .pro file, to include ther proper libraries and include paths).