The two cameras are aligned horizontally, and the distance between them is 20 cm. I want to calculate the distance D between the cameras and an Object.
I tried but I couldn't, there are some papers talking about that such as http://www.warse.org/pdfs/2013/icctesp02.pdf. However, when I applied the technique , I got wrong results
The formula is as following
D = (b * f) / (x2 - x1)
or
D = (b * x0) / (2 * tan(theta/2) * (x2 - x1))
Where:
b = distance between the two cameras in cm
f = focal length of the camera's lens in mm
x2 - x1 = the disparity of a particular object between left image and right image
x0 = image width in pixels
theta = camera view angle in degrees
The problem that when I applied these formulas, I got wrong result of D, I think the problem is in the disparity between left image and right image.
My parameters are as following
b = 20 cm
f = 35 mm
x2 - x1 = 189 pixels
x0 = 3264 pixel
theta = 54.4 degrees
But I got wrong results for distance D, and I think the problem is in the disparity xl=xr
How did you estimate the focal length of your cameras? Even if the two cameras are the same type, there might be slight differences between them. Additionally, one of the cameras might be rotated just a little bit which might influence your results. Doing a stereo calibration and triangulate using the parameters from the stereo calibration should do the trick. See e.g. the documentation of the Bouguet Matlab toolbox for camera calibration for a clear example how to do stereo calibration at http://www.vision.caltech.edu/bouguetj/calib_doc/htmls/example5.html.
Before trying to use any library implementation or built function to solve the problem, You need to understand what principles are at operation.
You want to take first a look to the pin-hole camera model, a basic mathematical model explaining how a point in the 3D world is projected into a 2D Image trough a camera system.
Then you want to look into the principles of epipolar geometry. This is where the basic model of stereo vision comes from and explains the geometric relation between a 3D point and its projection in the image when you are using two pin-hole cameras to view the scene from two distinct positions.
As far as I remember in this paper http://www.pnas.org/content/106/52/22341, the authors used calibrated visual fields. See Size-Specific Predation in methods. Is not exactily de same because they used it to estimate the size of certain individuals entering into the visual field of their cameras but maybe can helps. I think that contact with Scott Ling, the main author of this paper could be really helpfull.