#include<iostream>
#include<algorithm>
#include<fstream>
#include<chrono>
#include<opencv2/core/core.hpp>
#include<System.h>
#include<unistd.h>
using namespace std;
void LoadImages(const string &strImagePath, const string &strPathTimes,
vector<string> &vstrImages, vector<double> &vTimeStamps);
int main(int argc, char **argv)
{
if(argc != 5)
{
cerr << endl << "Usage: ./mono_tum path_to_vocabulary path_to_settings path_to_image_folder path_to_times_file" << endl;
return 1;
}
vector<string> vstrImageFilenames;
vector<double> vTimestamps;
LoadImages(string(argv[3]),
string(argv[4]),
vstrImageFilenames,
vTimestamps);
int nImages = vstrImageFilenames.size();
if(nImages<=0)
{
cerr << "ERROR: Failed to load images" << endl;
return 1;
}
ORB_SLAM2::System SLAM(
argv[1],
argv[2],
ORB_SLAM2::System::MONOCULAR,
true);
vector<float> vTimesTrack;
vTimesTrack.resize(nImages);
cout << endl << "-------" << endl;
cout << "Start processing sequence ..." << endl;
cout << "Images in the sequence: " << nImages << endl << endl;
cv::Mat im;
for(int ni=0; ni<nImages; ni++)
{
im = cv::imread(vstrImageFilenames[ni],CV_LOAD_IMAGE_UNCHANGED);
double tframe = vTimestamps[ni];
if(im.empty())
{
cerr << endl << "Failed to load image at: "
<< vstrImageFilenames[ni] << endl;
return 1;
}
#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
SLAM.TrackMonocular(im,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<std::chrono::duration<double> >(t2 - t1).count();
vTimesTrack[ni]=ttrack;
double T=0;
if(ni<nImages-1)
T = vTimestamps[ni+1]-tframe;
else if(ni>0)
T = tframe-vTimestamps[ni-1];
if(ttrack<T)
usleep((T-ttrack)*1e6);
}
SLAM.Shutdown();
sort(vTimesTrack.begin(),vTimesTrack.end());
float totaltime = 0;
for(int ni=0; ni<nImages; ni++)
{
totaltime+=vTimesTrack[ni];
}
cout << "-------" << endl << endl;
cout << "median tracking time: " << vTimesTrack[nImages/2] << endl;
cout << "mean tracking time: " << totaltime/nImages << endl;
SLAM.SaveKeyFrameTrajectoryTUM("KeyFrameTrajectory.txt");
return 0;
}
void LoadImages(const string &strImagePath, const string &strPathTimes,
vector<string> &vstrImages, vector<double> &vTimeStamps)
{
ifstream fTimes;
fTimes.open(strPathTimes.c_str());
vTimeStamps.reserve(5000);
vstrImages.reserve(5000);
while(!fTimes.eof())
{
string s;
getline(fTimes,s);
if(!s.empty())
{
stringstream ss;
ss << s;
vstrImages.push_back(strImagePath + "/" + ss.str() + ".png");
double t;
ss >> t;
vTimeStamps.push_back(t/1e9);
}
}
}
SLAM主类
成员变量/函数 | 意 |
---|
eSensor mSensor | 传感器的类型 | ORBVocabulary* mpVocabulary | ORB字典,保存ORB描述子聚类的结果 | keyFrameDatabase* mpKeyFrameDatabase | 关键帧数据库,保存ORB描述子倒排索引 | Map* mpMap | 地图 | Tracking* mpTracker | 追踪器 | LoolMapping* mpLocalMapper thread* mptLocalMapping | 局部建图器 局部建图线程 | LoopClosing* mpLoopCloser thread* mpLoopCloser | 回环检测器 回环检测线程 | Viewer* mpViewer FrameDrawer* mpFrameDrawer MapDrawer thread* mptViewer | 查看器 帧绘制器 地图绘制器 查看器线程 | System | 构造函数 | cv::Mat TrackMonocular | 跟踪单目相机,返回相机位姿 | bool mbActivateLocalizationMode bool mbDeactivate | 开启/关闭纯定位模式 | std::mutex mMutexReset | 锁 | void ActivateLocalizationMode void DctivateLocalizationMode | 开启/关闭纯定位模式 | bool mbReset void Reset | 系统复位 | void shutdown | 系统关闭 |
构造函数System
|