Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/features2d/src/feature2d.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) 2000-2008, Intel Corporation, all rights reserved.
14
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15
// Third party copyrights are property of their respective owners.
16
//
17
// Redistribution and use in source and binary forms, with or without modification,
18
// are permitted provided that the following conditions are met:
19
//
20
// * Redistribution's of source code must retain the above copyright notice,
21
// this list of conditions and the following disclaimer.
22
//
23
// * Redistribution's in binary form must reproduce the above copyright notice,
24
// this list of conditions and the following disclaimer in the documentation
25
// and/or other materials provided with the distribution.
26
//
27
// * The name of the copyright holders may not be used to endorse or promote products
28
// derived from this software without specific prior written permission.
29
//
30
// This software is provided by the copyright holders and contributors "as is" and
31
// any express or implied warranties, including, but not limited to, the implied
32
// warranties of merchantability and fitness for a particular purpose are disclaimed.
33
// In no event shall the Intel Corporation or contributors be liable for any direct,
34
// indirect, incidental, special, exemplary, or consequential damages
35
// (including, but not limited to, procurement of substitute goods or services;
36
// loss of use, data, or profits; or business interruption) however caused
37
// and on any theory of liability, whether in contract, strict liability,
38
// or tort (including negligence or otherwise) arising in any way out of
39
// the use of this software, even if advised of the possibility of such damage.
40
//
41
//M*/
42
43
#include "precomp.hpp"
44
45
namespace cv
46
{
47
48
using std::vector;
49
50
Feature2D::~Feature2D() {}
51
52
/*
53
* Detect keypoints in an image.
54
* image The image.
55
* keypoints The detected keypoints.
56
* mask Mask specifying where to look for keypoints (optional). Must be a char
57
* matrix with non-zero values in the region of interest.
58
*/
59
void Feature2D::detect( InputArray image,
60
std::vector<KeyPoint>& keypoints,
61
InputArray mask )
62
{
63
CV_INSTRUMENT_REGION();
64
65
if( image.empty() )
66
{
67
keypoints.clear();
68
return;
69
}
70
detectAndCompute(image, mask, keypoints, noArray(), false);
71
}
72
73
74
void Feature2D::detect( InputArrayOfArrays _images,
75
std::vector<std::vector<KeyPoint> >& keypoints,
76
InputArrayOfArrays _masks )
77
{
78
CV_INSTRUMENT_REGION();
79
80
vector<Mat> images, masks;
81
82
_images.getMatVector(images);
83
size_t i, nimages = images.size();
84
85
if( !_masks.empty() )
86
{
87
_masks.getMatVector(masks);
88
CV_Assert(masks.size() == nimages);
89
}
90
91
keypoints.resize(nimages);
92
93
for( i = 0; i < nimages; i++ )
94
{
95
detect(images[i], keypoints[i], masks.empty() ? Mat() : masks[i] );
96
}
97
}
98
99
/*
100
* Compute the descriptors for a set of keypoints in an image.
101
* image The image.
102
* keypoints The input keypoints. Keypoints for which a descriptor cannot be computed are removed.
103
* descriptors Copmputed descriptors. Row i is the descriptor for keypoint i.
104
*/
105
void Feature2D::compute( InputArray image,
106
std::vector<KeyPoint>& keypoints,
107
OutputArray descriptors )
108
{
109
CV_INSTRUMENT_REGION();
110
111
if( image.empty() )
112
{
113
descriptors.release();
114
return;
115
}
116
detectAndCompute(image, noArray(), keypoints, descriptors, true);
117
}
118
119
void Feature2D::compute( InputArrayOfArrays _images,
120
std::vector<std::vector<KeyPoint> >& keypoints,
121
OutputArrayOfArrays _descriptors )
122
{
123
CV_INSTRUMENT_REGION();
124
125
if( !_descriptors.needed() )
126
return;
127
128
vector<Mat> images;
129
130
_images.getMatVector(images);
131
size_t i, nimages = images.size();
132
133
CV_Assert( keypoints.size() == nimages );
134
CV_Assert( _descriptors.kind() == _InputArray::STD_VECTOR_MAT );
135
136
vector<Mat>& descriptors = *(vector<Mat>*)_descriptors.getObj();
137
descriptors.resize(nimages);
138
139
for( i = 0; i < nimages; i++ )
140
{
141
compute(images[i], keypoints[i], descriptors[i]);
142
}
143
}
144
145
146
/* Detects keypoints and computes the descriptors */
147
void Feature2D::detectAndCompute( InputArray, InputArray,
148
std::vector<KeyPoint>&,
149
OutputArray,
150
bool )
151
{
152
CV_INSTRUMENT_REGION();
153
154
CV_Error(Error::StsNotImplemented, "");
155
}
156
157
void Feature2D::write( const String& fileName ) const
158
{
159
FileStorage fs(fileName, FileStorage::WRITE);
160
write(fs);
161
}
162
163
void Feature2D::read( const String& fileName )
164
{
165
FileStorage fs(fileName, FileStorage::READ);
166
read(fs.root());
167
}
168
169
void Feature2D::write( FileStorage&) const
170
{
171
}
172
173
void Feature2D::read( const FileNode&)
174
{
175
}
176
177
int Feature2D::descriptorSize() const
178
{
179
return 0;
180
}
181
182
int Feature2D::descriptorType() const
183
{
184
return CV_32F;
185
}
186
187
int Feature2D::defaultNorm() const
188
{
189
int tp = descriptorType();
190
return tp == CV_8U ? NORM_HAMMING : NORM_L2;
191
}
192
193
// Return true if detector object is empty
194
bool Feature2D::empty() const
195
{
196
return true;
197
}
198
199
String Feature2D::getDefaultName() const
200
{
201
return "Feature2D";
202
}
203
204
}
205
206