简体   繁体   English

OpenCV标准视差图不起作用

[英]opencv standard disparity map not working

I can't seem to get any sort of depth image using the standard opencv function (stereoBM). 我似乎无法使用标准的opencv函数(stereoBM)获得任何深度图像。

I tried: 我试过了:

Mat disp, disp8;

StereoBM *sbm = StereoBM::create(16, 2);
sbm->setDisp12MaxDiff(1);
sbm->setSpeckleRange(8);
sbm->setSpeckleWindowSize(0);
sbm->setUniquenessRatio(0);
sbm->setTextureThreshold(507);
sbm->setMinDisparity(-39);
sbm->setPreFilterCap(61);
sbm->setPreFilterSize(5);
sbm->compute(imgLeft, imgRight, disp);
normalize(disp, disp8, 0, 255, CV_MINMAX, CV_8U);

cv::imshow("disp", disp8);

which compiles but chucks a load of errors. 可以编译,但会产生大量错误。 Not sure if I am using the abstract class right? 不确定我是否使用抽象类对吗?

Thanks 谢谢

Here my function working. 我的功能在这里工作。 I hope it helps you. 希望对您有帮助。

cv::Mat Arritmic::DepthMap(cv::Mat &imageL, cv::Mat &imageR)
{

    /// DISPARITY MAP AND DEPTH MAP
    cv::Mat left_for_matcher, right_for_matcher;
    cv::Mat left_disp,right_disp;
    cv::Mat filtered_disp;
    cv::Mat conf_map =  cv::Mat(imageL.rows, imageL.cols, CV_8U);
    conf_map =  cv::Scalar(255);
    cv::Rect ROI;
    int max_disp = 16; // n*16
    int wsize = 15;




   // Perform matching and create the filter instance
   /* I am using StereoBM for faster processing. If speed is not critical, 
   though, StereoSGBM would provide better quality.
   The filter instance is created by providing the StereoMatcher instance
   that we intend to use. Another matcher instance is returned by the
   createRightMatcher function. These two matcher instances are then used
   to compute disparity maps both for the left and right views, that are
   required by the filter. */

    cv::Ptr<cv::ximgproc::DisparityWLSFilter> wls_filter;

    cv::Ptr<cv::StereoBM >left_matcher = cv::StereoBM::create(max_disp,wsize);
    wls_filter = cv::ximgproc::createDisparityWLSFilter(left_matcher);
    cv::Ptr<cv::StereoMatcher> right_matcher = cv::ximgproc::createRightMatcher(left_matcher);
    cv::cvtColor(imageL,  left_for_matcher,  cv::COLOR_BGR2GRAY);
    cv::cvtColor(imageR, right_for_matcher, cv::COLOR_BGR2GRAY);


    left_matcher-> compute(left_for_matcher, right_for_matcher,left_disp);
    right_matcher->compute(right_for_matcher,left_for_matcher, right_disp);

    // Perform filtering
    /* Disparity maps computed by the respective matcher instances, as
    well as the source left view are passed to the filter. Note that we
    are using the original non-downscaled view to guide the filtering 
    process. 
    The disparity map is automatically upscaled in an edge-aware fashion
    to match the original view resolution. The result is stored in
    filtered_disp. */


    double lambda = 6000.0;   // hardcode
    double sigma = 2.0;       // hardcode

    //! [filtering]
    wls_filter->setLambda(lambda);
    wls_filter->setSigmaColor(sigma);

    wls_filter->filter(left_disp, imageL, filtered_disp, right_disp);

    //! [filtering]
    conf_map = wls_filter->getConfidenceMap();

    // Get the ROI that was used in the last filter call:
    ROI = wls_filter->getROI();

      cv::Mat raw_disp_vis;
    cv::ximgproc::getDisparityVis(left_disp,raw_disp_vis, 21.0);
    cv::Mat filtered_disp_vis;
    cv::ximgproc::getDisparityVis(filtered_disp,filtered_disp_vis, 15.0);


    return raw_disp_vis;  // rerturning de depth map image.
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM