Ask Your Question
2

How to obtain a correct depth map?

asked 2017-10-31 20:54:14 -0500

cv_new gravatar image

updated 2017-10-31 22:57:54 -0500

berak gravatar image

I am trying to create a depth map from stereo images, but the generated depth map is only black in color. Could you suggest what should I improve for getting a decent depth map? Thanks.

In my view, the parameters using in the constructor bpm is wrong. How to correct them?

Stereo images Stereo images.jpeg

Depth Map depthMat.jpg

#include <stdio.h>
#include <iostream>
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/gpu/gpu.hpp"

using namespace cv;
using namespace cv::gpu;


int main(int argc, char** argv)
{
    Mat img = imread("C:\\photo\\img0001.jpeg");
    cv::Rect leftROI(0, 0, img.cols/2, img.rows );
    cv::Rect rightROI(img.cols / 2, 0, img.cols/2, img.rows);

    Mat imgLeft = img(leftROI);
    Mat imgRight = img(rightROI);
    Mat depthMat;
    GpuMat disp_gpu, disp_gpu_depth, left_gpu, right_gpu, disp;
    int nD = 10, maxIter = 50;

    StereoBeliefPropagation bpm(nD, maxIter, 4, 25, 0.1f, 100, 1, CV_32F);

    left_gpu.upload(imgLeft);
    right_gpu.upload(imgRight);

    bpm(left_gpu, right_gpu, disp_gpu);

    disp_gpu.download(depthMat);
    imshow("windowDisparity", depthMat);
    imwrite("c:\\photo\\depthMat.jpg", depthMat);
    return 0;
}
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2017-11-03 19:07:49 -0500

updated 2017-11-03 19:08:54 -0500

The depthMat.jpg is not black, it shows a variety of depths for the object. It's just all the values are near 0 and only about 4% of full scale. I'd try something like:

...
disp_gpu.download(depthMat);
depthMat = depthMat * (255.0 / nD);
imshow("windowDisparity", depthMat);
...
edit flag offensive delete link more

Comments

1

Thank you. It works!!

cv_new gravatar imagecv_new ( 2017-11-05 18:59:19 -0500 )edit
Login/Signup to Answer

Question Tools

2 followers

Stats

Asked: 2017-10-31 20:54:14 -0500

Seen: 223 times

Last updated: Nov 03 '17