orb-slam3(mono_tum)代码学习(一)setting

orb-slam3主要由跟踪(Tracking)、局部建图(LocalMapping)、回环检测(loopclosing)三个线程组成。

先看mono_tum的主函数部分,创建了一个system类的对象SLAM,system类是初始化和控制整个slam系统的类。

ORB_SLAM3::System SLAM(argv[1],argv[2],ORB_SLAM3::System::MONOCULAR,true);

查看system类的构造函数,system类在构造的时候传建了一个setting对象,setting类配置系统的各种参数

if(!node.empty() && node.isString() && node.string() == "1.0"){
        settings_ = new Settings(strSettingsFile,mSensor);

        mStrLoadAtlasFromFile = settings_->atlasLoadFile();
        mStrSaveAtlasToFile = settings_->atlasSaveFile();

        cout << (*settings_) << endl;
    }

在来看setting类的构造函数,读取的相机参数和ORB特征提取器的行为

Settings::Settings(const std::string &configFile, const int& sensor) :
    bNeedToUndistort_(false), bNeedToRectify_(false), bNeedToResize1_(false), bNeedToResize2_(false) {
        sensor_ = sensor;

        //Open settings file
        cv::FileStorage fSettings(configFile, cv::FileStorage::READ);
        if (!fSettings.isOpened()) {
            cerr << "[ERROR]: could not open configuration file at: " << configFile << endl;
            cerr << "Aborting..." << endl;

            exit(-1);
        }
        else{
            cout << "Loading settings from " << configFile << endl;
        }

        //Read first camera 根据不同的相机模型导入参数
        readCamera1(fSettings);
        cout << "\t-Loaded camera 1" << endl;

        //Read second camera if stereo (not rectified)
        if(sensor_ == System::STEREO || sensor_ == System::IMU_STEREO){
            readCamera2(fSettings);
            cout << "\t-Loaded camera 2" << endl;
        }

        //Read image info 更新参数,如imageScale
        readImageInfo(fSettings);
        cout << "\t-Loaded image info" << endl;

        if(sensor_ == System::IMU_MONOCULAR || sensor_ == System::IMU_STEREO || sensor_ == System::IMU_RGBD){
            readIMU(fSettings);
            cout << "\t-Loaded IMU calibration" << endl;
        }

        if(sensor_ == System::RGBD || sensor_ == System::IMU_RGBD){
            readRGBD(fSettings);
            cout << "\t-Loaded RGB-D calibration" << endl;
        }
        // YAML 配置文件中的参数用于设置 ORB 特征提取器的行为,尺度金字塔中相邻层之间的缩放因子、层数,最多提取的特征点数、Fast角点检测阈值
        readORB(fSettings);
        cout << "\t-Loaded ORB settings" << endl;
        //读取可视化相关参数
        readViewer(fSettings);
        cout << "\t-Loaded viewer settings" << endl;
        //读取与加载和保存 Atlas(地图数据)相关的参数
        readLoadAndSave(fSettings);
        cout << "\t-Loaded Atlas settings" << endl;
        readOtherParameters(fSettings);
        cout << "\t-Loaded misc parameters" << endl;

        if(bNeedToRectify_){
            precomputeRectificationMaps();
            cout << "\t-Computed rectification maps" << endl;
        }

        cout << "----------------------------------" << endl;
    }

