使用opencv CUDA& amp; BM

时间:2014-02-23 00:48:04

标签: c++ opencv

我希望你能帮助我找出为什么CUDA BM会给我奇怪的结果。我只是想生成两个校正图像的视差图。但结果如下:

这是一段代码:

Mat img1, img2;
img1 = imread("img1.jpg", IMREAD_GRAYSCALE);
img2 = imread("img2.jpg", IMREAD_GRAYSCALE);
cuda::GpuMat d_left, d_right;
Ptr<cuda::StereoBM> bm;
bm = cuda::createStereoBM(64, 5);
Mat disp(img1.size(), CV_8U);
cuda::GpuMat d_disp(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, 64);
d_disp.download(disp);
resize(disp, disp, Size(0,0), 0.3, 0.3, 1);
imshow("disparity", disp);
waitKey(0);

1 个答案:

答案 0 :(得分:0)

据我所知,这是显示和图像深度的问题(无符号short,float等) 下载后将其标准化显示在0到1之间,然后乘以255并转换为uint8

Mat displayMat;
double minVal, maxVal;
minMaxLoc(disp, &minVal, &maxVal);
disp = 255.*(disp - minVal)/(maxVal - minVal);
disp.convertTo(displayMat, CV_8U);
imshow("disparity", displayMat)