Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/features2d/src/kaze.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] KAZE Features. Pablo F. Alcantarilla, Adrien Bartoli and Andrew J. Davison.
45
In European Conference on Computer Vision (ECCV), Fiorenze, Italy, October 2012
46
http://www.robesafe.com/personal/pablo.alcantarilla/papers/Alcantarilla12eccv.pdf
47
@author Eugene Khvedchenya <[email protected]>
48
*/
49
50
#include "precomp.hpp"
51
#include "kaze/KAZEFeatures.h"
52
53
namespace cv
54
{
55
56
class KAZE_Impl CV_FINAL : public KAZE
57
{
58
public:
59
KAZE_Impl(bool _extended, bool _upright, float _threshold, int _octaves,
60
int _sublevels, KAZE::DiffusivityType _diffusivity)
61
: extended(_extended)
62
, upright(_upright)
63
, threshold(_threshold)
64
, octaves(_octaves)
65
, sublevels(_sublevels)
66
, diffusivity(_diffusivity)
67
{
68
}
69
70
virtual ~KAZE_Impl() CV_OVERRIDE {}
71
72
void setExtended(bool extended_) CV_OVERRIDE { extended = extended_; }
73
bool getExtended() const CV_OVERRIDE { return extended; }
74
75
void setUpright(bool upright_) CV_OVERRIDE { upright = upright_; }
76
bool getUpright() const CV_OVERRIDE { return upright; }
77
78
void setThreshold(double threshold_) CV_OVERRIDE { threshold = (float)threshold_; }
79
double getThreshold() const CV_OVERRIDE { return threshold; }
80
81
void setNOctaves(int octaves_) CV_OVERRIDE { octaves = octaves_; }
82
int getNOctaves() const CV_OVERRIDE { return octaves; }
83
84
void setNOctaveLayers(int octaveLayers_) CV_OVERRIDE { sublevels = octaveLayers_; }
85
int getNOctaveLayers() const CV_OVERRIDE { return sublevels; }
86
87
void setDiffusivity(KAZE::DiffusivityType diff_) CV_OVERRIDE{ diffusivity = diff_; }
88
KAZE::DiffusivityType getDiffusivity() const CV_OVERRIDE{ return diffusivity; }
89
90
// returns the descriptor size in bytes
91
int descriptorSize() const CV_OVERRIDE
92
{
93
return extended ? 128 : 64;
94
}
95
96
// returns the descriptor type
97
int descriptorType() const CV_OVERRIDE
98
{
99
return CV_32F;
100
}
101
102
// returns the default norm type
103
int defaultNorm() const CV_OVERRIDE
104
{
105
return NORM_L2;
106
}
107
108
void detectAndCompute(InputArray image, InputArray mask,
109
std::vector<KeyPoint>& keypoints,
110
OutputArray descriptors,
111
bool useProvidedKeypoints) CV_OVERRIDE
112
{
113
CV_INSTRUMENT_REGION();
114
115
cv::Mat img = image.getMat();
116
if (img.channels() > 1)
117
cvtColor(image, img, COLOR_BGR2GRAY);
118
119
Mat img1_32;
120
if ( img.depth() == CV_32F )
121
img1_32 = img;
122
else if ( img.depth() == CV_8U )
123
img.convertTo(img1_32, CV_32F, 1.0 / 255.0, 0);
124
else if ( img.depth() == CV_16U )
125
img.convertTo(img1_32, CV_32F, 1.0 / 65535.0, 0);
126
127
CV_Assert( ! img1_32.empty() );
128
129
KAZEOptions options;
130
options.img_width = img.cols;
131
options.img_height = img.rows;
132
options.extended = extended;
133
options.upright = upright;
134
options.dthreshold = threshold;
135
options.omax = octaves;
136
options.nsublevels = sublevels;
137
options.diffusivity = diffusivity;
138
139
KAZEFeatures impl(options);
140
impl.Create_Nonlinear_Scale_Space(img1_32);
141
142
if (!useProvidedKeypoints)
143
{
144
impl.Feature_Detection(keypoints);
145
}
146
147
if (!mask.empty())
148
{
149
cv::KeyPointsFilter::runByPixelsMask(keypoints, mask.getMat());
150
}
151
152
if( descriptors.needed() )
153
{
154
Mat desc;
155
impl.Feature_Description(keypoints, desc);
156
desc.copyTo(descriptors);
157
158
CV_Assert((!desc.rows || desc.cols == descriptorSize()));
159
CV_Assert((!desc.rows || (desc.type() == descriptorType())));
160
}
161
}
162
163
void write(FileStorage& fs) const CV_OVERRIDE
164
{
165
writeFormat(fs);
166
fs << "extended" << (int)extended;
167
fs << "upright" << (int)upright;
168
fs << "threshold" << threshold;
169
fs << "octaves" << octaves;
170
fs << "sublevels" << sublevels;
171
fs << "diffusivity" << diffusivity;
172
}
173
174
void read(const FileNode& fn) CV_OVERRIDE
175
{
176
extended = (int)fn["extended"] != 0;
177
upright = (int)fn["upright"] != 0;
178
threshold = (float)fn["threshold"];
179
octaves = (int)fn["octaves"];
180
sublevels = (int)fn["sublevels"];
181
diffusivity = static_cast<KAZE::DiffusivityType>((int)fn["diffusivity"]);
182
}
183
184
bool extended;
185
bool upright;
186
float threshold;
187
int octaves;
188
int sublevels;
189
KAZE::DiffusivityType diffusivity;
190
};
191
192
Ptr<KAZE> KAZE::create(bool extended, bool upright,
193
float threshold,
194
int octaves, int sublevels,
195
KAZE::DiffusivityType diffusivity)
196
{
197
return makePtr<KAZE_Impl>(extended, upright, threshold, octaves, sublevels, diffusivity);
198
}
199
200
String KAZE::getDefaultName() const
201
{
202
return (Feature2D::getDefaultName() + ".KAZE");
203
}
204
205
}
206
207