2
votes

I'm trying to calculate a disparity map using openCV3 in python but the result is not satisfactory. I made sure that the calibration and rectification are done correctly:

rectification result

I tried disparity function in Matlab using these rectified images and results were quite good. However, the opencv output looks like a Van Gogh paitning:

disparity map.

Here is the python code related to disparity:

block_matcher = cv2.StereoBM_create(numDisparities=16, blockSize=15)
disp = block_matcher.compute(rectified_l, rectified_r)

Interestingly, a range of disparity is [-16,240], however, I expect it to be in [0,16] since I set numDisparities to 16. Am I misunderstanding the concept of numDisparities? I tried varying the numDisparities and blockSize but didn't get any meaningful improvement.

Let me know if you have ideas on what is going on.

1

1 Answers

1
votes

I figured out what was going on and why Matlab was performing so much better. The disparity map in my original post was obtained by using StereoBM method of openCV, while Matlab uses StereoSGBM. After I switched to StereoSGBM the results look much better and identical to what I get from Matlab.