Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/features2d/src/akaze.cpp
16337 views
1
/*M///////////////////////////////////////////////////////////////////////////////////////
2
//
3
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4
//
5
// By downloading, copying, installing or using the software you agree to this license.
6
// If you do not agree to this license, do not download, install,
7
// copy or use the software.
8
//
9
//
10
// License Agreement
11
// For Open Source Computer Vision Library
12
//
13
// Copyright (C) 2008, Willow Garage Inc., all rights reserved.
14
// Third party copyrights are property of their respective owners.
15
//
16
// Redistribution and use in source and binary forms, with or without modification,
17
// are permitted provided that the following conditions are met:
18
//
19
// * Redistribution's of source code must retain the above copyright notice,
20
// this list of conditions and the following disclaimer.
21
//
22
// * Redistribution's in binary form must reproduce the above copyright notice,
23
// this list of conditions and the following disclaimer in the documentation
24
// and/or other materials provided with the distribution.
25
//
26
// * The name of Intel Corporation may not be used to endorse or promote products
27
// derived from this software without specific prior written permission.
28
//
29
// This software is provided by the copyright holders and contributors "as is" and
30
// any express or implied warranties, including, but not limited to, the implied
31
// warranties of merchantability and fitness for a particular purpose are disclaimed.
32
// In no event shall the Intel Corporation or contributors be liable for any direct,
33
// indirect, incidental, special, exemplary, or consequential damages
34
// (including, but not limited to, procurement of substitute goods or services;
35
// loss of use, data, or profits; or business interruption) however caused
36
// and on any theory of liability, whether in contract, strict liability,
37
// or tort (including negligence or otherwise) arising in any way out of
38
// the use of this software, even if advised of the possibility of such damage.
39
//
40
//M*/
41
42
/*
43
OpenCV wrapper of reference implementation of
44
[1] Fast Explicit Diffusion for Accelerated Features in Nonlinear Scale Spaces.
45
Pablo F. Alcantarilla, J. Nuevo and Adrien Bartoli.
46
In British Machine Vision Conference (BMVC), Bristol, UK, September 2013
47
http://www.robesafe.com/personal/pablo.alcantarilla/papers/Alcantarilla13bmvc.pdf
48
@author Eugene Khvedchenya <[email protected]>
49
*/
50
51
#include "precomp.hpp"
52
#include "kaze/AKAZEFeatures.h"
53
54
#include <iostream>
55
56
namespace cv
57
{
58
using namespace std;
59
60
class AKAZE_Impl : public AKAZE
61
{
62
public:
63
AKAZE_Impl(DescriptorType _descriptor_type, int _descriptor_size, int _descriptor_channels,
64
float _threshold, int _octaves, int _sublevels, KAZE::DiffusivityType _diffusivity)
65
: descriptor(_descriptor_type)
66
, descriptor_channels(_descriptor_channels)
67
, descriptor_size(_descriptor_size)
68
, threshold(_threshold)
69
, octaves(_octaves)
70
, sublevels(_sublevels)
71
, diffusivity(_diffusivity)
72
{
73
}
74
75
virtual ~AKAZE_Impl() CV_OVERRIDE
76
{
77
78
}
79
80
void setDescriptorType(DescriptorType dtype) CV_OVERRIDE{ descriptor = dtype; }
81
DescriptorType getDescriptorType() const CV_OVERRIDE{ return descriptor; }
82
83
void setDescriptorSize(int dsize) CV_OVERRIDE { descriptor_size = dsize; }
84
int getDescriptorSize() const CV_OVERRIDE { return descriptor_size; }
85
86
void setDescriptorChannels(int dch) CV_OVERRIDE { descriptor_channels = dch; }
87
int getDescriptorChannels() const CV_OVERRIDE { return descriptor_channels; }
88
89
void setThreshold(double threshold_) CV_OVERRIDE { threshold = (float)threshold_; }
90
double getThreshold() const CV_OVERRIDE { return threshold; }
91
92
void setNOctaves(int octaves_) CV_OVERRIDE { octaves = octaves_; }
93
int getNOctaves() const CV_OVERRIDE { return octaves; }
94
95
void setNOctaveLayers(int octaveLayers_) CV_OVERRIDE { sublevels = octaveLayers_; }
96
int getNOctaveLayers() const CV_OVERRIDE { return sublevels; }
97
98
void setDiffusivity(KAZE::DiffusivityType diff_) CV_OVERRIDE{ diffusivity = diff_; }
99
KAZE::DiffusivityType getDiffusivity() const CV_OVERRIDE{ return diffusivity; }
100
101
// returns the descriptor size in bytes
102
int descriptorSize() const CV_OVERRIDE
103
{
104
switch (descriptor)
105
{
106
case DESCRIPTOR_KAZE:
107
case DESCRIPTOR_KAZE_UPRIGHT:
108
return 64;
109
110
case DESCRIPTOR_MLDB:
111
case DESCRIPTOR_MLDB_UPRIGHT:
112
// We use the full length binary descriptor -> 486 bits
113
if (descriptor_size == 0)
114
{
115
int t = (6 + 36 + 120) * descriptor_channels;
116
return divUp(t, 8);
117
}
118
else
119
{
120
// We use the random bit selection length binary descriptor
121
return divUp(descriptor_size, 8);
122
}
123
124
default:
125
return -1;
126
}
127
}
128
129
// returns the descriptor type
130
int descriptorType() const CV_OVERRIDE
131
{
132
switch (descriptor)
133
{
134
case DESCRIPTOR_KAZE:
135
case DESCRIPTOR_KAZE_UPRIGHT:
136
return CV_32F;
137
138
case DESCRIPTOR_MLDB:
139
case DESCRIPTOR_MLDB_UPRIGHT:
140
return CV_8U;
141
142
default:
143
return -1;
144
}
145
}
146
147
// returns the default norm type
148
int defaultNorm() const CV_OVERRIDE
149
{
150
switch (descriptor)
151
{
152
case DESCRIPTOR_KAZE:
153
case DESCRIPTOR_KAZE_UPRIGHT:
154
return NORM_L2;
155
156
case DESCRIPTOR_MLDB:
157
case DESCRIPTOR_MLDB_UPRIGHT:
158
return NORM_HAMMING;
159
160
default:
161
return -1;
162
}
163
}
164
165
void detectAndCompute(InputArray image, InputArray mask,
166
std::vector<KeyPoint>& keypoints,
167
OutputArray descriptors,
168
bool useProvidedKeypoints) CV_OVERRIDE
169
{
170
CV_INSTRUMENT_REGION();
171
172
CV_Assert( ! image.empty() );
173
174
AKAZEOptions options;
175
options.descriptor = descriptor;
176
options.descriptor_channels = descriptor_channels;
177
options.descriptor_size = descriptor_size;
178
options.img_width = image.cols();
179
options.img_height = image.rows();
180
options.dthreshold = threshold;
181
options.omax = octaves;
182
options.nsublevels = sublevels;
183
options.diffusivity = diffusivity;
184
185
AKAZEFeatures impl(options);
186
impl.Create_Nonlinear_Scale_Space(image);
187
188
if (!useProvidedKeypoints)
189
{
190
impl.Feature_Detection(keypoints);
191
}
192
193
if (!mask.empty())
194
{
195
KeyPointsFilter::runByPixelsMask(keypoints, mask.getMat());
196
}
197
198
if(descriptors.needed())
199
{
200
impl.Compute_Descriptors(keypoints, descriptors);
201
202
CV_Assert((descriptors.empty() || descriptors.cols() == descriptorSize()));
203
CV_Assert((descriptors.empty() || (descriptors.type() == descriptorType())));
204
}
205
}
206
207
void write(FileStorage& fs) const CV_OVERRIDE
208
{
209
writeFormat(fs);
210
fs << "descriptor" << descriptor;
211
fs << "descriptor_channels" << descriptor_channels;
212
fs << "descriptor_size" << descriptor_size;
213
fs << "threshold" << threshold;
214
fs << "octaves" << octaves;
215
fs << "sublevels" << sublevels;
216
fs << "diffusivity" << diffusivity;
217
}
218
219
void read(const FileNode& fn) CV_OVERRIDE
220
{
221
descriptor = static_cast<DescriptorType>((int)fn["descriptor"]);
222
descriptor_channels = (int)fn["descriptor_channels"];
223
descriptor_size = (int)fn["descriptor_size"];
224
threshold = (float)fn["threshold"];
225
octaves = (int)fn["octaves"];
226
sublevels = (int)fn["sublevels"];
227
diffusivity = static_cast<KAZE::DiffusivityType>((int)fn["diffusivity"]);
228
}
229
230
DescriptorType descriptor;
231
int descriptor_channels;
232
int descriptor_size;
233
float threshold;
234
int octaves;
235
int sublevels;
236
KAZE::DiffusivityType diffusivity;
237
};
238
239
Ptr<AKAZE> AKAZE::create(DescriptorType descriptor_type,
240
int descriptor_size, int descriptor_channels,
241
float threshold, int octaves,
242
int sublevels, KAZE::DiffusivityType diffusivity)
243
{
244
return makePtr<AKAZE_Impl>(descriptor_type, descriptor_size, descriptor_channels,
245
threshold, octaves, sublevels, diffusivity);
246
}
247
248
String AKAZE::getDefaultName() const
249
{
250
return (Feature2D::getDefaultName() + ".AKAZE");
251
}
252
253
}
254
255