4

I'm trying to compute disparity map in C++ using OpenCV 3.1. I use StereoSGBM algorithm and I need to be able to recognize far and very close objects. Thus I set MinDisparity to -16 and MaxDisparity 160.

Camera is now correctly calibrated but the resulted disparity map is cut from left. The amount of the cut depends on the MaxDisparity settings.

I would understand why this happens for close objects. Simply because pixels on one image are not available on the second image. But this does not happen with farther objects. In such case, the object is fully visible in both camera images, but it is not visible in the resulted disparity map.

Look at this picture. Why my hand is not visible on the result? enter image description here

Is there any solution for this problem? To compute disparity map for all visible area in case of high MaxDisparity settings?

bigmuscle
  • 419
  • 1
  • 6
  • 16

1 Answers1

2

The problem you are facing is the number of disparities in your result picture. SGBM searches the whole disparity space and trys to find the best match in the other picture.

A pixel of the right image is taken and compared to every pixel within the disparity range from the left image. If the left image is too small, the disparity is invalid. Therefore the 176 most left pixels in the left image are discarded.

Try to reduce the maximum disparity and/or increase the minimum disparity!

Trevir
  • 1,253
  • 9
  • 16
  • But it makes no sense to me. If I increase the minimum disparity, I will lose the far objects, if I reduce the maximum disparity, I will lose close objects. Since my hand is still visible in both images, why it just does not find its match correctly? ... My other idea is to compute two spearate disparities maps, e.g. 0-48 and 48-96 and then combine them somehow (but I'm not sure how), but I don't see it as 100% solution. – bigmuscle Oct 14 '16 at 11:26
  • I tried an experiment. I modified OpenCV's StereoSGBM code to start minX1 always from zero and not from maxDisparity value and the result is that it works correctly - my hand is visible in disparity map, its distance is correctly detected and there seems to be no problem. – bigmuscle Oct 18 '16 at 08:12
  • It may seem to work correctly. However your gonna run in a huge pile of problems as soon as the image contains recurring structures! – Trevir Oct 18 '16 at 10:25
  • I understand, however, the problems with recurring structures can appear in stereo matching regardless my change. And I just need disparity map for the whole field of view. – bigmuscle Oct 19 '16 at 12:59
  • @bigmuscle: Yes, it can always happen. But be aware that with your approach the problem gets worse! – Trevir Oct 19 '16 at 14:34
  • Yes, but is there some better way to correctly compute disparity map for the **whole visible** area (including far objects and very close objects) = recognize even my hand in the upper picture ? – bigmuscle Oct 20 '16 at 09:31