-
-
Notifications
You must be signed in to change notification settings - Fork 874
Expand file tree
/
Copy pathImageDescriber_AKAZE.hpp
More file actions
187 lines (169 loc) · 5.31 KB
/
ImageDescriber_AKAZE.hpp
File metadata and controls
187 lines (169 loc) · 5.31 KB
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
// This file is part of the AliceVision project.
// Copyright (c) 2016 AliceVision contributors.
// Copyright (c) 2012 openMVG contributors.
// This Source Code Form is subject to the terms of the Mozilla Public License,
// v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.
#pragma once
#include <aliceVision/config.hpp>
#include <aliceVision/feature/ImageDescriber.hpp>
#include <aliceVision/feature/imageDescriberCommon.hpp>
#include <aliceVision/feature/regionsFactory.hpp>
#include <aliceVision/feature/akaze/AKAZE.hpp>
#include <aliceVision/feature/akaze/descriptorLIOP.hpp>
#include <aliceVision/feature/akaze/descriptorMLDB.hpp>
#include <aliceVision/feature/akaze/descriptorMSURF.hpp>
namespace aliceVision {
namespace feature {
enum EAKAZE_DESCRIPTOR
{
AKAZE_MSURF,
AKAZE_LIOP,
AKAZE_MLDB
};
struct AKAZEParams
{
AKAZEParams(AKAZEOptions akazeOptions = AKAZEOptions(), EAKAZE_DESCRIPTOR eAkazeDescriptor = AKAZE_MSURF)
: options(akazeOptions)
, akazeDescriptorType(eAkazeDescriptor)
{}
// parameters
AKAZEOptions options;
EAKAZE_DESCRIPTOR akazeDescriptorType;
};
class ImageDescriber_AKAZE : public ImageDescriber
{
public:
explicit ImageDescriber_AKAZE(const AKAZEParams& params = AKAZEParams(), bool isOriented = true)
: ImageDescriber()
, _params(params)
, _isOriented(isOriented)
{}
/**
* @brief Check if the image describer use CUDA
* @return True if the image describer use CUDA
*/
bool useCuda() const override
{
return false;
}
/**
* @brief Check if the image describer use float image
* @return True if the image describer use float image
*/
bool useFloatImage() const override
{
return true;
}
/**
* @brief Get the corresponding EImageDescriberType
* @return EImageDescriberType
*/
virtual EImageDescriberType getDescriberType() const override
{
switch(_params.akazeDescriptorType)
{
case AKAZE_MSURF: return EImageDescriberType::AKAZE;
case AKAZE_LIOP: return EImageDescriberType::AKAZE_LIOP;
case AKAZE_MLDB: return EImageDescriberType::AKAZE_MLDB;
}
throw std::logic_error("Unknown AKAZE type.");
}
/**
* @brief Get the total amount of RAM needed for a
* feature extraction of an image of the given dimension.
* @param[in] width The image width
* @param[in] height The image height
* @return total amount of memory needed
*/
std::size_t getMemoryConsumption(std::size_t width, std::size_t height) const override
{
std::size_t fullImgSize = width * height;
std::size_t memoryConsuption = 0;
double downscale = 1.0;
for(int octave = 0; octave < _params.options.nbOctaves; ++octave)
{
memoryConsuption += fullImgSize / (downscale * downscale);
downscale *= 2.0;
}
memoryConsuption *= _params.options.nbSlicePerOctave * sizeof(float);
return 4 * memoryConsuption + (3 * width * height * sizeof(float)) + 1.5 * std::pow(2,30); // add arbitrary 1.5 GB
}
/**
* @brief Set image describer always upRight
* @param[in] upRight
*/
void setUpRight(bool upRight) override
{
_isOriented = !upRight;
}
/**
* @brief Use a preset to control the number of detected regions
* @param[in] preset The preset configuration
*/
void setConfigurationPreset(EImageDescriberPreset preset) override
{
switch(preset)
{
case EImageDescriberPreset::LOW:
{
_params.options.maxTotalKeypoints = 1000;
break;
}
case EImageDescriberPreset::MEDIUM:
{
_params.options.maxTotalKeypoints = 5000;
break;
}
case EImageDescriberPreset::NORMAL:
{
_params.options.maxTotalKeypoints = 10000;
_params.options.threshold = AKAZEOptions().threshold;
break;
}
case EImageDescriberPreset::HIGH:
{
_params.options.maxTotalKeypoints = 50000;
_params.options.threshold = AKAZEOptions().threshold / 10.f;
break;
}
case EImageDescriberPreset::ULTRA:
{
_params.options.maxTotalKeypoints = 100000;
_params.options.threshold = AKAZEOptions().threshold / 100.f;
break;
}
default:
throw std::out_of_range("Invalid image describer preset enum");
}
}
/**
* @brief Detect regions on the float image and compute their attributes (description)
* @param[in] image Image.
* @param[out] regions The detected regions and attributes
* @param[in] mask 8-bit grayscale image for keypoint filtering (optional)
* Non-zero values depict the region of interest.
*/
bool describe(const image::Image<float>& image,
std::unique_ptr<Regions>& regions,
const image::Image<unsigned char> * mask = nullptr) override;
/**
* @brief Allocate Regions type depending of the ImageDescriber
* @param[in,out] regions
*/
void allocate(std::unique_ptr<Regions>& regions) const override
{
switch(_params.akazeDescriptorType)
{
case AKAZE_MSURF: regions.reset(new AKAZE_Float_Regions); break;
case AKAZE_LIOP: regions.reset(new AKAZE_Liop_Regions); break;
case AKAZE_MLDB: regions.reset(new AKAZE_BinaryRegions); break;
}
}
~ImageDescriber_AKAZE() override = default;
private:
AKAZEParams _params;
bool _isOriented = true;
};
} // namespace feature
} // namespace aliceVision