# Disparity calculations and camera centers

**URL:** <https://forum.opencv.org/t/disparity-calculations-and-camera-centers/2881>\
**Category:** C++\
**Tags:** disparity\
**Created:** [April 20, 2021, 9:26pm UTC](https://forum.opencv.org/t/disparity-calculations-and-camera-centers/2881 "2021-04-20T21:26:38Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![lpea](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/lpea/32/1974_2.png) [@lpea](https://forum.opencv.org/u/lpea)\
**Post date:** [May 5, 2021, 7:17pm UTC](https://forum.opencv.org/t/disparity-calculations-and-camera-centers/2881/4 "2021-05-05T19:17:45Z")

</div>

@DoDoM Since you have calibrated your cameras, you should use the focal length given by the stereo calibration function.

Edit: as you mentioned in another thread, `stereoCalibrate` gives you a value of f\_x in pixels and not in millimeters. But it turns out that this is exactly what you need to compute Z. If you look at the formula mentioned in my previous comment:

- the baseline B is expressed in metric units
- the disparity (x - c\_x) - (x' - c'\_x) is in pixels (since x is the pixel coordinate of the point and c\_x the coordinate of the principal point).

Therefore, f has to be expressed in pixels for the formula to be consistent. You actually don’t need to know the size of a pixel or the focal length in metric units, but only the ratio between these two quantities (i.e. the focal length _in pixels_).

---

_[View the full topic](https://forum.opencv.org/t/disparity-calculations-and-camera-centers/2881)._
