2

I try to generate disparity of stereo image by using OpenCV and optimize performance by using GPU but the results of them are different.

StereoSGBM initialize

StereoSGBM sbm;
sbm.SADWindowSize = 3;
sbm.numberOfDisparities = 144;
sbm.preFilterCap = 63;
sbm.minDisparity = -39;
sbm.uniquenessRatio = 10;
sbm.speckleWindowSize = 100;
sbm.speckleRange = 32;
sbm.disp12MaxDiff = 1;
sbm.fullDP = false;
sbm.P1 = 216;
sbm.P2 = 864;
sbm(grayLeftCurrentFrameCPU, grayRightCurrentFrameCPU, resultCurrentFrameCPU);
normalize(resultCurrentFrameCPU, resultNorCurrentFrameCPU, 0, 255, CV_MINMAX, CV_8U);

Result: https://i.stack.imgur.com/eov4N.jpg

gpu::StereoBM_GPU initialize

gpu::StereoBM_GPU *bm = new gpu::StereoBM_GPU();
bm->preset = gpu::StereoBM_GPU::BASIC_PRESET;
bm->ndisp = 48;
bm->winSize = 5;
bm->operator()(grayLeftCurrentFrameGPU, grayRightCurrentFrameGPU,       resultCurrentFrameGPU);
gpu::normalize(resultCurrentFrameGPU, resultNorCurrentFrameGPU, 0, 255, CV_MINMAX, CV_8U);

Result: https://i.stack.imgur.com/WVzrK.jpg

Does anyone know why?

StuperUser
  • 10,555
  • 13
  • 78
  • 137
thanhit08
  • 23
  • 1
  • 3

1 Answers1

2

gpu::StereoBM_GPU is the GPU version of cv::StereoBM (documentation link).

cv::StereoSGBM uses another algorithm (documentation link), hence the different results.

In order to determine why the result of gpu::StereoBM_GPU is wrong, it would be useful to know how you rectified your pair of images.

BConic
  • 8,750
  • 2
  • 29
  • 55
  • That means before I use `gpu::StereoBM_GPU` I must rectify my pair of images and so I can get the same result as `cv::StereoSGBM'. That is what you mean? – thanhit08 Mar 04 '14 at 07:03
  • Rectification of the pair of input images is necessary before using _any_ stereo matching technique, including both `gpu::StereoBM_GPU` and `cv::StereoSGBM`. However, you seem to obtain a decent result with `cv::StereoSGBM`, therefore your images must already be rectified. Still, image rectification can be done in several ways, and `gpu::StereoBM_GPU` requires a certain form of rectification (where disparity is in the range `[0,256]`), which can explain the poor results. – BConic Mar 04 '14 at 08:43