-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.cpp
156 lines (123 loc) · 3.49 KB
/
main.cpp
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
149
150
151
152
153
154
155
156
#define tum
#include "opencv2/opencv.hpp"
#include <iostream>
#include "System.h"
#include<fstream>
using namespace cv;
using namespace std;
#ifdef tum
void LoadImages(const string &strFile, vector<string> &vstrImageFilenames,
vector<double> &vTimestamps);
int main(int argc, char **argv)
{
// Retrieve paths to images
vector<string> vstrImageFilenames;
vector<double> vTimestamps;
string strFile = string(argv[2])+"/rgb.txt";
cout<<strFile<<endl;
LoadImages(strFile, vstrImageFilenames, vTimestamps);
int nImages = vstrImageFilenames.size();
cout<<vstrImageFilenames.size()<<endl;
bool visualizer = true;
VITAMINE::System vitamine(argv[1], visualizer);
// Vector for tracking time statistics
vector<float> vTimesTrack;
vTimesTrack.resize(nImages);
cout << endl << "-------" << endl;
cout << "Start processing sequence ..." << endl;
cout << "Images in the sequence: " << nImages << endl << endl;
// Main loop
cv::Mat im;
for(int ni=0; ni<nImages; ni++)
{
// Read image from file
im = cv::imread(string(argv[2])+"/"+vstrImageFilenames[ni]);
cout<<im.size()<<endl;
double tframe = vTimestamps[ni];
if(im.empty())
{
cerr << endl << "Failed to load image at: "
<< string(argv[2]) << "/" << vstrImageFilenames[ni] << endl;
return 1;
}
// Pass the image to the SLAM system
cout<<"?"<<endl;
vitamine.Track(im);
/* vTimesTrack[ni]=ttrack;
// Wait to load the next frame
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); */
}
// Stop all threads
vitamine.Shutdown();
/* // Tracking time statistics
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; */
vitamine.Shutdown();
return 0;
}
void LoadImages(const string &strFile, vector<string> &vstrImageFilenames, vector<double> &vTimestamps)
{
ifstream f;
f.open(strFile.c_str());
// skip first three lines
string s0;
getline(f,s0);
getline(f,s0);
getline(f,s0);
while(!f.eof())
{
string s;
getline(f,s);
if(!s.empty())
{
stringstream ss;
ss << s;
double t;
string sRGB;
ss >> t;
vTimestamps.push_back(t);
ss >> sRGB;
vstrImageFilenames.push_back(sRGB);
}
}
}
#endif
#ifdef webcam
int main(int argc, char **argv)
{
VideoCapture cap(0);
if (!cap.isOpened())
{
cerr<<"cam open error"<<endl;
}
bool visualizer = true;
VITAMINE::System vitamine(argv[1], visualizer);
Mat frame;
int i=0;
while(true)
{
cap >> frame;
resize(frame, frame, Size(640,480));
//imshow("img", frame);
//std::string filename = "calib_img1"+to_string(i++)+".jpg";
//imwrite(filename, frame);
//waitKey(0);
vitamine.Track(frame);
}
vitamine.Shutdown();
return 0;
}
#endif