Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to obtain a correct depth map?

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;
}
click to hide/show revision 2
retagged

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

berak gravatar image

How to obtain a correct depth map?

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;
}