-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathDatasetReader.cpp
194 lines (166 loc) · 6.17 KB
/
DatasetReader.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
//
// Created by zhuzunjie on 18-4-9.
//
#include "DatasetReader.h"
#include <iostream>
namespace DataReader {
void loadImageList(const char *imagePath, std::vector<ICell> &iListData) {
ifstream inf;
inf.open(imagePath, ifstream::in);
const int cnt = 2; // 你要输出的个数
string line;
size_t comma = 0;
size_t comma2 = 0;
ICell temp;
getline(inf, line);
while (!inf.eof()) {
getline(inf, line);
comma = line.find(',', 0);
string temp1 = line.substr(0, comma);
temp.timeStamp = (double) atof(temp1.c_str());
comma2 = line.find(',', comma + 1);
temp.imgName = line.substr(comma + 1, comma2 - comma - 1).c_str();
if(temp.timeStamp < 1e-3) continue;
iListData.push_back(temp);
}
inf.close();
}
void loadIMUFile(const char *imuPath, std::vector<IMUData> &vimuData) {
ifstream inf;
inf.open(imuPath, ifstream::in);
if(!inf){
cout<< "No IMU information" << endl;
return;
}
const int cnt = 7; // 你要输出的个数
string line;
//int i = 0;
int j = 0;
size_t comma = 0;
size_t comma2 = 0;
// char imuTime[14] = {0};
double acc[3] = {0.0};
double grad[3] = {0.0};
double imuTimeStamp = 0.0;
getline(inf, line);
while (!inf.eof()) {
getline(inf, line);
comma = line.find(',', 0);
string temp = line.substr(0, comma);
imuTimeStamp = (double) atof(temp.c_str());
//cout<<line.substr(0,comma).c_str()<<' ';
//memcpy(imuTimeStamp,line.substr(0,comma).c_str(),line.substr(0,comma).length);
while (comma < line.size() && j != cnt - 1) {
comma2 = line.find(',', comma + 1);
switch (j) {
case 0:
grad[0] = atof(line.substr(comma + 1, comma2 - comma - 1).c_str());
break;
case 1:
grad[1] = atof(line.substr(comma + 1, comma2 - comma - 1).c_str());
break;
case 2:
grad[2] = atof(line.substr(comma + 1, comma2 - comma - 1).c_str());
break;
case 3:
acc[0] = atof(line.substr(comma + 1, comma2 - comma - 1).c_str());
break;
case 4:
acc[1] = atof(line.substr(comma + 1, comma2 - comma - 1).c_str());
break;
case 5:
acc[2] = atof(line.substr(comma + 1, comma2 - comma - 1).c_str());
break;
}
//cout<<line.substr(comma + 1,comma2-comma-1).c_str()<<' ';
++j;
comma = comma2;
}
if(imuTimeStamp < 1e-3) continue;
IMUData tempImu(grad[0], grad[1], grad[2], acc[0], acc[1], acc[2], imuTimeStamp);
vimuData.push_back(tempImu);
j = 0;
}
inf.close();
//return 0;
}
void synInit(std::vector<ICell> &imageList, std::vector<IMUData> &imuList, int imgIdx, int imuIdx) {
// Find Start Idx
// 预处理数据
int startImuIdx = 0;
int startImageIdx = 0;
// 剔除初始的冗余IMU数据
while (1) {
if (imuList[startImuIdx]._t >= imageList[0].timeStamp)
break;
startImuIdx++;
}
// 剔除初始的冗余Image数据
while (1) {
if (imuList[0]._t <= imageList[startImageIdx].timeStamp)
break;
startImageIdx++;
}
// 将IMU和图片时间戳对齐
while (1) {
if (imuList[startImuIdx]._t >= imageList[startImageIdx].timeStamp)
break;
startImuIdx++;
}
imgIdx = startImageIdx;
imuIdx = startImuIdx;
}
}
/*void loadGTFile(const char *imuPath, std::vector<GT> &vGTData) {
ifstream inf;
inf.open(imuPath, ifstream::in);
const int cnt = 7; // 你要输出的个数
string line;
//int i = 0;
int j = 0;
size_t comma = 0;
size_t comma2 = 0;
getline(inf, line);
while (!inf.eof()) {
GT tempGT;
getline(inf, line);
comma = line.find(',', 0);
string temp = line.substr(0, comma);
tempGT.timeStamp = (double) atof(temp.c_str());
//cout<<line.substr(0,comma).c_str()<<' ';
//memcpy(imuTimeStamp,line.substr(0,comma).c_str(),line.substr(0,comma).length);
while (j < cnt) {
comma2 = line.find(',', comma + 1);
switch (j) {
case 0:
tempGT.position[2] = atof(line.substr(comma + 1, comma2 - comma - 1).c_str());
break;
case 1:
tempGT.position[0] = -(atof(line.substr(comma + 1, comma2 - comma - 1).c_str()));
break;
case 2:
tempGT.position[1] = -(atof(line.substr(comma + 1, comma2 - comma - 1).c_str()));
break;
// case 3:
// tempGT.rotation_Q[0] = atof(line.substr(comma + 1,comma2-comma-1).c_str());
// break;
// case 4:
// tempGT.rotation_Q[1] = atof(line.substr(comma + 1,comma2-comma-1).c_str());
// break;
// case 5:
// tempGT.rotation_Q[2] = atof(line.substr(comma + 1,comma2-comma-1).c_str());
// break;
// case 6:
// tempGT.rotation_Q[3] = atof(line.substr(comma + 1,comma2-comma-1).c_str());
// break;
}
//cout<<line.substr(comma + 1,comma2-comma-1).c_str()<<' ';
++j;
comma = comma2;
}
vGTData.push_back(tempGT);
j = 0;
}
inf.close();
//return 0;
}*/