I have successfuly created a satisfying disparity map using cv::stereoSGBM class in OpenCV 2.4.5, with 256 different disparity levels. I have divided all the disparity values by 16, as indicated in the documentation, but this final map can't possibly contain the "true" disparities: if I add to a (x, y) pixel's horizontal dimension its computed disparity (x + d), the resulting coordinates (x + d, y) in the other image correspond to a completely different pixel.
I guess the problem stems from the fact that I parameterized stereoSGBM initially for 256 disparity levels, but the actual maximum disparity (in pixels) is way smaller. Since I don't really know the actual maximum disparity, I can't just normalize accordingly the values computed by stereoSGBM.
I need the actual disparity values to compute dense stereo correspondences (necessary for triangulation and 3D reconstruction).