Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Calculating depth with Ptr<stereosgbm>, black bar on image

I have a calibrated fisheye stereo pair that I am using to create a depth map.

I send these rectified images:

image description

image description

into the following function:

cv::Mat RGBDFunctions::ComputeDepth(cv::Mat left, cv::Mat right)
{
    bool no_downscale = false;

    int max_disp = MAX_DISPARITY;


    Mat left_for_matcher, right_for_matcher;
    Mat left_disp, right_disp;
    Mat filtered_disp;
    Mat conf_map = Mat(left.rows, left.cols, CV_8U);
    conf_map = Scalar(255);
    Rect ROI;
    Ptr<DisparityWLSFilter> wls_filter;
    double matching_time, filtering_time;


        if (!no_downscale)
        {
            max_disp *= DOWNSCALE;
            if (max_disp % 16 != 0)
                max_disp += 16 - (max_disp % 16);
            resize(left, left_for_matcher, Size(), DOWNSCALE, DOWNSCALE);
            resize(right, right_for_matcher, Size(), DOWNSCALE, DOWNSCALE);
        }
        else
        {
            left_for_matcher = left.clone();
            right_for_matcher = right.clone();
        }

        Ptr<StereoSGBM> left_matcher = StereoSGBM::create(0, max_disp, WIN_SIZE_SGBM);
        left_matcher->setP1(24 * WIN_SIZE_SGBM*WIN_SIZE_SGBM*SMOOTHING_FACTOR);
        left_matcher->setP2(96 * WIN_SIZE_SGBM*WIN_SIZE_SGBM*SMOOTHING_FACTOR);
        left_matcher->setPreFilterCap(MAX_X_GRAD);
        left_matcher->setMode(StereoSGBM::MODE_SGBM_3WAY);
        wls_filter = createDisparityWLSFilter(left_matcher);
        Ptr<StereoMatcher> right_matcher = createRightMatcher(left_matcher);

        matching_time = (double)getTickCount();
        left_matcher->compute(left_for_matcher, right_for_matcher, left_disp);
        right_matcher->compute(right_for_matcher, left_for_matcher, right_disp);
        matching_time = ((double)getTickCount() - matching_time) / getTickFrequency();


        wls_filter->setLambda(LAMBDA);
        wls_filter->setSigmaColor(SIGMA);
        filtering_time = (double)getTickCount();
        wls_filter->filter(left_disp, left, filtered_disp, right_disp);
        filtering_time = ((double)getTickCount() - filtering_time) / getTickFrequency();

        conf_map = wls_filter->getConfidenceMap();

        // Get the ROI that was used in the last filter call:
        if (!no_downscale)
        {
            // upscale raw disparity and ROI back for a proper comparison:
            resize(left_disp, left_disp, Size(), 1 / DOWNSCALE, 1 / DOWNSCALE);
            left_disp = left_disp / DOWNSCALE;
        }



    Mat raw_disp_vis;
    cv::ximgproc::getDisparityVis(left_disp, raw_disp_vis, VIS_MULT);

    Mat filtered_disp_vis;
    cv::ximgproc::getDisparityVis(filtered_disp, filtered_disp_vis, VIS_MULT);

    return filtered_disp_vis;

}

This gives me this depth map:

image description

Which looks pretty good!

Except for the black bar on the side. What might be causing this?

Also, i am now trying to create a point cloud from this depth map, and am having huge trouble getting a good result. Is there any example code to create a cloud from depth?

Thank you!