-
Notifications
You must be signed in to change notification settings - Fork 17
/
pose_estimation.cpp
166 lines (135 loc) · 3.43 KB
/
pose_estimation.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
/*
* pose_estimation.cpp
*
* Created on: Feb 28, 2015
* Author: Fabian Tschopp, Marco Zorzi
*/
#include <iostream>
#include <chrono>
#include <ctime>
#include <algorithm>
#include <functional>
#include <iterator>
#include <array>
#include <string>
#include <fstream>
#include <sstream>
#include <cassert>
#include <vector>
#ifndef __APPLE__
#include <omp.h>
#endif
#include <chrono>
#include <cmath>
#include <time.h>
#include <sys/time.h>
#include <flann/flann.h>
#include <eigen3/Eigen/Dense>
#include <eigen3/Eigen/Core>
#include <eigen3/Eigen/Eigen>
#include "P3p.hpp"
#include "P4pf.hpp"
#include "SIFT_keypoint.hpp"
#include "parse_bundler.hpp"
#include "bundler_camera.hpp"
#include "query_loader.hpp"
#include "query_processor.hpp"
#include "log.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "import_export.hpp"
#include "benchmark.hpp"
#define DLOG true
#define INFO_DATASET "data/dubrovnik6k.info"
#define GOLDEN_DATASET "data/Dubrovnik6K/bundle/bundle.orig.out"
#define DATABASE_PATH "data/Dubrovnik6K/"
#define QUERY_PATH "data/query/"
using namespace pose_estimation;
int main(int argc, char* argv[]) {
// For the parallel algorithms, use 4 threads
#ifndef __APPLE__
omp_set_num_threads(4);
#endif
// Write some log message
log("Program started.");
// Load the INFO file
parse_bundler pb;
// Load the golden reference file
parse_bundler golden_pb;
#pragma omp parallel sections
{
#pragma omp section
{
golden_pb.parse_data(GOLDEN_DATASET, nullptr);
}
#pragma omp section
{
pb.load_from_binary(INFO_DATASET, 1);
}
}
log("Dataset loaded.");
int processor_type;
// Select the processor
std::cout << "0: Basic Processor, 1: Advanced Processor: ";
std::cin >> processor_type;
QueryProcessor *qp;
// Prepare query processor
if (processor_type == 1) {
qp = new QueryProcessorAdvanced(pb);
} else {
qp = new QueryProcessorBasic(pb);
}
// Prepare query loader
QueryLoader ql(DATABASE_PATH, QUERY_PATH);
// Load a query file
int queryindex;
std::string querypath;
int mode;
bool exit = false;
// User input loop
while (!exit) {
std::cout
<< "0: Exit, 1: Export 3D Model, 2: Process query file, 3: Benchmark: ";
std::cin >> mode;
switch (mode) {
case 0: {
exit = true;
break;
}
case 1: {
ExportMesh(golden_pb, "out/", "mesh");
break;
}
case 2: {
std::cout << "Enter a query index (1 to " << (ql.GetQueryCount())
<< "): ";
std::cin >> queryindex;
int queryidx = std::min(std::max(queryindex - 1, 0),
ql.GetQueryCount() - 1);
Query golden = LoadGoldenQuery(golden_pb, queryidx,
"data/Dubrovnik6K/bundle/");
Query query = ql.GetQuery(queryidx, true);
bool success = qp->Process(query);
std::cout << "Pose Estimation: " << std::endl;
std::cout << query.focal_length() << std::endl;
std::cout << query.camera_position() << std::endl;
std::cout << query.camera_rotation() << std::endl;
std::cout << "Pose Estimation (Golden): " << std::endl;
std::cout << golden.focal_length() << std::endl;
std::cout << golden.camera_position() << std::endl;
std::cout << golden.camera_rotation() << std::endl;
ExportCamera(query, "out/", "camera" + std::to_string(queryindex));
ExportCameraProjectEdges(query, "out/",
"camera_proj" + std::to_string(queryindex));
break;
}
case 3: {
Benchmark(ql, golden_pb, qp);
break;
}
default:
break;
}
}
}