I find a huge difference between the outputs of the CPU and GPU versions of StereoBM. I have compiled a GPU version of OpenCV 3.2 on my machine. I am attaching the outputs of both CPU and GPU, along with the GPU code.
StereoBM GPU
StereoBM CPU
Here is the code:
#include "opencv2/opencv.hpp"
#include "opencv2/core.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/cudaarithm.hpp"
#include <iostream>
#include <stdio.h>
#include <limits.h>
using namespace cv;
int main()
{
cv::Mat img1, img2;
img1 = imread( "~/left.png", cv::IMREAD_GRAYSCALE);
img2 = imread( "~/right.png", cv::IMREAD_GRAYSCALE);
cuda::GpuMat d_left, d_right;
Ptr<cuda::StereoBM> bm;
bm = cuda::createStereoBM(64, 11); //numDisparities=64, windowSize=11
Mat disp(img1.size(), CV_8U);
cuda::GpuMat d_disp(img1.size(), CV_8U);
cuda::GpuMat d_disp_color(img1.size(), CV_8U);
d_left.upload(img1);
d_right.upload(img2);
bm->compute(d_right, d_left, d_disp);
cuda::drawColorDisp(d_disp, d_disp_color, 64);
d_disp.download(disp);
imwrite("~/disparity.png", disp);
d_disp_color.download(disp);
imwrite("~/disparity_color.png", disp);
return 0;
}
The Output of StereoBM CPU is obtained with the same parameters as StereoBM GPU. In addition to that, StereoBM CPU has following parameters:
preFilterSize = 9, preFilterCap = 31, wsize = 11, numDisparities = 64, minDisparity = 0, uniquenessRatio = 0, textureThreshold = 0, speckleWindowSize = 400, speckleRange = 4, disp12MaxDiff = 0.