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 << mrpt::format(
160  "\n----------- [CFeatureExtraction::TOptions] ------------ \n\n");
161 
162  LOADABLEOPTS_DUMP_VAR(featsType, int)
163  LOADABLEOPTS_DUMP_VAR(patchSize, int)
164  LOADABLEOPTS_DUMP_VAR(FIND_SUBPIXEL, bool)
165  LOADABLEOPTS_DUMP_VAR(useMask, bool)
166  LOADABLEOPTS_DUMP_VAR(addNewFeatures, bool)
167 
168  LOADABLEOPTS_DUMP_VAR(harrisOptions.k, double)
169  LOADABLEOPTS_DUMP_VAR(harrisOptions.radius, int)
170  LOADABLEOPTS_DUMP_VAR(harrisOptions.threshold, float)
171  LOADABLEOPTS_DUMP_VAR(harrisOptions.sigma, float)
172  LOADABLEOPTS_DUMP_VAR(harrisOptions.min_distance, float)
173 
174  LOADABLEOPTS_DUMP_VAR(KLTOptions.min_distance, float)
175  LOADABLEOPTS_DUMP_VAR(KLTOptions.threshold, float)
176  LOADABLEOPTS_DUMP_VAR(KLTOptions.radius, int)
177 
178  LOADABLEOPTS_DUMP_VAR(SIFTOptions.implementation, int)
179 
180  LOADABLEOPTS_DUMP_VAR(SURFOptions.rotation_invariant, bool)
181  LOADABLEOPTS_DUMP_VAR(SURFOptions.hessianThreshold, int)
182  LOADABLEOPTS_DUMP_VAR(SURFOptions.nOctaves, int)
183  LOADABLEOPTS_DUMP_VAR(SURFOptions.nLayersPerOctave, int)
184 
185  LOADABLEOPTS_DUMP_VAR(FASTOptions.threshold, int)
186  LOADABLEOPTS_DUMP_VAR(FASTOptions.nonmax_suppression, bool)
187  LOADABLEOPTS_DUMP_VAR(FASTOptions.min_distance, float)
188  LOADABLEOPTS_DUMP_VAR(FASTOptions.use_KLT_response, bool)
189 
190  LOADABLEOPTS_DUMP_VAR(ORBOptions.scale_factor, float)
191  LOADABLEOPTS_DUMP_VAR(ORBOptions.min_distance, int)
192  LOADABLEOPTS_DUMP_VAR(ORBOptions.n_levels, int)
193  LOADABLEOPTS_DUMP_VAR(ORBOptions.extract_patch, bool)
194 
195  LOADABLEOPTS_DUMP_VAR(SpinImagesOptions.hist_size_distance, int)
196  LOADABLEOPTS_DUMP_VAR(SpinImagesOptions.hist_size_intensity, int)
197  LOADABLEOPTS_DUMP_VAR(SpinImagesOptions.radius, int)
198  LOADABLEOPTS_DUMP_VAR(SpinImagesOptions.std_dist, float)
199  LOADABLEOPTS_DUMP_VAR(SpinImagesOptions.std_intensity, float)
200 
201  LOADABLEOPTS_DUMP_VAR(PolarImagesOptions.bins_angle, int)
202  LOADABLEOPTS_DUMP_VAR(PolarImagesOptions.bins_distance, int)
203  LOADABLEOPTS_DUMP_VAR(PolarImagesOptions.radius, int)
204 
205  LOADABLEOPTS_DUMP_VAR(LogPolarImagesOptions.radius, int)
206  LOADABLEOPTS_DUMP_VAR(LogPolarImagesOptions.num_angles, int)
207  LOADABLEOPTS_DUMP_VAR(LogPolarImagesOptions.rho_scale, double)
208 
209  // # added by Raghavender Sahdev
210  LOADABLEOPTS_DUMP_VAR(AKAZEOptions.descriptor_type, int)
211  LOADABLEOPTS_DUMP_VAR(AKAZEOptions.descriptor_size, int)
212  LOADABLEOPTS_DUMP_VAR(AKAZEOptions.descriptor_channels, int)
213  LOADABLEOPTS_DUMP_VAR(AKAZEOptions.threshold, float)
214  LOADABLEOPTS_DUMP_VAR(AKAZEOptions.nOctaves, int)
215  LOADABLEOPTS_DUMP_VAR(AKAZEOptions.nOctaveLayers, int)
216  LOADABLEOPTS_DUMP_VAR(AKAZEOptions.diffusivity, int)
217 
218  LOADABLEOPTS_DUMP_VAR(LSDOptions.nOctaves, int)
219  LOADABLEOPTS_DUMP_VAR(LSDOptions.scale, int)
220 
221  LOADABLEOPTS_DUMP_VAR(BLDOptions.numOfOctave, int)
222  LOADABLEOPTS_DUMP_VAR(BLDOptions.reductionRatio, int)
223  LOADABLEOPTS_DUMP_VAR(BLDOptions.widthOfBand, int)
224 
225  LOADABLEOPTS_DUMP_VAR(LATCHOptions.bytes, int)
226  LOADABLEOPTS_DUMP_VAR(LATCHOptions.half_ssd_size, int)
227  LOADABLEOPTS_DUMP_VAR(LATCHOptions.rotationInvariance, bool)
228 
229  out << mrpt::format("\n");
230 }
231 
232 /*---------------------------------------------------------------
233  loadFromConfigFile
234  ---------------------------------------------------------------*/
235 void CFeatureExtraction::TOptions::loadFromConfigFile(
236  const mrpt::config::CConfigFileBase& iniFile, const std::string& section)
237 {
238  featsType = iniFile.read_enum(section, "featsType", featsType);
239 
240  MRPT_LOAD_CONFIG_VAR(patchSize, int, iniFile, section)
241  MRPT_LOAD_CONFIG_VAR(FIND_SUBPIXEL, bool, iniFile, section)
242  MRPT_LOAD_CONFIG_VAR(useMask, bool, iniFile, section)
243  MRPT_LOAD_CONFIG_VAR(addNewFeatures, bool, iniFile, section)
244 
245  // string sect = section;
246  MRPT_LOAD_CONFIG_VAR(harrisOptions.k, double, iniFile, section)
247  MRPT_LOAD_CONFIG_VAR(harrisOptions.radius, int, iniFile, section)
248  MRPT_LOAD_CONFIG_VAR(harrisOptions.threshold, float, iniFile, section)
249  MRPT_LOAD_CONFIG_VAR(harrisOptions.sigma, float, iniFile, section)
250  MRPT_LOAD_CONFIG_VAR(harrisOptions.min_distance, float, iniFile, section)
251 
252  MRPT_LOAD_CONFIG_VAR(KLTOptions.min_distance, float, iniFile, section)
253  MRPT_LOAD_CONFIG_VAR(KLTOptions.threshold, float, iniFile, section)
254  MRPT_LOAD_CONFIG_VAR(KLTOptions.radius, int, iniFile, section)
255 
257  SIFTOptions.implementation, int, TSIFTImplementation, iniFile, section)
258  MRPT_LOAD_CONFIG_VAR(SIFTOptions.threshold, double, iniFile, section)
259  MRPT_LOAD_CONFIG_VAR(SIFTOptions.edgeThreshold, double, iniFile, section)
260 
261  MRPT_LOAD_CONFIG_VAR(SURFOptions.rotation_invariant, bool, iniFile, section)
262  MRPT_LOAD_CONFIG_VAR(SURFOptions.hessianThreshold, int, iniFile, section)
263  MRPT_LOAD_CONFIG_VAR(SURFOptions.nOctaves, int, iniFile, section)
264  MRPT_LOAD_CONFIG_VAR(SURFOptions.nLayersPerOctave, int, iniFile, section)
265 
266  MRPT_LOAD_CONFIG_VAR(FASTOptions.threshold, int, iniFile, section)
267  MRPT_LOAD_CONFIG_VAR(FASTOptions.nonmax_suppression, bool, iniFile, section)
268  MRPT_LOAD_CONFIG_VAR(FASTOptions.min_distance, float, iniFile, section)
269  MRPT_LOAD_CONFIG_VAR(FASTOptions.use_KLT_response, bool, iniFile, section)
270 
271  MRPT_LOAD_CONFIG_VAR(ORBOptions.extract_patch, bool, iniFile, section)
272  MRPT_LOAD_CONFIG_VAR(ORBOptions.min_distance, int, iniFile, section)
273  MRPT_LOAD_CONFIG_VAR(ORBOptions.n_levels, int, iniFile, section)
274  MRPT_LOAD_CONFIG_VAR(ORBOptions.scale_factor, float, iniFile, section)
275 
277  SpinImagesOptions.hist_size_distance, int, iniFile, section)
279  SpinImagesOptions.hist_size_intensity, int, iniFile, section)
280  MRPT_LOAD_CONFIG_VAR(SpinImagesOptions.radius, int, iniFile, section)
281  MRPT_LOAD_CONFIG_VAR(SpinImagesOptions.std_dist, float, iniFile, section)
283  SpinImagesOptions.std_intensity, float, iniFile, section)
284 
285  MRPT_LOAD_CONFIG_VAR(PolarImagesOptions.bins_angle, int, iniFile, section)
287  PolarImagesOptions.bins_distance, int, iniFile, section)
288  MRPT_LOAD_CONFIG_VAR(PolarImagesOptions.radius, int, iniFile, section)
289 
290  MRPT_LOAD_CONFIG_VAR(LogPolarImagesOptions.radius, int, iniFile, section)
292  LogPolarImagesOptions.num_angles, int, iniFile, section)
294  LogPolarImagesOptions.rho_scale, double, iniFile, section)
295 
296  // #added by Raghavender Sahdev
297  MRPT_LOAD_CONFIG_VAR(AKAZEOptions.descriptor_type, int, iniFile, section)
298  MRPT_LOAD_CONFIG_VAR(AKAZEOptions.descriptor_size, int, iniFile, section)
300  AKAZEOptions.descriptor_channels, int, iniFile, section)
301  MRPT_LOAD_CONFIG_VAR(AKAZEOptions.threshold, float, iniFile, section)
302  MRPT_LOAD_CONFIG_VAR(AKAZEOptions.nOctaves, int, iniFile, section)
303  MRPT_LOAD_CONFIG_VAR(AKAZEOptions.nOctaveLayers, int, iniFile, section)
304  MRPT_LOAD_CONFIG_VAR(AKAZEOptions.diffusivity, int, iniFile, section)
305 
306  MRPT_LOAD_CONFIG_VAR(LSDOptions.nOctaves, int, iniFile, section)
307  MRPT_LOAD_CONFIG_VAR(LSDOptions.scale, int, iniFile, section)
308 
309  MRPT_LOAD_CONFIG_VAR(BLDOptions.numOfOctave, int, iniFile, section)
310  MRPT_LOAD_CONFIG_VAR(BLDOptions.widthOfBand, int, iniFile, section)
311  MRPT_LOAD_CONFIG_VAR(BLDOptions.reductionRatio, int, iniFile, section)
312 
313  MRPT_LOAD_CONFIG_VAR(LATCHOptions.bytes, int, iniFile, section)
314  MRPT_LOAD_CONFIG_VAR(LATCHOptions.half_ssd_size, int, iniFile, section)
316  LATCHOptions.rotationInvariance, bool, iniFile, section)
317 }
#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].
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
Definition: format.cpp:16
#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: 8fe78517f Sun Jul 14 19:43:28 2019 +0200 at lun oct 28 02:10:00 CET 2019