【问题标题】:opencv standard disparity map not workingopencv标准视差图不起作用
【发布时间】:2018-08-01 05:22:20
【问题描述】:

我似乎无法使用标准的 opencv 函数 (stereoBM) 获得任何类型的深度图像。

我试过了:

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

它可以编译但会处理大量错误。不确定我是否使用了抽象类?

谢谢

【问题讨论】:

  • 你到底遇到了什么错误?

标签: c++ opencv runtime-error disparity-mapping


【解决方案1】:

我的功能在这里工作。希望对你有帮助。

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

【讨论】:

  • 那么到底是什么问题以及您是如何解决的?
  • 您好 @AndreasUnterweger 我只发布了我拥有的一个代码的一部分,用于从 2 个图像(LR)计算视差图,以防万一,它可以帮助发布初始问题的人.
  • 对不起,我以为你问的是原始问题。您能否为您的代码添加一些额外的解释?
  • @AndreasUnterweger 抱歉耽搁了。忙碌的周末。我将在基于 OpenCV doc 的代码中添加一些 cmets。
猜你喜欢
  • 2015-03-29
  • 2015-10-31
  • 2013-12-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-11-05
  • 2015-06-09
  • 2011-05-27
相关资源
最近更新 更多