-
Notifications
You must be signed in to change notification settings - Fork 5
/
readData.cpp
92 lines (75 loc) · 2.24 KB
/
readData.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
//
// Created by huchao on 19-5-17.
//
#include "readData.h"
#include <iostream>
#include <string>
bool readData::getDataFromTxt(baData& data) {
ifstream file;
file.open(path, ios::in);
if( !file.is_open() )
return false;
int numCam;
file >> numCam;
data.numCam = numCam;
int numPoints;
file >> numPoints;
data.numPoints = numPoints;
int numObservations;
file >> numObservations;
data.numObservations = numObservations;
cout << "The number of camera is : " << data.numCam <<endl;
cout << "The number of points is : " << data.numPoints <<endl;
cout << "The number of observations is : " <<data.numObservations <<endl;
if( data.numCam ==0 ||
data.numPoints ==0 ||
data.numObservations ==0)
return false;
data.cam_ptn_pt.resize(data.numCam);
{
for(int i=0;i<data.numObservations;++i){
int camSubCoord;
int pointSubCoord;
Point2f pt;
file >> camSubCoord;
file >> pointSubCoord;
file >> pt.x;
file >> pt.y;
data.cam_ptn_pt[camSubCoord].insert(
make_pair(pointSubCoord,pt) );
}
int tempNumObservations = 0;
for(int i=0;i<data.cam_ptn_pt.size();++i)
{
tempNumObservations += data.cam_ptn_pt[i].size();
}
if( tempNumObservations != data.numObservations ){
cout<<"The real number of observations is not "<<data.numObservations<<endl;
return false;
}
for(int i=0;i<data.numCam;++i){
vector<double> cam_param_temp;
double temp;
for(int j=0;j<9;++j){
file >> temp;
cam_param_temp.push_back(temp);
}
data.cams.insert(make_pair(i,cam_param_temp));
}
for(int i=0;i<data.numPoints;++i){
vector<double> points_temp;
double temp;
for(int j=0;j<3;j++){
file >> temp;
points_temp.push_back(temp);
}
data.pts.insert(make_pair(i,points_temp));
}
}
string temp;
file >> temp;
if(file.eof())
return true;
else
return false;
}