9
votes

I am working on Stereo vision task and I would like to get the distance between stereo vision cameras and the object. I am using Matlab with Computer Vision System Toolbox.
I have calibrated cameras with using "Camera Calibration Toolbox for Matlab" thus I have Intrinsic parameters of left and right camera and Extrinsic parameters (position of right camera wrt left camera). I have also a pair of rectified pictures and thier disparity map. For estimation of disparity I have used Matlab function disparity(). I know the baseline and the focal length of cameras but my results are still wrong.

baseline = 70 mm
focal length = 25 mm
disparity = 60 pixels
---------------------
depth = baseline * focal length / disparity = 70 * 25 / 60 = 29 mm

But I know that the distance is cca 600 mm. Is this formula right? What about the units? mm * mm / pixel != mm. And especially I would like to use Camera matrix (Intrinsic parameters) for calculation but I didn't figure out how. I would be thankful for any hint.

1

1 Answers

8
votes

Like you said, you have to convert the unit into mm. And for that you need this formulas

z = (b*F) / (d*s)

mm = (mm * mm) / (pixel * (mm/pixel)) 

Where

  • z = depth in mm
  • b = baseline in mm
  • F = focal length in mm
  • d = depth in pixel
  • s = sensor size in mm/pixel. (Normally it provide in um, so do conversion before).

EDIT

Sometime your focal is in pixel so you don't need to use the sensor size. So just use your formula :

z = b*F / d
mm = mm * pixel / pixel