首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >opencv标准视差图不起作用

opencv标准视差图不起作用
EN

Stack Overflow用户
提问于 2018-02-21 23:04:02
回答 1查看 1.1K关注 0票数 0

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

我试过了:

代码语言:javascript
运行
复制
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);

它会编译,但会抛出一堆错误。不确定我是否使用了正确的抽象类?

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-02-22 00:50:43

这里我的函数起作用了。我希望它能对你有所帮助。

代码语言:javascript
运行
复制
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.
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48909124

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档