# Scaling of the disparity map of cv.stereo\_BM.create

**URL:** <https://forum.opencv.org/t/scaling-of-the-disparity-map-of-cv-stereo-bm-create/138>\
**Category:** Python\
**Tags:** calib3d, stereo\
**Created:** [December 4, 2020, 3:16pm UTC](https://forum.opencv.org/t/scaling-of-the-disparity-map-of-cv-stereo-bm-create/138 "2020-12-04T15:16:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dnns](https://avatars.discourse-cdn.com/v4/letter/d/9fc348/32.png) [@dnns](https://forum.opencv.org/u/dnns)\
**Post date:** [December 4, 2020, 3:16pm UTC](https://forum.opencv.org/t/scaling-of-the-disparity-map-of-cv-stereo-bm-create/138/1 "2020-12-04T15:16:09Z")

</div>

Dear Forum,

i followed the example of the creation of disparity maps and got strange results. While the images look good on the first look, the numeric values of the disparity of the pixels seem incorrect. In my understanding, the disparity should map the distance of a feature in image\_left to the same feature in image\_right image in pixels.

Consider this example:

```
import numpy as np
import cv2 as cv
from matplotlib import pyplot as plt

imgL = cv.imread('Tsukuba_L.png', 0)
imgR = cv.imread('Tsukuba_R.png', 0)

stereo = cv.StereoBM_create(numDisparities=16, blockSize=15)
disparity = stereo.compute(imgL, imgR)
fig, ax = plt.subplots(ncols=3, nrows=1)
ax[0].imshow(imgL)
ax[1].imshow(imgR)
ax[2].imshow(disparity)
plt.show()

```

This will lead to these images:

 ![disparitymap_scaling](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/1X/6758259ae8e29911308a6b9d7e0576ceb1449876.jpeg)  
Check the position, where the paper meets the image bound. Its around 0,115 in the left image and 0, 105 in the right image. So shouldnt the disparity image be (roughly) 10? Its 180, which appears vastly wrong.

This is important as I am trying to measure the 3d-distance based on the found disparity.

Cheers

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [December 4, 2020, 6:36pm UTC](https://forum.opencv.org/t/scaling-of-the-disparity-map-of-cv-stereo-bm-create/138/2 "2020-12-04T18:36:33Z")

</div>

the disparity map contains numbers in a fixed point format, i.e. the values are scaled. I think it’s four fractional pixels, so the factor is 16.

check if 180/16 = 11.25 is approximately the distance you expect. maybe it’s some other number of fractional bits.

the docs on that are awful, I know. here’s documentation on reproject… which states the factor-16 fixed-point format.

> **[OpenCV: Camera Calibration and 3D Reconstruction](https://docs.opencv.org/3.4/d9/d0c/group__calib3d.html#ga1bc1152bd57d63bc524204f21fde6e02)**
