Scaling of the disparity map of cv.stereo_BM.create

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)

This will lead to these images:

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.


1 Like

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.