-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
148 lines (124 loc) · 4.09 KB
/
main.cpp
File metadata and controls
148 lines (124 loc) · 4.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include "System.h"
using namespace std;
const string strPathToSequence = "./dataset/00";
const string settingFilePath = "./KITTI00-02.yaml";
const string strImagePath = "./dataset/Enoc/cam0";
const string timefilePath = "./dataset/Enoc/data.csv";
void LoadImages_kitti(const string &strSequence, vector<string> &vstrImageFilenames,
vector<double> &vTimestamps);
void LoadImage_euroc(const string &strImagePath, const string &strPathTimes,
vector<string> &vstrImages, vector<double> &vTimeStamps);
void LoadImages(const string &strPathToSequence, vector<string> &vstrImageFilenames, vector<double> &vTimestamps);
int main()
{
// 处理路径加载图像
vector<string> vstrImageFilenames;
vector<double> vTimestamps;
LoadImages(strPathToSequence, vstrImageFilenames, vTimestamps);
int nImages = vstrImageFilenames.size();
Goudan_SLAM::System SLAM("./ORBvoc.txt", settingFilePath);
// 统计时间的Vector
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;
// cv::namedWindow("dataset", cv::WINDOW_AUTOSIZE );
for(int ni = 0; ni<nImages; ni++){
// Read image from file
cout << vstrImageFilenames[ni] <<endl;
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;
}
// Tracking
SLAM.TrackMonocular(im, tframe);
// :TODO
// cv::imshow("dataset", im);
// cv::waitKey(10);
}
return 0;
}
void LoadImages_kitti(const string &strSequence, vector<string> &vstrImageFilenames,
vector<double> &vTimestamps)
{
ifstream fTimes;
string strPathTimeFile = strPathToSequence + "/timestamps.txt";
fTimes.open(strPathTimeFile.c_str());
while(!fTimes.eof()){
string s;
getline(fTimes, s);
if(!s.empty()){
stringstream ss;
ss << s;
double t;
ss >> t;
vTimestamps.push_back(t);
}
}
string strPrefixLeft = strPathToSequence + "/data/";
const int nTimes = vTimestamps.size();
vstrImageFilenames.resize(nTimes);
for(int i=0; i<nTimes; i++)
{
stringstream ss;
ss << setfill('0') << setw(10) << i;
vstrImageFilenames[i] = strPrefixLeft + ss.str() + ".png";
// cout << vstrImageFilenames[i] << endl; // test;
}
}
void LoadImage_euroc(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);
}
}
}
void LoadImages(const string &strPathToSequence, vector<string> &vstrImageFilenames, vector<double> &vTimestamps)
{
ifstream fTimes;
string strPathTimeFile = strPathToSequence + "/times.txt";
fTimes.open(strPathTimeFile.c_str());
while(!fTimes.eof())
{
string s;
getline(fTimes,s);
if(!s.empty())
{
stringstream ss;
ss << s;
double t;
ss >> t;
vTimestamps.push_back(t);
}
}
string strPrefixLeft = strPathToSequence + "/image_0/";
const int nTimes = vTimestamps.size();
vstrImageFilenames.resize(nTimes);
for(int i=0; i<nTimes; i++)
{
stringstream ss;
ss << setfill('0') << setw(6) << i;
vstrImageFilenames[i] = strPrefixLeft + ss.str() + ".png";
}
}