干货!双目相机实测orbslam2 小白一小时可跑通 一篇把orbslam门槛降低到高中毕业的文章

Keywords

双目相机 orbslam2 orbslam orb_slam2 双目广角相机 双目广角相机参数 orbslam用相机跑 双目相机slam 立体相机slam stereo camera slam
orbslam配置 orbslam参数 orb_slam2参数

为什么写这篇文章?
纯slam小白跑用自己的双目也可以轻轻松松跑起来! 大多数博文要么是针对小觅相机等高级货的,还不甚明了,要么压根就就是跑数据集的,或者压根就跑不通的,误导后来者。
十里桃园写下此博文,愿景是会操作电脑就会跑orbslam2。

本文内容有什么?
接十里桃园的上篇博文《双目相机标定和orbslam2双目参数详解》,让一个小白用很烂的相机也可以跑起来orbslam2双目。

跑的时侯啥环境啊?
非ROS系统 纯linux的ORBSLAM2,对了,就那个github上下载下来./build.sh就能编译通过的那个,地址点击 https://github.com/raulmur/ORB_SLAM2

代码在哪????给的代码咋用?
代码在文章最后,将给的代码覆盖掉源码中( https://github.com/raulmur/ORB_SLAM2 ) stereo_euroc.cc文件中的内容,保存后重新用./build.sh命令编译。

要用小觅相机吗?
话不多说,看我艰苦的环境!还小觅,自己粘了俩相机就可以突突突的跑。
干货!双目相机实测orbslam2 小白一小时可跑通 一篇把orbslam门槛降低到高中毕业的文章_第1张图片

咋运行啊?看图:
替换之后,按官网给的步骤编译robslam2.编译完成之后敲下面的命令,十里桃园用的是linux系统,windows没测想来也差不多把,没有用ros系统:
./Examples/Stereo/stereo_euroc Vocabulary/ORBvoc.txt Examples/Stereo/newbot.yaml
干货!双目相机实测orbslam2 小白一小时可跑通 一篇把orbslam门槛降低到高中毕业的文章_第2张图片

敲啥敲啊,我是小白敲上面的命令报错咋整啊?newbot.yaml是个啥?
参考十里的上篇博文《双目相机标定和orbslam2双目参数详解》你改好的配置文件命名为newbot.yaml,放到Examples/Stereo/ 文件夹下面

运行后啥结果啊?
运行后有十里桃园的专属计数器,觉得烦可以进代码去掉shilitaoyuan。正常运行一直刷帧数就对了
干货!双目相机实测orbslam2 小白一小时可跑通 一篇把orbslam门槛降低到高中毕业的文章_第3张图片

经典orbslam结果 必须要上的:
干货!双目相机实测orbslam2 小白一小时可跑通 一篇把orbslam门槛降低到高中毕业的文章_第4张图片
跑起来啥效果啊?
参数正确的话,这个还是蛮稳定的可以突突突的跑(笔记本设置电源选项,最大性能不然不接电源会卡,orbslam会计算的很慢)。
绕桌子一圈回个环,十里桃园在转弯的时侯一路小跑,没丢,赞:
干货!双目相机实测orbslam2 小白一小时可跑通 一篇把orbslam门槛降低到高中毕业的文章_第5张图片

说了这么多,代码在哪啊?
在下面,换掉源码中的stereo_euroc.cc文件中的内容,保存,重新编译即可,记得调下代码中读相机的函数调成你自己的,这个我也想帮你都调好了,但是每个人的相机总有那么一点差异不是:

/**
* This file is part of ORB-SLAM2.
*
* Copyright (C) 2014-2016 Raúl Mur-Artal  (University of Zaragoza)
* For more information see 
*
* ORB-SLAM2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ORB-SLAM2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ORB-SLAM2. If not, see .
*/


#include
#include
#include
#include
#include

#include

#include
using namespace std::chrono;
using namespace std;



int main(int argc, char **argv)
{


    // Retrieve paths to images
    vector vstrImageLeft;
    vector vstrImageRight;
    vector vTimeStamp;
    //LoadImages(string(argv[3]), string(argv[4]), string(argv[5]), vstrImageLeft, vstrImageRight, vTimeStamp);

    //if(vstrImageLeft.empty() || vstrImageRight.empty())
   // {
      //  cerr << "ERROR: No images in provided path." << endl;
       // return 1;
    //}

   // if(vstrImageLeft.size()!=vstrImageRight.size())
   // {
     //   cerr << "ERROR: Different number of left and right images." << endl;
   //     return 1;
   // }

    // Read rectification parameters
    cv::FileStorage fsSettings(argv[2], cv::FileStorage::READ);
    if(!fsSettings.isOpened())
    {
        cerr << "ERROR: Wrong path to settings" << endl;
        return -1;
    }

    cv::Mat K_l, K_r, P_l, P_r, R_l, R_r, D_l, D_r;
    fsSettings["LEFT.K"] >> K_l;
    fsSettings["RIGHT.K"] >> K_r;

    fsSettings["LEFT.P"] >> P_l;
    fsSettings["RIGHT.P"] >> P_r;

    fsSettings["LEFT.R"] >> R_l;
    fsSettings["RIGHT.R"] >> R_r;

    fsSettings["LEFT.D"] >> D_l;
    fsSettings["RIGHT.D"] >> D_r;

    int rows_l = fsSettings["LEFT.height"];
    int cols_l = fsSettings["LEFT.width"];
    int rows_r = fsSettings["RIGHT.height"];
    int cols_r = fsSettings["RIGHT.width"];

    if(K_l.empty() || K_r.empty() || P_l.empty() || P_r.empty() || R_l.empty() || R_r.empty() || D_l.empty() || D_r.empty() ||
            rows_l==0 || rows_r==0 || cols_l==0 || cols_r==0)
    {
        cerr << "ERROR: Calibration parameters to rectify stereo are missing!" << endl;
        return -1;
    }

    cv::Mat M1l,M2l,M1r,M2r;
    cv::initUndistortRectifyMap(K_l,D_l,R_l,P_l.rowRange(0,3).colRange(0,3),cv::Size(cols_l,rows_l),CV_32F,M1l,M2l);
    cv::initUndistortRectifyMap(K_r,D_r,R_r,P_r.rowRange(0,3).colRange(0,3),cv::Size(cols_r,rows_r),CV_32F,M1r,M2r);


   // const int nImages = vstrImageLeft.size();

    // Create SLAM system. It initializes all system threads and gets ready to process frames.
    ORB_SLAM2::System SLAM(argv[1],argv[2],ORB_SLAM2::System::STEREO,true);

    // Vector for tracking time statistics
    vector vTimesTrack;
    cout << endl << "-------" << endl;
    cout << "Start processing camera ..." << endl;

  
    cv::Mat imLeft, imRight, imLeftRect, imRightRect;



//***********************************************************************8
       cv::VideoCapture cap1(0);
    cap1.set(CV_CAP_PROP_FRAME_WIDTH,640);

    cap1.set(CV_CAP_PROP_FRAME_HEIGHT,480);
    cap1.set(CV_CAP_PROP_FPS, 30);
    cv::VideoCapture cap2(1);
    cap2.set(CV_CAP_PROP_FRAME_WIDTH,640);

    cap2.set(CV_CAP_PROP_FRAME_HEIGHT,480);
    cap2.set(CV_CAP_PROP_FPS, 30);
   // cv::VideoCapture cap1(0);

//上面这段按你自己的相机参数修改 双目相机有倆id的 有一个id的 左右别反就行
//***********************************************************************8
	long int nImages = 0;
        int ni=0;
// Main loop
    while(ni>-1)
    {

//***********************************************************************8        
         cap2 >> imRight;
         cap1 >> imLeft;
 
//***********************************************************************8
        if(imLeft.empty())
        {
            cerr << endl << "Check Left Camera!! "<< endl;
            return 1;
        }

        if(imRight.empty())
        {
            cerr << endl << "Check Right Camera!! "<< endl;
            return 1;
        }

        cv::remap(imLeft,imLeftRect,M1l,M2l,cv::INTER_LINEAR);
        cv::remap(imRight,imRightRect,M1r,M2r,cv::INTER_LINEAR);

        time_point now = system_clock::now();
        
        double tframe = now.time_since_epoch().count();
        vTimeStamp.push_back(tframe);

#ifdef COMPILEDWITHC11
        std::chrono::steady_clock::time_point t1 = std::chrono::steady_clock::now();
#else
        std::chrono::monotonic_clock::time_point t1 = std::chrono::monotonic_clock::now();
#endif

        // Pass the images to the SLAM system
        SLAM.TrackStereo(imLeftRect,imRightRect,tframe);

#ifdef COMPILEDWITHC11
        std::chrono::steady_clock::time_point t2 = std::chrono::steady_clock::now();
#else
        std::chrono::monotonic_clock::time_point t2 = std::chrono::monotonic_clock::now();
#endif

        double ttrack= std::chrono::duration_cast >(t2 - t1).count();
       
        vTimesTrack.push_back(ttrack);

        // Wait to load the next frame
/*        
	double T=0;
        if(ni0)
            T = tframe-vTimeStamp[ni-1];

       if(ttrack

你可能感兴趣的:(SLAM)