将配置文件传入setting类成为内参后,定义了tracking对象,并开了localmapping和loopclosing两个新线程

    mpFrameDrawer = new FrameDrawer(mpAtlas);
    mpMapDrawer = new MapDrawer(mpAtlas, strSettingsFile, settings_);

    //Initialize the Tracking thread
    //(it will live in the main thread of execution, the one that called this constructor)
    cout << "Seq. Name: " << strSequence << endl;
    mpTracker = new Tracking(this, mpVocabulary, mpFrameDrawer, mpMapDrawer,
                             mpAtlas, mpKeyFrameDatabase, strSettingsFile, mSensor, settings_, strSequence);

    //Initialize the Local Mapping thread and launch
    mpLocalMapper = new LocalMapping(this, mpAtlas, mSensor==MONOCULAR || mSensor==IMU_MONOCULAR,
                                     mSensor==IMU_MONOCULAR || mSensor==IMU_STEREO || mSensor==IMU_RGBD, strSequence);
    mptLocalMapping = new thread(&ORB_SLAM3::LocalMapping::Run,mpLocalMapper);
    mpLocalMapper->mInitFr = initFr;
    if(settings_)
        mpLocalMapper->mThFarPoints = settings_->thFarPoints();
    else
        mpLocalMapper->mThFarPoints = fsSettings["thFarPoints"];
    if(mpLocalMapper->mThFarPoints!=0)
    {
        cout << "Discard points further than " << mpLocalMapper->mThFarPoints << " m from current camera" << endl;
        mpLocalMapper->mbFarPoints = true;
    }
    else
        mpLocalMapper->mbFarPoints = false;

    //Initialize the Loop Closing thread and launch
    // mSensor!=MONOCULAR && mSensor!=IMU_MONOCULAR
    mpLoopCloser = new LoopClosing(mpAtlas, mpKeyFrameDatabase, mpVocabulary, mSensor!=MONOCULAR, activeLC); // mSensor!=MONOCULAR);
    mptLoopClosing = new thread(&ORB_SLAM3::LoopClosing::Run, mpLoopCloser);

    //Set pointers between threads
    mpTracker->SetLocalMapper(mpLocalMapper);
    mpTracker->SetLoopClosing(mpLoopCloser);

    mpLocalMapper->SetTracker(mpTracker);
    mpLocalMapper->SetLoopCloser(mpLoopCloser);

    mpLoopCloser->SetTracker(mpTracker);
    mpLoopCloser->SetLocalMapper(mpLocalMapper);

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要配置ORB-SLAM3的环境,您需要按照以下步骤操作: 1. 安装依赖库:ORB-SLAM3需要使用一些第三方库,例如OpenCV、Eigen、Pangolin等。确保您已经安装了这些库。您可以通过以下命令在Ubuntu上安装它们: ``` sudo apt-get install libeigen3-dev libopencv-dev libpangolin-dev ``` 2. 克隆ORB-SLAM3的代码库:使用Git工具克隆ORB-SLAM3的代码库到您的本地机器上: ``` git clone https://github.com/UZ-SLAMLab/ORB_SLAM3.git ``` 3. 编译ORB-SLAM3:进入克隆的代码库目录,并创建一个build目录。然后,使用CMake来配置和构建ORB-SLAM3: ``` cd ORB_SLAM3 mkdir build cd build cmake .. make -j4 ``` 4. 下载Vocabulary文件:在ORB-SLAM3的代码库中,有一个vocabulary文件夹。您需要下载一个适合您的应用的vocabulary文件。例如,如果您想使用ORB-SLAM3的Monocular模式,可以从官方网站(https://github.com/UZ-SLAMLab/ORB_SLAM3#downloads)下载Monocular-vocabulary文件,并将其放置在vocabulary文件夹中。 5. 配置数据集:ORB-SLAM3需要一个输入图像序列作为输入数据集。您可以使用自己的数据集,或者从ORB-SLAM3的官方网站上下载一些示例数据集。 6. 运行ORB-SLAM3:使用以下命令来运行ORB-SLAM3,并指定您的数据集和相机参数: ``` ./Examples/Monocular/mono_tum Vocabulary/ORBvoc.txt Examples/Monocular/TUMX.yaml 数据集的路径 ``` 这些步骤可以帮助您配置和运行ORB-SLAM3。请确保按照文档提供的说明进行操作。如果遇到任何问题,您可以参考ORB-SLAM3的官方文档或在相关论坛上寻求帮助。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值