ORB-SLAM3的源码学习: Settings.cc:settings构造函数

前言

配置文件的相关的构造函数

1.函数声明 

settings的构造函数

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

这个构造函数接受两个参数:

1.configFile:配置文件的路径。

2.sensor:传感器类型。

列表初始化成员变量bNeedToUndistort_bNeedToRectify_bNeedToResize1_bNeedToResize2_,它们表示在设置过程中是否需要进行去畸变、校正、缩放等操作。

2.函数定义

1.打开配置文件 

// 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;
    }

使用 OpenCV 的 cv::FileStorage 打开传入的配置文件。如果文件打开失败,打印错误信息并终止程序。如果文件成功打开,输出 "Loading settings from" 配置文件路径。

2.读取相机参数

1.读取相机1参数

调用settings文件中定义的readCamera1函数来提取配置文件中的相机参数。

// Read first camera
    readCamera1(fSettings);
    cout << "\t-Loaded camera 1" << endl;

2.读取相机2参数 

如果是双目模式则还需要读取第二个相机的参数。

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

3.读取图像信息

// Read first camera
    readCamera1(fSettings);
    cout << "\t-Loaded camera 1" << endl;

4.读取IMU参数

如果是imu模式就需要读取相关参数

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

5.读取RGBD参数 

如果是RGBD模式就需读取相关参数

if (sensor_ == System::RGBD || sensor_ == System::IMU_RGBD)
    {
        readRGBD(fSettings);
        cout << "\t-Loaded RGB-D calibration" << endl;
    }

6.读取配置文件中的其余参数

readORB(fSettings);
    cout << "\t-Loaded ORB settings" << endl;
    readViewer(fSettings);
    cout << "\t-Loaded viewer settings" << endl;
    readLoadAndSave(fSettings);
    cout << "\t-Loaded Atlas settings" << endl;
    readOtherParameters(fSettings);
    cout << "\t-Loaded misc parameters" << endl;

7 .检查是否需要矫正操作

如果需要进行图像的校正(例如,去畸变),调用 precomputeRectificationMaps() 预计算校正地图。

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

完整的代码 

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

    readORB(fSettings);
    cout << "\t-Loaded ORB settings" << endl;
    readViewer(fSettings);
    cout << "\t-Loaded viewer settings" << endl;
    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;
}

结束语

以上就是我学习到的内容,如果对您有帮助请多多支持我,如果哪里有问题欢迎大家在评论区积极讨论,我看到会及时回复。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值