forked from sweeneychris/akaze-eigen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathakaze_features.cpp
241 lines (217 loc) · 7.62 KB
/
akaze_features.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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
//=============================================================================
//
// akaze_features.cpp
// Authors: Pablo F. Alcantarilla (1), Jesus Nuevo (2)
// Institutions: Toshiba Research Europe Ltd (1)
// TrueVision Solutions (2)
// Date: 07/10/2014
// Email: pablofdezalc@gmail.com
//
// AKAZE Features Copyright 2014, Pablo F. Alcantarilla, Jesus Nuevo
// All Rights Reserved
// See LICENSE for the license information
//=============================================================================
/**
* @file akaze_features.cpp
* @brief Main program for detecting and computing binary descriptors in an
* accelerated nonlinear scale space
* @date Oct 07, 2014
* @author Pablo F. Alcantarilla, Jesus Nuevo
*/
#include <ctime>
#include "cimg/CImg.h"
#include "src/AKAZE.h"
#include "src/AKAZEConfig.h"
#include "src/utils.h"
#include "timer/timer.hpp"
/* ************************************************************************* */
/**
* @brief This function parses the command line arguments for setting A-KAZE
* parameters
* @param options Structure that contains A-KAZE settings
* @param img_path Path for the input image
* @param kpts_path Path for the file where the keypoints where be stored
*/
int parse_input_options(libAKAZE::AKAZEOptions& options, std::string& img_path,
std::string& kpts_path, int argc, char* argv[]);
/* ************************************************************************* */
int main(int argc, char* argv[]) {
// Variables
libAKAZE::AKAZEOptions options;
std::string img_path, kpts_path;
// Variable for computation times.
double tdet = 0.0, tdesc = 0.0;
// Parse the input command line options
if (parse_input_options(options, img_path, kpts_path, argc, argv)) {
return -1;
}
if (options.verbosity) {
std::cout << "Check AKAZE options:" << std::endl;
std::cout << options << std::endl;
}
// Try to read the image and if necessary convert to grayscale. CImg will
// throw an error and crash if the image could not be read.
cimg_library::CImg<float> img(img_path.c_str());
RowMatrixXf img_32;
ConvertCImgToEigen(img, img_32);
img_32 /= 255.0;
// Don't forget to specify image dimensions in AKAZE's options.
options.img_width = img_32.cols();
options.img_height = img_32.rows();
// Extract features.
std::vector<libAKAZE::AKAZEKeypoint> kpts;
timer::Timer timer;
libAKAZE::AKAZE evolution(options);
evolution.Create_Nonlinear_Scale_Space(img_32);
evolution.Feature_Detection(kpts);
tdet = timer.elapsedMs();
// Compute descriptors.
libAKAZE::AKAZEDescriptors desc;
timer.reset();
evolution.Compute_Descriptors(kpts, desc);
tdesc = timer.elapsedMs();
// Summarize the computation times.
evolution.Show_Computation_Times();
evolution.Save_Scale_Space();
std::cout << "Number of points: " << kpts.size() << std::endl;
std::cout << "Time Detector: " << tdet << " ms" << std::endl;
std::cout << "Time Descriptor: " << tdesc << " ms" << std::endl;
// Save keypoints in ASCII format.
if (!kpts_path.empty()) {
if (options.descriptor < libAKAZE::MLDB_UPRIGHT) {
save_keypoints(kpts_path, kpts, desc.float_descriptor, true);
} else {
save_keypoints(kpts_path, kpts, desc.binary_descriptor, true);
}
}
// Convert the input image to RGB.
cimg_library::CImg<float> rgb_image =
img.get_resize(img.width(), img.height(), img.depth(), 3);
draw_keypoints(rgb_image, kpts);
rgb_image.save("../output/detected_features.jpg");
}
/* ************************************************************************* */
int parse_input_options(libAKAZE::AKAZEOptions& options, std::string& img_path,
std::string& kpts_path, int argc, char* argv[]) {
// If there is only one argument return
if (argc < 2) {
show_input_options_help(0);
return -1;
}
// Set the options from the command line
else if (argc >= 3) {
options = libAKAZE::AKAZEOptions();
kpts_path = "./keypoints.txt";
if (!strcmp(argv[1], "--help")) {
show_input_options_help(0);
return -1;
}
img_path = argv[1];
for (int i = 3; i < argc; i++) {
if (!strcmp(argv[i], "--num_threads")) {
i = i + 1;
options.num_threads = atoi(argv[i]);
} else if (!strcmp(argv[i], "--soffset")) {
i = i + 1;
if (i >= argc) {
std::cerr << "Error introducing input options!!" << std::endl;
return -1;
} else {
options.soffset = atof(argv[i]);
}
} else if (!strcmp(argv[i], "--omax")) {
i = i + 1;
if (i >= argc) {
std::cerr << "Error introducing input options!!" << std::endl;
return -1;
} else {
options.omax = atof(argv[i]);
}
} else if (!strcmp(argv[i], "--dthreshold")) {
i = i + 1;
if (i >= argc) {
std::cerr << "Error introducing input options!!" << std::endl;
return -1;
} else {
options.dthreshold = atof(argv[i]);
}
} else if (!strcmp(argv[i], "--sderivatives")) {
i = i + 1;
if (i >= argc) {
std::cerr << "Error introducing input options!!" << std::endl;
return -1;
} else {
options.sderivatives = atof(argv[i]);
}
} else if (!strcmp(argv[i], "--nsublevels")) {
i = i + 1;
if (i >= argc) {
std::cerr << "Error introducing input options!!" << std::endl;
return -1;
} else
options.nsublevels = atoi(argv[i]);
} else if (!strcmp(argv[i], "--diffusivity")) {
i = i + 1;
if (i >= argc) {
std::cerr << "Error introducing input options!!" << std::endl;
return -1;
} else
options.diffusivity = libAKAZE::DIFFUSIVITY_TYPE(atoi(argv[i]));
} else if (!strcmp(argv[i], "--descriptor")) {
i = i + 1;
if (i >= argc) {
std::cerr << "Error introducing input options!!" << std::endl;
return -1;
} else {
options.descriptor = libAKAZE::DESCRIPTOR_TYPE(atoi(argv[i]));
if (options.descriptor < 0 || options.descriptor > libAKAZE::MLDB) {
options.descriptor = libAKAZE::MLDB;
}
}
} else if (!strcmp(argv[i], "--descriptor_channels")) {
i = i + 1;
if (i >= argc) {
std::cerr << "Error introducing input options!!" << std::endl;
return -1;
} else {
options.descriptor_channels = atoi(argv[i]);
if (options.descriptor_channels <= 0 ||
options.descriptor_channels > 3) {
options.descriptor_channels = 3;
}
}
} else if (!strcmp(argv[i],"--descriptor_size")) {
i = i+1;
if (i >= argc) {
std::cerr << "Error introducing input options!!" << std::endl;
return -1;
}
else {
options.descriptor_size = atoi(argv[i]);
if (options.descriptor_size < 0) {
options.descriptor_size = 0;
}
}
} else if (!strcmp(argv[i], "--save_scale_space")) {
i = i + 1;
if (i >= argc) {
std::cerr << "Error introducing input options!!" << std::endl;
return -1;
} else {
options.save_scale_space = (bool)atoi(argv[i]);
}
} else if (!strcmp(argv[i], "--verbose")) {
options.verbosity = true;
} else if (!strcmp(argv[i], "--output")) {
options.save_keypoints = true;
i = i + 1;
if (i >= argc) {
std::cerr << "Error introducing input options!!" << std::endl;
return -1;
} else
kpts_path = argv[i];
}
}
}
return 0;
}