Skip to content

Commit 57c551e

Browse files
committed
fix build
1 parent f2e6f51 commit 57c551e

13 files changed

Lines changed: 1509 additions & 1493 deletions

File tree

Examples/Monocular/mono_euroc.cc

Lines changed: 44 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@
1818
* along with ORB-SLAM2. If not, see <http://www.gnu.org/licenses/>.
1919
*/
2020

21+
#include <iostream>
22+
#include <algorithm>
23+
#include <fstream>
24+
#include <chrono>
25+
#include "unistd.h"
2126

22-
#include<iostream>
23-
#include<algorithm>
24-
#include<fstream>
25-
#include<chrono>
27+
#include <opencv2/core/core.hpp>
2628

27-
#include<opencv2/core/core.hpp>
28-
29-
#include<System.h>
29+
#include <System.h>
3030

3131
using namespace std;
3232

@@ -35,9 +35,10 @@ void LoadImages(const string &strImagePath, const string &strPathTimes,
3535

3636
int main(int argc, char **argv)
3737
{
38-
if(argc != 5)
38+
if (argc != 5)
3939
{
40-
cerr << endl << "Usage: ./mono_tum path_to_vocabulary path_to_settings path_to_image_folder path_to_times_file" << endl;
40+
cerr << endl
41+
<< "Usage: ./mono_tum path_to_vocabulary path_to_settings path_to_image_folder path_to_times_file" << endl;
4142
return 1;
4243
}
4344

@@ -48,35 +49,38 @@ int main(int argc, char **argv)
4849

4950
int nImages = vstrImageFilenames.size();
5051

51-
if(nImages<=0)
52+
if (nImages <= 0)
5253
{
5354
cerr << "ERROR: Failed to load images" << endl;
5455
return 1;
5556
}
5657

5758
// Create SLAM system. It initializes all system threads and gets ready to process frames.
58-
ORB_SLAM2::System SLAM(argv[1],argv[2],ORB_SLAM2::System::MONOCULAR,true);
59+
ORB_SLAM2::System SLAM(argv[1], argv[2], ORB_SLAM2::System::MONOCULAR, true);
5960

6061
// Vector for tracking time statistics
6162
vector<float> vTimesTrack;
6263
vTimesTrack.resize(nImages);
6364

64-
cout << endl << "-------" << endl;
65+
cout << endl
66+
<< "-------" << endl;
6567
cout << "Start processing sequence ..." << endl;
66-
cout << "Images in the sequence: " << nImages << endl << endl;
68+
cout << "Images in the sequence: " << nImages << endl
69+
<< endl;
6770

6871
// Main loop
6972
cv::Mat im;
70-
for(int ni=0; ni<nImages; ni++)
73+
for (int ni = 0; ni < nImages; ni++)
7174
{
7275
// Read image from file
73-
im = cv::imread(vstrImageFilenames[ni],CV_LOAD_IMAGE_UNCHANGED);
76+
im = cv::imread(vstrImageFilenames[ni], CV_LOAD_IMAGE_UNCHANGED);
7477
double tframe = vTimestamps[ni];
7578

76-
if(im.empty())
79+
if (im.empty())
7780
{
78-
cerr << endl << "Failed to load image at: "
79-
<< vstrImageFilenames[ni] << endl;
81+
cerr << endl
82+
<< "Failed to load image at: "
83+
<< vstrImageFilenames[ni] << endl;
8084
return 1;
8185
}
8286

@@ -87,42 +91,43 @@ int main(int argc, char **argv)
8791
#endif
8892

8993
// Pass the image to the SLAM system
90-
SLAM.TrackMonocular(im,tframe);
94+
SLAM.TrackMonocular(im, tframe);
9195

9296
#ifdef COMPILEDWITHC11
9397
std::chrono::steady_clock::time_point t2 = std::chrono::steady_clock::now();
9498
#else
9599
std::chrono::monotonic_clock::time_point t2 = std::chrono::monotonic_clock::now();
96100
#endif
97101

98-
double ttrack= std::chrono::duration_cast<std::chrono::duration<double> >(t2 - t1).count();
102+
double ttrack = std::chrono::duration_cast<std::chrono::duration<double>>(t2 - t1).count();
99103

100-
vTimesTrack[ni]=ttrack;
104+
vTimesTrack[ni] = ttrack;
101105

102106
// Wait to load the next frame
103-
double T=0;
104-
if(ni<nImages-1)
105-
T = vTimestamps[ni+1]-tframe;
106-
else if(ni>0)
107-
T = tframe-vTimestamps[ni-1];
108-
109-
if(ttrack<T)
110-
usleep((T-ttrack)*1e6);
107+
double T = 0;
108+
if (ni < nImages - 1)
109+
T = vTimestamps[ni + 1] - tframe;
110+
else if (ni > 0)
111+
T = tframe - vTimestamps[ni - 1];
112+
113+
if (ttrack < T)
114+
usleep((T - ttrack) * 1e6);
111115
}
112116

113117
// Stop all threads
114118
SLAM.Shutdown();
115119

116120
// Tracking time statistics
117-
sort(vTimesTrack.begin(),vTimesTrack.end());
121+
sort(vTimesTrack.begin(), vTimesTrack.end());
118122
float totaltime = 0;
119-
for(int ni=0; ni<nImages; ni++)
123+
for (int ni = 0; ni < nImages; ni++)
120124
{
121-
totaltime+=vTimesTrack[ni];
125+
totaltime += vTimesTrack[ni];
122126
}
123-
cout << "-------" << endl << endl;
124-
cout << "median tracking time: " << vTimesTrack[nImages/2] << endl;
125-
cout << "mean tracking time: " << totaltime/nImages << endl;
127+
cout << "-------" << endl
128+
<< endl;
129+
cout << "median tracking time: " << vTimesTrack[nImages / 2] << endl;
130+
cout << "mean tracking time: " << totaltime / nImages << endl;
126131

127132
// Save camera trajectory
128133
SLAM.SaveKeyFrameTrajectoryTUM("KeyFrameTrajectory.txt");
@@ -137,19 +142,18 @@ void LoadImages(const string &strImagePath, const string &strPathTimes,
137142
fTimes.open(strPathTimes.c_str());
138143
vTimeStamps.reserve(5000);
139144
vstrImages.reserve(5000);
140-
while(!fTimes.eof())
145+
while (!fTimes.eof())
141146
{
142147
string s;
143-
getline(fTimes,s);
144-
if(!s.empty())
148+
getline(fTimes, s);
149+
if (!s.empty())
145150
{
146151
stringstream ss;
147152
ss << s;
148153
vstrImages.push_back(strImagePath + "/" + ss.str() + ".png");
149154
double t;
150155
ss >> t;
151-
vTimeStamps.push_back(t/1e9);
152-
156+
vTimeStamps.push_back(t / 1e9);
153157
}
154158
}
155159
}

Examples/Monocular/mono_kitti.cc

Lines changed: 44 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@
1818
* along with ORB-SLAM2. If not, see <http://www.gnu.org/licenses/>.
1919
*/
2020

21+
#include <iostream>
22+
#include <algorithm>
23+
#include <fstream>
24+
#include <chrono>
25+
#include <iomanip>
26+
#include "unistd.h"
2127

22-
#include<iostream>
23-
#include<algorithm>
24-
#include<fstream>
25-
#include<chrono>
26-
#include<iomanip>
28+
#include <opencv2/core/core.hpp>
2729

28-
#include<opencv2/core/core.hpp>
29-
30-
#include"System.h"
30+
#include "System.h"
3131

3232
using namespace std;
3333

@@ -36,9 +36,10 @@ void LoadImages(const string &strSequence, vector<string> &vstrImageFilenames,
3636

3737
int main(int argc, char **argv)
3838
{
39-
if(argc != 4)
39+
if (argc != 4)
4040
{
41-
cerr << endl << "Usage: ./mono_kitti path_to_vocabulary path_to_settings path_to_sequence" << endl;
41+
cerr << endl
42+
<< "Usage: ./mono_kitti path_to_vocabulary path_to_settings path_to_sequence" << endl;
4243
return 1;
4344
}
4445

@@ -50,27 +51,30 @@ int main(int argc, char **argv)
5051
int nImages = vstrImageFilenames.size();
5152

5253
// Create SLAM system. It initializes all system threads and gets ready to process frames.
53-
ORB_SLAM2::System SLAM(argv[1],argv[2],ORB_SLAM2::System::MONOCULAR,true);
54+
ORB_SLAM2::System SLAM(argv[1], argv[2], ORB_SLAM2::System::MONOCULAR, true);
5455

5556
// Vector for tracking time statistics
5657
vector<float> vTimesTrack;
5758
vTimesTrack.resize(nImages);
5859

59-
cout << endl << "-------" << endl;
60+
cout << endl
61+
<< "-------" << endl;
6062
cout << "Start processing sequence ..." << endl;
61-
cout << "Images in the sequence: " << nImages << endl << endl;
63+
cout << "Images in the sequence: " << nImages << endl
64+
<< endl;
6265

6366
// Main loop
6467
cv::Mat im;
65-
for(int ni=0; ni<nImages; ni++)
68+
for (int ni = 0; ni < nImages; ni++)
6669
{
6770
// Read image from file
68-
im = cv::imread(vstrImageFilenames[ni],CV_LOAD_IMAGE_UNCHANGED);
71+
im = cv::imread(vstrImageFilenames[ni], CV_LOAD_IMAGE_UNCHANGED);
6972
double tframe = vTimestamps[ni];
7073

71-
if(im.empty())
74+
if (im.empty())
7275
{
73-
cerr << endl << "Failed to load image at: " << vstrImageFilenames[ni] << endl;
76+
cerr << endl
77+
<< "Failed to load image at: " << vstrImageFilenames[ni] << endl;
7478
return 1;
7579
}
7680

@@ -81,45 +85,46 @@ int main(int argc, char **argv)
8185
#endif
8286

8387
// Pass the image to the SLAM system
84-
SLAM.TrackMonocular(im,tframe);
88+
SLAM.TrackMonocular(im, tframe);
8589

8690
#ifdef COMPILEDWITHC11
8791
std::chrono::steady_clock::time_point t2 = std::chrono::steady_clock::now();
8892
#else
8993
std::chrono::monotonic_clock::time_point t2 = std::chrono::monotonic_clock::now();
9094
#endif
9195

92-
double ttrack= std::chrono::duration_cast<std::chrono::duration<double> >(t2 - t1).count();
96+
double ttrack = std::chrono::duration_cast<std::chrono::duration<double>>(t2 - t1).count();
9397

94-
vTimesTrack[ni]=ttrack;
98+
vTimesTrack[ni] = ttrack;
9599

96100
// Wait to load the next frame
97-
double T=0;
98-
if(ni<nImages-1)
99-
T = vTimestamps[ni+1]-tframe;
100-
else if(ni>0)
101-
T = tframe-vTimestamps[ni-1];
102-
103-
if(ttrack<T)
104-
usleep((T-ttrack)*1e6);
101+
double T = 0;
102+
if (ni < nImages - 1)
103+
T = vTimestamps[ni + 1] - tframe;
104+
else if (ni > 0)
105+
T = tframe - vTimestamps[ni - 1];
106+
107+
if (ttrack < T)
108+
usleep((T - ttrack) * 1e6);
105109
}
106110

107111
// Stop all threads
108112
SLAM.Shutdown();
109113

110114
// Tracking time statistics
111-
sort(vTimesTrack.begin(),vTimesTrack.end());
115+
sort(vTimesTrack.begin(), vTimesTrack.end());
112116
float totaltime = 0;
113-
for(int ni=0; ni<nImages; ni++)
117+
for (int ni = 0; ni < nImages; ni++)
114118
{
115-
totaltime+=vTimesTrack[ni];
119+
totaltime += vTimesTrack[ni];
116120
}
117-
cout << "-------" << endl << endl;
118-
cout << "median tracking time: " << vTimesTrack[nImages/2] << endl;
119-
cout << "mean tracking time: " << totaltime/nImages << endl;
121+
cout << "-------" << endl
122+
<< endl;
123+
cout << "median tracking time: " << vTimesTrack[nImages / 2] << endl;
124+
cout << "mean tracking time: " << totaltime / nImages << endl;
120125

121126
// Save camera trajectory
122-
SLAM.SaveKeyFrameTrajectoryTUM("KeyFrameTrajectory.txt");
127+
SLAM.SaveKeyFrameTrajectoryTUM("KeyFrameTrajectory.txt");
123128

124129
return 0;
125130
}
@@ -129,11 +134,11 @@ void LoadImages(const string &strPathToSequence, vector<string> &vstrImageFilena
129134
ifstream fTimes;
130135
string strPathTimeFile = strPathToSequence + "/times.txt";
131136
fTimes.open(strPathTimeFile.c_str());
132-
while(!fTimes.eof())
137+
while (!fTimes.eof())
133138
{
134139
string s;
135-
getline(fTimes,s);
136-
if(!s.empty())
140+
getline(fTimes, s);
141+
if (!s.empty())
137142
{
138143
stringstream ss;
139144
ss << s;
@@ -148,7 +153,7 @@ void LoadImages(const string &strPathToSequence, vector<string> &vstrImageFilena
148153
const int nTimes = vTimestamps.size();
149154
vstrImageFilenames.resize(nTimes);
150155

151-
for(int i=0; i<nTimes; i++)
156+
for (int i = 0; i < nTimes; i++)
152157
{
153158
stringstream ss;
154159
ss << setfill('0') << setw(6) << i;

0 commit comments

Comments
 (0)