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

[复制链接]
发表于 2025-10-30 17:09:43 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
媒介

设置文件的相干的构造函数
1.函数声明 

settings的构造函数
  1. Settings::Settings(const std::string &configFile, const int &sensor)
  2. : bNeedToUndistort_(false), bNeedToRectify_(false), bNeedToResize1_(false), bNeedToResize2_(false)
复制代码
这个构造函数继续两个参数:
1.configFile:设置文件的路径。
2.sensor:传感器范例。
列表初始化成员变量bNeedToUndistort_、bNeedToRectify_、bNeedToResize1_ 和bNeedToResize2_,它们表现在设置过程中是否须要举行去畸变、校正、缩放等使用。
2.函数界说

1.打开设置文件 
  1. // Open settings file
  2.     cv::FileStorage fSettings(configFile, cv::FileStorage::READ);
  3.     if (!fSettings.isOpened())
  4.     {
  5.         cerr << "[ERROR]: could not open configuration file at: " << configFile << endl;
  6.         cerr << "Aborting..." << endl;
  7.         exit(-1);
  8.     }
  9.     else
  10.     {
  11.         cout << "Loading settings from " << configFile << endl;
  12.     }
复制代码
使用 OpenCV 的 cv::FileStorage 打开传入的设置文件。假如文件打开失败,打印错误信息并停止步调。假如文件乐成打开,输出 "Loading settings from" 设置文件路径。
2.读取相机参数

1.读取相机1参数

调用settings文件中界说的readCamera1函数来提取设置文件中的相机参数。
  1. // Read first camera
  2.     readCamera1(fSettings);
  3.     cout << "\t-Loaded camera 1" << endl;
复制代码
2.读取相机2参数 

假如是双目模式则还须要读取第二个相机的参数。
  1. // Read second camera if stereo (not rectified)
  2.     if (sensor_ == System::STEREO || sensor_ == System::IMU_STEREO)
  3.     {
  4.         readCamera2(fSettings);
  5.         cout << "\t-Loaded camera 2" << endl;
  6.     }
复制代码
3.读取图像信息
  1. // Read first camera
  2.     readCamera1(fSettings);
  3.     cout << "\t-Loaded camera 1" << endl;
复制代码
4.读取IMU参数

假如是imu模式就须要读取相干参数
  1. if (sensor_ == System::IMU_MONOCULAR || sensor_ == System::IMU_STEREO || sensor_ == System::IMU_RGBD)
  2.     {
  3.         readIMU(fSettings);
  4.         cout << "\t-Loaded IMU calibration" << endl;
  5.     }
复制代码
5.读取RGBD参数 

假如是RGBD模式就需读取相干参数
  1. if (sensor_ == System::RGBD || sensor_ == System::IMU_RGBD)
  2.     {
  3.         readRGBD(fSettings);
  4.         cout << "\t-Loaded RGB-D calibration" << endl;
  5.     }
复制代码
6.读取设置文件中的别的参数
  1. readORB(fSettings);
  2.     cout << "\t-Loaded ORB settings" << endl;
  3.     readViewer(fSettings);
  4.     cout << "\t-Loaded viewer settings" << endl;
  5.     readLoadAndSave(fSettings);
  6.     cout << "\t-Loaded Atlas settings" << endl;
  7.     readOtherParameters(fSettings);
  8.     cout << "\t-Loaded misc parameters" << endl;
复制代码
7 .查抄是否须要改正使用

假如须要举行图像的校正(比方,去畸变),调用 precomputeRectificationMaps() 预盘算校正舆图。
  1. if (bNeedToRectify_)
  2.     {
  3.         precomputeRectificationMaps();
  4.         cout << "\t-Computed rectification maps" << endl;
  5.     }
复制代码
完备的代码 
  1. Settings::Settings(const std::string &configFile, const int &sensor)
  2. : bNeedToUndistort_(false), bNeedToRectify_(false), bNeedToResize1_(false), bNeedToResize2_(false){    sensor_ = sensor;   
  3. // Open settings file
  4.     cv::FileStorage fSettings(configFile, cv::FileStorage::READ);
  5.     if (!fSettings.isOpened())
  6.     {
  7.         cerr << "[ERROR]: could not open configuration file at: " << configFile << endl;
  8.         cerr << "Aborting..." << endl;
  9.         exit(-1);
  10.     }
  11.     else
  12.     {
  13.         cout << "Loading settings from " << configFile << endl;
  14.     }   
  15. // Read first camera
  16.     readCamera1(fSettings);
  17.     cout << "\t-Loaded camera 1" << endl;   
  18. // Read second camera if stereo (not rectified)
  19.     if (sensor_ == System::STEREO || sensor_ == System::IMU_STEREO)
  20.     {
  21.         readCamera2(fSettings);
  22.         cout << "\t-Loaded camera 2" << endl;
  23.     }    // Read image info    readImageInfo(fSettings);    cout << "\t-Loaded image info" << endl;   
  24. if (sensor_ == System::IMU_MONOCULAR || sensor_ == System::IMU_STEREO || sensor_ == System::IMU_RGBD)
  25.     {
  26.         readIMU(fSettings);
  27.         cout << "\t-Loaded IMU calibration" << endl;
  28.     }   
  29. if (sensor_ == System::RGBD || sensor_ == System::IMU_RGBD)
  30.     {
  31.         readRGBD(fSettings);
  32.         cout << "\t-Loaded RGB-D calibration" << endl;
  33.     }   
  34. readORB(fSettings);
  35.     cout << "\t-Loaded ORB settings" << endl;
  36.     readViewer(fSettings);
  37.     cout << "\t-Loaded viewer settings" << endl;
  38.     readLoadAndSave(fSettings);
  39.     cout << "\t-Loaded Atlas settings" << endl;
  40.     readOtherParameters(fSettings);
  41.     cout << "\t-Loaded misc parameters" << endl;   
  42. if (bNeedToRectify_)
  43.     {
  44.         precomputeRectificationMaps();
  45.         cout << "\t-Computed rectification maps" << endl;
  46.     }    cout << "----------------------------------" << endl;}
复制代码
竣事语

以上就是我学习到的内容,假如对您有资助请多多支持我,假如那里有标题欢迎各人在品评区积极讨论,我看到会实时复兴。
回复

使用道具 举报

登录后关闭弹窗

登录参与点评抽奖  加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表