MRPT  2.0.1
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-2020, 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 featORB:
66  extractFeaturesORB(img, feats, init_ID, nDesiredFeatures, ROI);
67  break;
68 
69  // # added by Raghavender Sahdev
70  case featAKAZE:
71  extractFeaturesAKAZE(img, feats, init_ID, nDesiredFeatures, ROI);
72  break;
73  case featLSD:
74  extractFeaturesLSD(img, feats, init_ID, nDesiredFeatures, ROI);
75  break;
76 
77  default:
78  THROW_EXCEPTION("options.method has an invalid value!");
79  break;
80  }
81 }
82 
83 /************************************************************************************************
84  computeDescriptors
85 ************************************************************************************************/
86 void CFeatureExtraction::computeDescriptors(
87  const CImage& in_img, CFeatureList& inout_features,
88  TDescriptorType in_descriptor_list)
89 {
91  CTimeLoggerEntry tle(profiler, "computeDescriptors");
92 
93  int nDescComputed = 0;
94 
95  if ((in_descriptor_list & descSIFT) != 0)
96  {
97  this->internal_computeSiftDescriptors(in_img, inout_features);
98  ++nDescComputed;
99  }
100  if ((in_descriptor_list & descSURF) != 0)
101  {
102  this->internal_computeSurfDescriptors(in_img, inout_features);
103  ++nDescComputed;
104  }
105  if ((in_descriptor_list & descSpinImages) != 0)
106  {
107  this->internal_computeSpinImageDescriptors(in_img, inout_features);
108  ++nDescComputed;
109  }
110  if ((in_descriptor_list & descPolarImages) != 0)
111  {
112  this->internal_computePolarImageDescriptors(in_img, inout_features);
113  ++nDescComputed;
114  }
115  if ((in_descriptor_list & descLogPolarImages) != 0)
116  {
117  this->internal_computeLogPolarImageDescriptors(in_img, inout_features);
118  ++nDescComputed;
119  }
120  if ((in_descriptor_list & descORB) != 0)
121  {
122  this->internal_computeORBDescriptors(in_img, inout_features);
123  ++nDescComputed;
124  }
125  // # added by Raghavender Sahdev
126  if ((in_descriptor_list & descBLD) != 0)
127  {
128  this->internal_computeBLDLineDescriptors(in_img, inout_features);
129  ++nDescComputed;
130  }
131  if ((in_descriptor_list & descLATCH) != 0)
132  {
133  this->internal_computeLATCHDescriptors(in_img, inout_features);
134  ++nDescComputed;
135  }
136  if (!nDescComputed)
138  "No known descriptor value found in in_descriptor_list=%u",
139  (unsigned)in_descriptor_list);
140 
141  MRPT_END
142 }
143 
144 void CFeatureExtraction::TOptions::dumpToTextStream(std::ostream& out) const
145 {
146  out << "\n----------- [CFeatureExtraction::TOptions] ------------ \n\n";
147 
148  LOADABLEOPTS_DUMP_VAR(featsType, int)
149  LOADABLEOPTS_DUMP_VAR(patchSize, int)
150  LOADABLEOPTS_DUMP_VAR(FIND_SUBPIXEL, bool)
151  LOADABLEOPTS_DUMP_VAR(useMask, bool)
152  LOADABLEOPTS_DUMP_VAR(addNewFeatures, bool)
153 
154  LOADABLEOPTS_DUMP_VAR(harrisOptions.k, double)
155  LOADABLEOPTS_DUMP_VAR(harrisOptions.radius, int)
156  LOADABLEOPTS_DUMP_VAR(harrisOptions.threshold, float)
157  LOADABLEOPTS_DUMP_VAR(harrisOptions.sigma, float)
158  LOADABLEOPTS_DUMP_VAR(harrisOptions.min_distance, float)
159 
160  LOADABLEOPTS_DUMP_VAR(KLTOptions.min_distance, float)
161  LOADABLEOPTS_DUMP_VAR(KLTOptions.threshold, float)
162  LOADABLEOPTS_DUMP_VAR(KLTOptions.radius, int)
163 
164  LOADABLEOPTS_DUMP_VAR(SIFTOptions.implementation, int)
165 
166  LOADABLEOPTS_DUMP_VAR(SURFOptions.rotation_invariant, bool)
167  LOADABLEOPTS_DUMP_VAR(SURFOptions.hessianThreshold, int)
168  LOADABLEOPTS_DUMP_VAR(SURFOptions.nOctaves, int)
169  LOADABLEOPTS_DUMP_VAR(SURFOptions.nLayersPerOctave, int)
170 
171  LOADABLEOPTS_DUMP_VAR(FASTOptions.threshold, int)
172  LOADABLEOPTS_DUMP_VAR(FASTOptions.nonmax_suppression, bool)
173  LOADABLEOPTS_DUMP_VAR(FASTOptions.min_distance, float)
174  LOADABLEOPTS_DUMP_VAR(FASTOptions.use_KLT_response, bool)
175 
176  LOADABLEOPTS_DUMP_VAR(ORBOptions.scale_factor, float)
177  LOADABLEOPTS_DUMP_VAR(ORBOptions.min_distance, int)
178  LOADABLEOPTS_DUMP_VAR(ORBOptions.n_levels, int)
179  LOADABLEOPTS_DUMP_VAR(ORBOptions.extract_patch, bool)
180 
181  LOADABLEOPTS_DUMP_VAR(SpinImagesOptions.hist_size_distance, int)
182  LOADABLEOPTS_DUMP_VAR(SpinImagesOptions.hist_size_intensity, int)
183  LOADABLEOPTS_DUMP_VAR(SpinImagesOptions.radius, int)
184  LOADABLEOPTS_DUMP_VAR(SpinImagesOptions.std_dist, float)
185  LOADABLEOPTS_DUMP_VAR(SpinImagesOptions.std_intensity, float)
186 
187  LOADABLEOPTS_DUMP_VAR(PolarImagesOptions.bins_angle, int)
188  LOADABLEOPTS_DUMP_VAR(PolarImagesOptions.bins_distance, int)
189  LOADABLEOPTS_DUMP_VAR(PolarImagesOptions.radius, int)
190 
191  LOADABLEOPTS_DUMP_VAR(LogPolarImagesOptions.radius, int)
192  LOADABLEOPTS_DUMP_VAR(LogPolarImagesOptions.num_angles, int)
193  LOADABLEOPTS_DUMP_VAR(LogPolarImagesOptions.rho_scale, double)
194 
195  // # added by Raghavender Sahdev
196  LOADABLEOPTS_DUMP_VAR(AKAZEOptions.descriptor_type, int)
197  LOADABLEOPTS_DUMP_VAR(AKAZEOptions.descriptor_size, int)
198  LOADABLEOPTS_DUMP_VAR(AKAZEOptions.descriptor_channels, int)
199  LOADABLEOPTS_DUMP_VAR(AKAZEOptions.threshold, float)
200  LOADABLEOPTS_DUMP_VAR(AKAZEOptions.nOctaves, int)
201  LOADABLEOPTS_DUMP_VAR(AKAZEOptions.nOctaveLayers, int)
202  LOADABLEOPTS_DUMP_VAR(AKAZEOptions.diffusivity, int)
203 
204  LOADABLEOPTS_DUMP_VAR(LSDOptions.nOctaves, int)
205  LOADABLEOPTS_DUMP_VAR(LSDOptions.scale, int)
206 
207  LOADABLEOPTS_DUMP_VAR(BLDOptions.numOfOctave, int)
208  LOADABLEOPTS_DUMP_VAR(BLDOptions.reductionRatio, int)
209  LOADABLEOPTS_DUMP_VAR(BLDOptions.widthOfBand, int)
210 
211  LOADABLEOPTS_DUMP_VAR(LATCHOptions.bytes, int)
212  LOADABLEOPTS_DUMP_VAR(LATCHOptions.half_ssd_size, int)
213  LOADABLEOPTS_DUMP_VAR(LATCHOptions.rotationInvariance, bool)
214 
215  out << "\n";
216 }
217 
218 /*---------------------------------------------------------------
219  loadFromConfigFile
220  ---------------------------------------------------------------*/
221 void CFeatureExtraction::TOptions::loadFromConfigFile(
222  const mrpt::config::CConfigFileBase& iniFile, const std::string& section)
223 {
224  featsType = iniFile.read_enum(section, "featsType", featsType);
225 
226  MRPT_LOAD_CONFIG_VAR(patchSize, int, iniFile, section)
227  MRPT_LOAD_CONFIG_VAR(FIND_SUBPIXEL, bool, iniFile, section)
228  MRPT_LOAD_CONFIG_VAR(useMask, bool, iniFile, section)
229  MRPT_LOAD_CONFIG_VAR(addNewFeatures, bool, iniFile, section)
230 
231  // string sect = section;
232  MRPT_LOAD_CONFIG_VAR(harrisOptions.k, double, iniFile, section)
233  MRPT_LOAD_CONFIG_VAR(harrisOptions.radius, int, iniFile, section)
234  MRPT_LOAD_CONFIG_VAR(harrisOptions.threshold, float, iniFile, section)
235  MRPT_LOAD_CONFIG_VAR(harrisOptions.sigma, float, iniFile, section)
236  MRPT_LOAD_CONFIG_VAR(harrisOptions.min_distance, float, iniFile, section)
237 
238  MRPT_LOAD_CONFIG_VAR(KLTOptions.min_distance, float, iniFile, section)
239  MRPT_LOAD_CONFIG_VAR(KLTOptions.threshold, float, iniFile, section)
240  MRPT_LOAD_CONFIG_VAR(KLTOptions.radius, int, iniFile, section)
241 
243  SIFTOptions.implementation, int, TSIFTImplementation, iniFile, section)
244  MRPT_LOAD_CONFIG_VAR(SIFTOptions.threshold, double, iniFile, section)
245  MRPT_LOAD_CONFIG_VAR(SIFTOptions.edgeThreshold, double, iniFile, section)
246 
247  MRPT_LOAD_CONFIG_VAR(SURFOptions.rotation_invariant, bool, iniFile, section)
248  MRPT_LOAD_CONFIG_VAR(SURFOptions.hessianThreshold, int, iniFile, section)
249  MRPT_LOAD_CONFIG_VAR(SURFOptions.nOctaves, int, iniFile, section)
250  MRPT_LOAD_CONFIG_VAR(SURFOptions.nLayersPerOctave, int, iniFile, section)
251 
252  MRPT_LOAD_CONFIG_VAR(FASTOptions.threshold, int, iniFile, section)
253  MRPT_LOAD_CONFIG_VAR(FASTOptions.nonmax_suppression, bool, iniFile, section)
254  MRPT_LOAD_CONFIG_VAR(FASTOptions.min_distance, int, iniFile, section)
255  MRPT_LOAD_CONFIG_VAR(FASTOptions.use_KLT_response, bool, iniFile, section)
256 
257  MRPT_LOAD_CONFIG_VAR(ORBOptions.extract_patch, bool, iniFile, section)
258  MRPT_LOAD_CONFIG_VAR(ORBOptions.min_distance, int, iniFile, section)
259  MRPT_LOAD_CONFIG_VAR(ORBOptions.n_levels, int, iniFile, section)
260  MRPT_LOAD_CONFIG_VAR(ORBOptions.scale_factor, float, iniFile, section)
261 
263  SpinImagesOptions.hist_size_distance, int, iniFile, section)
265  SpinImagesOptions.hist_size_intensity, int, iniFile, section)
266  MRPT_LOAD_CONFIG_VAR(SpinImagesOptions.radius, int, iniFile, section)
267  MRPT_LOAD_CONFIG_VAR(SpinImagesOptions.std_dist, float, iniFile, section)
269  SpinImagesOptions.std_intensity, float, iniFile, section)
270 
271  MRPT_LOAD_CONFIG_VAR(PolarImagesOptions.bins_angle, int, iniFile, section)
273  PolarImagesOptions.bins_distance, int, iniFile, section)
274  MRPT_LOAD_CONFIG_VAR(PolarImagesOptions.radius, int, iniFile, section)
275 
276  MRPT_LOAD_CONFIG_VAR(LogPolarImagesOptions.radius, int, iniFile, section)
278  LogPolarImagesOptions.num_angles, int, iniFile, section)
280  LogPolarImagesOptions.rho_scale, double, iniFile, section)
281 
282  // #added by Raghavender Sahdev
283  MRPT_LOAD_CONFIG_VAR(AKAZEOptions.descriptor_type, int, iniFile, section)
284  MRPT_LOAD_CONFIG_VAR(AKAZEOptions.descriptor_size, int, iniFile, section)
286  AKAZEOptions.descriptor_channels, int, iniFile, section)
287  MRPT_LOAD_CONFIG_VAR(AKAZEOptions.threshold, float, iniFile, section)
288  MRPT_LOAD_CONFIG_VAR(AKAZEOptions.nOctaves, int, iniFile, section)
289  MRPT_LOAD_CONFIG_VAR(AKAZEOptions.nOctaveLayers, int, iniFile, section)
290  MRPT_LOAD_CONFIG_VAR(AKAZEOptions.diffusivity, int, iniFile, section)
291 
292  MRPT_LOAD_CONFIG_VAR(LSDOptions.nOctaves, int, iniFile, section)
293  MRPT_LOAD_CONFIG_VAR(LSDOptions.scale, int, iniFile, section)
294 
295  MRPT_LOAD_CONFIG_VAR(BLDOptions.numOfOctave, int, iniFile, section)
296  MRPT_LOAD_CONFIG_VAR(BLDOptions.widthOfBand, int, iniFile, section)
297  MRPT_LOAD_CONFIG_VAR(BLDOptions.reductionRatio, int, iniFile, section)
298 
299  MRPT_LOAD_CONFIG_VAR(LATCHOptions.bytes, int, iniFile, section)
300  MRPT_LOAD_CONFIG_VAR(LATCHOptions.half_ssd_size, int, iniFile, section)
302  LATCHOptions.rotationInvariance, bool, iniFile, section)
303 }
#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...
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].
FAST feature detector, OpenCV&#39;s implementation ("Faster and better: A machine learning approach to...
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.
Harris border and corner detector [HARRIS].
mrpt::vision::TStereoCalibResults out
#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:148



Page generated by Doxygen 1.8.14 for MRPT 2.0.1 Git: 0fef1a6d7 Fri Apr 3 23:00:21 2020 +0200 at vie abr 3 23:20:28 CEST 2020