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
3232using namespace std ;
3333
@@ -36,9 +36,10 @@ void LoadImages(const string &strSequence, vector<string> &vstrImageFilenames,
3636
3737int 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