• opencv wlsfilter depth refinement demo


    参考

    https://docs.opencv.org/3.2.0/d3/d14/tutorial_ximgproc_disparity_filtering.html

    // This file is part of OpenCV project.
    // It is subject to the license terms in the LICENSE file found in the top-level directory
    // of this distribution and at http://opencv.org/license.html.
    #include "test_precomp.hpp"
    #include "opencv2/ximgproc/disparity_filter.hpp"
    #include <string>
    //CV_TEST_MAIN("")
    using namespace cv;
    using namespace std;
    using namespace ximgproc;
    
    int main()
    {
        string left_im = "C:\Users\Administrator\Desktop\green_tree\left.bmp";
        string right_im = "C:\Users\Administrator\Desktop\green_tree\right.bmp";
        Mat left = imread(left_im, IMREAD_COLOR);
        if (left.empty())
        {
            cout << "Cannot read image file: " << left_im;
            return -1;
        }
        Mat right = imread(right_im, IMREAD_COLOR);
        if (right.empty())
        {
            cout << "Cannot read image file: " << right_im;
            return -1;
        }
    
        int max_disp = 16;
        max_disp /= 2;
        if (max_disp % 16 != 0)
            max_disp += 16 - (max_disp % 16);
        Mat left_for_matcher, right_for_matcher;
        resize(left, left_for_matcher, Size(), 1.0, 1.0);
        resize(right, right_for_matcher, Size(), 1.0, 1.0);
    
        int wsize = 5;
        Ptr<StereoBM> left_matcher = StereoBM::create(max_disp, wsize);
    
        Ptr<DisparityWLSFilter> wls_filter;
        wls_filter = createDisparityWLSFilter(left_matcher);
    
        Ptr<StereoMatcher> right_matcher = createRightMatcher(left_matcher);
        cvtColor(left_for_matcher, left_for_matcher, COLOR_BGR2GRAY);
        cvtColor(right_for_matcher, right_for_matcher, COLOR_BGR2GRAY);
        double matching_time = (double)getTickCount();
        Mat left_disp, right_disp, filtered_disp;
        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();
    
    
        double lambda = 8000.0;
        double sigma = 0.5;
        wls_filter->setLambda(lambda);
        wls_filter->setSigmaColor(sigma);
        double filtering_time = (double)getTickCount();
        wls_filter->filter(left_disp, left, filtered_disp, right_disp);
        filtering_time = ((double)getTickCount() - filtering_time) / getTickFrequency();
    
        Mat raw_disp_vis;
        double vis_mult = 10.0;
        getDisparityVis(left_disp, raw_disp_vis, vis_mult);
        namedWindow("raw disparity", WINDOW_AUTOSIZE);
        imshow("raw disparity", raw_disp_vis);
        Mat filtered_disp_vis;
        getDisparityVis(filtered_disp, filtered_disp_vis, vis_mult);
        namedWindow("filtered disparity", WINDOW_AUTOSIZE);
        imshow("filtered disparity", filtered_disp_vis);
        waitKey();
    
    
        return 0;
    }

  • 相关阅读:
    H5及微信中唤起app的解决方案
    html5统计数据上报API:SendBeacon
    基于webpack4的react开发环境配置
    electron-vue开发爬坑指南
    利用git 进行多人协作开发
    js 性能优化利器:prepack
    各种渲染方式对比解析
    Nuxt.js部署应用的方式
    微信小程序--data的赋值与取值
    甘超波:什么是个人定位
  • 原文地址:https://www.cnblogs.com/adong7639/p/10600148.html
Copyright © 2020-2023  润新知