MRPT  1.9.9
CFeatureExtraction_common.cpp
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2019, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in https://www.mrpt.org/License |
8  +---------------------------------------------------------------------------+
9  */
10 
11 #include "vision-precomp.h" // Precompiled headers
12 
14 #include <mrpt/system/CTicTac.h>
16 
17 using namespace mrpt;
18 using namespace mrpt::img;
19 using namespace mrpt::vision;
20 using namespace mrpt::img;
21 using namespace mrpt::system;
22 using namespace std;
23 
24 struct sort_pred
25 {
26  bool operator()(
27  const std::vector<unsigned int>& left,
28  const std::vector<unsigned int>& right)
29  {
30  return left[1] < right[1];
31  }
32 };
33 
34 /************************************************************************************************
35  * extractFeatures *
36  ************************************************************************************************/
37 void CFeatureExtraction::detectFeatures(
38  const CImage& img, CFeatureList& feats, const unsigned int init_ID,
39  const unsigned int nDesiredFeatures, const TImageROI& ROI)
40 {
41  CTimeLoggerEntry tle(profiler, "detectFeatures");
42 
43  switch (options.featsType)
44  {
45  case featHarris:
46  extractFeaturesKLT(img, feats, init_ID, nDesiredFeatures, ROI);
47  break;
48 
49  case featKLT:
50  extractFeaturesKLT(img, feats, init_ID, nDesiredFeatures, ROI);
51  break;
52 
53  case featSIFT:
54  extractFeaturesSIFT(img, feats, init_ID, nDesiredFeatures, ROI);
55  break;
56 
57  case featSURF:
58  extractFeaturesSURF(img, feats, init_ID, nDesiredFeatures, ROI);
59  break;
60 
61  case featFAST:
62  extractFeaturesFAST(img, feats, init_ID, nDesiredFeatures);
63  break;
64 
65  case featFASTER9:
66  extractFeaturesFASTER_N(
67  9, img, feats, init_ID, nDesiredFeatures, ROI);
68  break;
69  case featFASTER10:
70  extractFeaturesFASTER_N(
71  10, img, feats, init_ID, nDesiredFeatures, ROI);
72  break;
73  case featFASTER12:
74  extractFeaturesFASTER_N(
75  12, img, feats, init_ID, nDesiredFeatures, ROI);
76  break;
77 
78  case featORB:
79  extractFeaturesORB(img, feats, init_ID, nDesiredFeatures, ROI);
80  break;
81 
82  // # added by Raghavender Sahdev
83  case featAKAZE:
84  extractFeaturesAKAZE(img, feats, init_ID, nDesiredFeatures, ROI);
85  break;
86  case featLSD:
87  extractFeaturesLSD(img, feats, init_ID, nDesiredFeatures, ROI);
88  break;
89 
90  default:
91  THROW_EXCEPTION("options.method has an invalid value!");
92  break;
93  }
94 }
95 
96 /************************************************************************************************
97  computeDescriptors
98 ************************************************************************************************/
99 void CFeatureExtraction::computeDescriptors(
100  const CImage& in_img, CFeatureList& inout_features,
101  TDescriptorType in_descriptor_list)
102 {
103  MRPT_START
104  CTimeLoggerEntry tle(profiler, "computeDescriptors");
105 
106  int nDescComputed = 0;
107 
108  if ((in_descriptor_list & descSIFT) != 0)
109  {
110  this->internal_computeSiftDescriptors(in_img, inout_features);
111  ++nDescComputed;
112  }
113  if ((in_descriptor_list & descSURF) != 0)
114  {
115  this->internal_computeSurfDescriptors(in_img, inout_features);
116  ++nDescComputed;
117  }
118  if ((in_descriptor_list & descSpinImages) != 0)
119  {
120  this->internal_computeSpinImageDescriptors(in_img, inout_features);
121  ++nDescComputed;
122  }
123  if ((in_descriptor_list & descPolarImages) != 0)
124  {
125  this->internal_computePolarImageDescriptors(in_img, inout_features);
126  ++nDescComputed;
127  }
128  if ((in_descriptor_list & descLogPolarImages) != 0)
129  {
130  this->internal_computeLogPolarImageDescriptors(in_img, inout_features);
131  ++nDescComputed;
132  }
133  if ((in_descriptor_list & descORB) != 0)
134  {
135  this->internal_computeORBDescriptors(in_img, inout_features);
136  ++nDescComputed;
137  }
138  // # added by Raghavender Sahdev
139  if ((in_descriptor_list & descBLD) != 0)
140  {
141  this->internal_computeBLDLineDescriptors(in_img, inout_features);
142  ++nDescComputed;
143  }
144  if ((in_descriptor_list & descLATCH) != 0)
145  {
146  this->internal_computeLATCHDescriptors(in_img, inout_features);
147  ++nDescComputed;
148  }
149  if (!nDescComputed)
151  "No known descriptor value found in in_descriptor_list=%u",
152  (unsigned)in_descriptor_list);
153 
154  MRPT_END
155 }
156 
157 void CFeatureExtraction::TOptions::dumpToTextStream(std::ostream& out) const
158 {
159  out << "\n----------- [CFeatureExtraction::TOptions] ------------ \n\n";
160 
161  LOADABLEOPTS_DUMP_VAR(featsType, int)
162  LOADABLEOPTS_DUMP_VAR(patchSize, int)
163  LOADABLEOPTS_DUMP_VAR(FIND_SUBPIXEL, bool)
164  LOADABLEOPTS_DUMP_VAR(useMask, bool)
165  LOADABLEOPTS_DUMP_VAR(addNewFeatures, bool)
166 
167  LOADABLEOPTS_DUMP_VAR(harrisOptions.k, double)
168  LOADABLEOPTS_DUMP_VAR(harrisOptions.radius, int)
169  LOADABLEOPTS_DUMP_VAR(harrisOptions.threshold, float)
170  LOADABLEOPTS_DUMP_VAR(harrisOptions.sigma, float)
171  LOADABLEOPTS_DUMP_VAR(harrisOptions.min_distance, float)
172 
173  LOADABLEOPTS_DUMP_VAR(KLTOptions.min_distance, float)
174  LOADABLEOPTS_DUMP_VAR(KLTOptions.threshold, float)
175  LOADABLEOPTS_DUMP_VAR(KLTOptions.radius, int)
176 
177  LOADABLEOPTS_DUMP_VAR(SIFTOptions.implementation, int)
178 
179  LOADABLEOPTS_DUMP_VAR(SURFOptions.rotation_invariant, bool)
180  LOADABLEOPTS_DUMP_VAR(SURFOptions.hessianThreshold, int)
181  LOADABLEOPTS_DUMP_VAR(SURFOptions.nOctaves, int)
182  LOADABLEOPTS_DUMP_VAR(SURFOptions.nLayersPerOctave, int)
183 
184  LOADABLEOPTS_DUMP_VAR(FASTOptions.threshold, int)
185  LOADABLEOPTS_DUMP_VAR(FASTOptions.nonmax_suppression, bool)
186  LOADABLEOPTS_DUMP_VAR(FASTOptions.min_distance, float)
187  LOADABLEOPTS_DUMP_VAR(FASTOptions.use_KLT_response, bool)
188 
189  LOADABLEOPTS_DUMP_VAR(ORBOptions.scale_factor, float)
190  LOADABLEOPTS_DUMP_VAR(ORBOptions.min_distance, int)
191  LOADABLEOPTS_DUMP_VAR(ORBOptions.n_levels, int)
192  LOADABLEOPTS_DUMP_VAR(ORBOptions.extract_patch, bool)
193 
194  LOADABLEOPTS_DUMP_VAR(SpinImagesOptions.hist_size_distance, int)
195  LOADABLEOPTS_DUMP_VAR(SpinImagesOptions.hist_size_intensity, int)
196  LOADABLEOPTS_DUMP_VAR(SpinImagesOptions.radius, int)
197  LOADABLEOPTS_DUMP_VAR(SpinImagesOptions.std_dist, float)
198  LOADABLEOPTS_DUMP_VAR(SpinImagesOptions.std_intensity, float)
199 
200  LOADABLEOPTS_DUMP_VAR(PolarImagesOptions.bins_angle, int)
201  LOADABLEOPTS_DUMP_VAR(PolarImagesOptions.bins_distance, int)
202  LOADABLEOPTS_DUMP_VAR(PolarImagesOptions.radius, int)
203 
204  LOADABLEOPTS_DUMP_VAR(LogPolarImagesOptions.radius, int)
205  LOADABLEOPTS_DUMP_VAR(LogPolarImagesOptions.num_angles, int)
206  LOADABLEOPTS_DUMP_VAR(LogPolarImagesOptions.rho_scale, double)
207 
208  // # added by Raghavender Sahdev
209  LOADABLEOPTS_DUMP_VAR(AKAZEOptions.descriptor_type, int)
210  LOADABLEOPTS_DUMP_VAR(AKAZEOptions.descriptor_size, int)
211  LOADABLEOPTS_DUMP_VAR(AKAZEOptions.descriptor_channels, int)
212  LOADABLEOPTS_DUMP_VAR(AKAZEOptions.threshold, float)
213  LOADABLEOPTS_DUMP_VAR(AKAZEOptions.nOctaves, int)
214  LOADABLEOPTS_DUMP_VAR(AKAZEOptions.nOctaveLayers, int)
215  LOADABLEOPTS_DUMP_VAR(AKAZEOptions.diffusivity, int)
216 
217  LOADABLEOPTS_DUMP_VAR(LSDOptions.nOctaves, int)
218  LOADABLEOPTS_DUMP_VAR(LSDOptions.scale, int)
219 
220  LOADABLEOPTS_DUMP_VAR(BLDOptions.numOfOctave, int)
221  LOADABLEOPTS_DUMP_VAR(BLDOptions.reductionRatio, int)
222  LOADABLEOPTS_DUMP_VAR(BLDOptions.widthOfBand, int)
223 
224  LOADABLEOPTS_DUMP_VAR(LATCHOptions.bytes, int)
225  LOADABLEOPTS_DUMP_VAR(LATCHOptions.half_ssd_size, int)
226  LOADABLEOPTS_DUMP_VAR(LATCHOptions.rotationInvariance, bool)
227 
228  out << "\n";
229 }
230 
231 /*---------------------------------------------------------------
232  loadFromConfigFile
233  ---------------------------------------------------------------*/
234 void CFeatureExtraction::TOptions::loadFromConfigFile(
235  const mrpt::config::CConfigFileBase& iniFile, const std::string& section)
236 {
237  featsType = iniFile.read_enum(section, "featsType", featsType);
238 
239  MRPT_LOAD_CONFIG_VAR(patchSize, int, iniFile, section)
240  MRPT_LOAD_CONFIG_VAR(FIND_SUBPIXEL, bool, iniFile, section)
241  MRPT_LOAD_CONFIG_VAR(useMask, bool, iniFile, section)
242  MRPT_LOAD_CONFIG_VAR(addNewFeatures, bool, iniFile, section)
243 
244  // string sect = section;
245  MRPT_LOAD_CONFIG_VAR(harrisOptions.k, double, iniFile, section)
246  MRPT_LOAD_CONFIG_VAR(harrisOptions.radius, int, iniFile, section)
247  MRPT_LOAD_CONFIG_VAR(harrisOptions.threshold, float, iniFile, section)
248  MRPT_LOAD_CONFIG_VAR(harrisOptions.sigma, float, iniFile, section)
249  MRPT_LOAD_CONFIG_VAR(harrisOptions.min_distance, float, iniFile, section)
250 
251  MRPT_LOAD_CONFIG_VAR(KLTOptions.min_distance, float, iniFile, section)
252  MRPT_LOAD_CONFIG_VAR(KLTOptions.threshold, float, iniFile, section)
253  MRPT_LOAD_CONFIG_VAR(KLTOptions.radius, int, iniFile, section)
254 
256  SIFTOptions.implementation, int, TSIFTImplementation, iniFile, section)
257  MRPT_LOAD_CONFIG_VAR(SIFTOptions.threshold, double, iniFile, section)
258  MRPT_LOAD_CONFIG_VAR(SIFTOptions.edgeThreshold, double, iniFile, section)
259 
260  MRPT_LOAD_CONFIG_VAR(SURFOptions.rotation_invariant, bool, iniFile, section)
261  MRPT_LOAD_CONFIG_VAR(SURFOptions.hessianThreshold, int, iniFile, section)
262  MRPT_LOAD_CONFIG_VAR(SURFOptions.nOctaves, int, iniFile, section)
263  MRPT_LOAD_CONFIG_VAR(SURFOptions.nLayersPerOctave, int, iniFile, section)
264 
265  MRPT_LOAD_CONFIG_VAR(FASTOptions.threshold, int, iniFile, section)
266  MRPT_LOAD_CONFIG_VAR(FASTOptions.nonmax_suppression, bool, iniFile, section)
267  MRPT_LOAD_CONFIG_VAR(FASTOptions.min_distance, float, iniFile, section)
268  MRPT_LOAD_CONFIG_VAR(FASTOptions.use_KLT_response, bool, iniFile, section)
269 
270  MRPT_LOAD_CONFIG_VAR(ORBOptions.extract_patch, bool, iniFile, section)
271  MRPT_LOAD_CONFIG_VAR(ORBOptions.min_distance, int, iniFile, section)
272  MRPT_LOAD_CONFIG_VAR(ORBOptions.n_levels, int, iniFile, section)
273  MRPT_LOAD_CONFIG_VAR(ORBOptions.scale_factor, float, iniFile, section)
274 
276  SpinImagesOptions.hist_size_distance, int, iniFile, section)
278  SpinImagesOptions.hist_size_intensity, int, iniFile, section)
279  MRPT_LOAD_CONFIG_VAR(SpinImagesOptions.radius, int, iniFile, section)
280  MRPT_LOAD_CONFIG_VAR(SpinImagesOptions.std_dist, float, iniFile, section)
282  SpinImagesOptions.std_intensity, float, iniFile, section)
283 
284  MRPT_LOAD_CONFIG_VAR(PolarImagesOptions.bins_angle, int, iniFile, section)
286  PolarImagesOptions.bins_distance, int, iniFile, section)
287  MRPT_LOAD_CONFIG_VAR(PolarImagesOptions.radius, int, iniFile, section)
288 
289  MRPT_LOAD_CONFIG_VAR(LogPolarImagesOptions.radius, int, iniFile, section)
291  LogPolarImagesOptions.num_angles, int, iniFile, section)
293  LogPolarImagesOptions.rho_scale, double, iniFile, section)
294 
295  // #added by Raghavender Sahdev
296  MRPT_LOAD_CONFIG_VAR(AKAZEOptions.descriptor_type, int, iniFile, section)
297  MRPT_LOAD_CONFIG_VAR(AKAZEOptions.descriptor_size, int, iniFile, section)
299  AKAZEOptions.descriptor_channels, int, iniFile, section)
300  MRPT_LOAD_CONFIG_VAR(AKAZEOptions.threshold, float, iniFile, section)
301  MRPT_LOAD_CONFIG_VAR(AKAZEOptions.nOctaves, int, iniFile, section)
302  MRPT_LOAD_CONFIG_VAR(AKAZEOptions.nOctaveLayers, int, iniFile, section)
303  MRPT_LOAD_CONFIG_VAR(AKAZEOptions.diffusivity, int, iniFile, section)
304 
305  MRPT_LOAD_CONFIG_VAR(LSDOptions.nOctaves, int, iniFile, section)
306  MRPT_LOAD_CONFIG_VAR(LSDOptions.scale, int, iniFile, section)
307 
308  MRPT_LOAD_CONFIG_VAR(BLDOptions.numOfOctave, int, iniFile, section)
309  MRPT_LOAD_CONFIG_VAR(BLDOptions.widthOfBand, int, iniFile, section)
310  MRPT_LOAD_CONFIG_VAR(BLDOptions.reductionRatio, int, iniFile, section)
311 
312  MRPT_LOAD_CONFIG_VAR(LATCHOptions.bytes, int, iniFile, section)
313  MRPT_LOAD_CONFIG_VAR(LATCHOptions.half_ssd_size, int, iniFile, section)
315  LATCHOptions.rotationInvariance, bool, iniFile, section)
316 }
#define MRPT_START
Definition: exceptions.h:241
#define THROW_EXCEPTION(msg)
Definition: exceptions.h:67
A safe way to call enter() and leave() of a mrpt::system::CTimeLogger upon construction and destructi...
Intensity-domain spin image descriptors.
Bit-based feature descriptor.
Scale Invariant Feature Transform [LOWE&#39;04].
STL namespace.
LSD detector, OpenCV&#39;s implementation.
bool operator()(const std::vector< unsigned int > &left, const std::vector< unsigned int > &right)
A structure for defining a ROI within an image.
This class allows loading and storing values and vectors of different types from a configuration text...
GLint GLvoid * img
Definition: glext.h:3769
TDescriptorType
The bitwise OR combination of values of TDescriptorType are used in CFeatureExtraction::computeDescri...
string iniFile(myDataDir+string("benchmark-options.ini"))
Classes for computer vision, detectors, features, etc.
Definition: CDifodo.h:17
Speeded Up Robust Feature [BAY&#39;06].
GLsizei const GLchar ** string
Definition: glext.h:4116
FAST feature detector, OpenCV&#39;s implementation ("Faster and better: A machine learning approach to...
FASTER-9 detector, Edward Rosten&#39;s libcvd, SSE2 optimized.
A list of visual features, to be used as output by detectors, as input/output by trackers, etc.
Definition: CFeature.h:275
#define LOADABLEOPTS_DUMP_VAR(variableName, variableType)
Macro for dumping a variable to a stream, within the method "dumpToTextStream(out)" (Variable types a...
#define MRPT_LOAD_CONFIG_VAR( variableName, variableType, configFileObject, sectionNameStr)
An useful macro for loading variables stored in a INI-like file under a key with the same name that t...
AKAZE detector, OpenCV&#39;s implementation.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
FASTER-9 detector, Edward Rosten&#39;s libcvd, SSE2 optimized.
Harris border and corner detector [HARRIS].
#define MRPT_END
Definition: exceptions.h:245
Kanade-Lucas-Tomasi feature [SHI&#39;94].
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
Definition: exceptions.h:69
ORB detector and descriptor, OpenCV&#39;s implementation.
#define MRPT_LOAD_CONFIG_VAR_CAST( variableName, variableType, variableTypeCast, configFileObject, sectionNameStr)
A class for storing images as grayscale or RGB bitmaps.
Definition: img/CImage.h:147
FASTER-9 detector, Edward Rosten&#39;s libcvd, SSE2 optimized.



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: abb8b1a1e Fri Oct 18 14:19:12 2019 +0200 at vie oct 18 14:20:13 CEST 2019