我希望你能帮助我找出为什么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);
答案 0 :(得分:0)
Mat displayMat;
double minVal, maxVal;
minMaxLoc(disp, &minVal, &maxVal);
disp = 255.*(disp - minVal)/(maxVal - minVal);
disp.convertTo(displayMat, CV_8U);
imshow("disparity", displayMat)