Features2d.h
Go to the documentation of this file.
1 /*
2 Copyright (c) 2010-2016, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7  * Redistributions of source code must retain the above copyright
8  notice, this list of conditions and the following disclaimer.
9  * Redistributions in binary form must reproduce the above copyright
10  notice, this list of conditions and the following disclaimer in the
11  documentation and/or other materials provided with the distribution.
12  * Neither the name of the Universite de Sherbrooke nor the
13  names of its contributors may be used to endorse or promote products
14  derived from this software without specific prior written permission.
15 
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27 
28 #ifndef FEATURES2D_H_
29 #define FEATURES2D_H_
30 
31 #include "rtabmap/core/RtabmapExp.h" // DLL export/import defines
32 
33 #include <opencv2/highgui/highgui.hpp>
34 #include <opencv2/core/core.hpp>
35 #include <opencv2/features2d/features2d.hpp>
36 #include <list>
39 
40 #if CV_MAJOR_VERSION < 3
41 namespace cv{
42 class SURF;
43 class SIFT;
44 namespace gpu {
45  class SURF_GPU;
46  class ORB_GPU;
47  class FAST_GPU;
48 }
49 }
50 typedef cv::SIFT CV_SIFT;
51 typedef cv::SURF CV_SURF;
52 typedef cv::FastFeatureDetector CV_FAST;
53 typedef cv::FREAK CV_FREAK;
54 typedef cv::GFTTDetector CV_GFTT;
55 typedef cv::BriefDescriptorExtractor CV_BRIEF;
56 typedef cv::BRISK CV_BRISK;
57 typedef cv::gpu::SURF_GPU CV_SURF_GPU;
58 typedef cv::gpu::ORB_GPU CV_ORB_GPU;
59 typedef cv::gpu::FAST_GPU CV_FAST_GPU;
60 #else
61 namespace cv{
62 namespace xfeatures2d {
63 class FREAK;
64 class BriefDescriptorExtractor;
65 class SIFT;
66 class SURF;
67 }
68 namespace cuda {
69 class FastFeatureDetector;
70 class ORB;
71 class SURF_CUDA;
72 }
73 }
74 typedef cv::xfeatures2d::SIFT CV_SIFT;
75 typedef cv::xfeatures2d::SURF CV_SURF;
76 typedef cv::FastFeatureDetector CV_FAST;
77 typedef cv::xfeatures2d::FREAK CV_FREAK;
78 typedef cv::GFTTDetector CV_GFTT;
79 typedef cv::xfeatures2d::BriefDescriptorExtractor CV_BRIEF;
80 typedef cv::BRISK CV_BRISK;
81 typedef cv::ORB CV_ORB;
82 typedef cv::cuda::SURF_CUDA CV_SURF_GPU;
83 typedef cv::cuda::ORB CV_ORB_GPU;
84 typedef cv::cuda::FastFeatureDetector CV_FAST_GPU;
85 #endif
86 
87 
88 namespace rtabmap {
89 
90 class Stereo;
91 #if CV_MAJOR_VERSION < 3
92 class CV_ORB;
93 #endif
94 
95 // Feature2D
97 public:
98  enum Type {kFeatureUndef=-1,
99  kFeatureSurf=0,
100  kFeatureSift=1,
101  kFeatureOrb=2,
102  kFeatureFastFreak=3,
103  kFeatureFastBrief=4,
104  kFeatureGfttFreak=5,
105  kFeatureGfttBrief=6,
106  kFeatureBrisk=7,
107  kFeatureGfttOrb=8, //new 0.10.11
108  kFeatureKaze=9}; //new 0.13.2
109 
110  static Feature2D * create(const ParametersMap & parameters = ParametersMap());
111  static Feature2D * create(Feature2D::Type type, const ParametersMap & parameters = ParametersMap()); // for convenience
112 
113  static void filterKeypointsByDepth(
114  std::vector<cv::KeyPoint> & keypoints,
115  const cv::Mat & depth,
116  float minDepth,
117  float maxDepth);
118  static void filterKeypointsByDepth(
119  std::vector<cv::KeyPoint> & keypoints,
120  cv::Mat & descriptors,
121  const cv::Mat & depth,
122  float minDepth,
123  float maxDepth);
124 
125  static void filterKeypointsByDisparity(
126  std::vector<cv::KeyPoint> & keypoints,
127  const cv::Mat & disparity,
128  float minDisparity);
129  static void filterKeypointsByDisparity(
130  std::vector<cv::KeyPoint> & keypoints,
131  cv::Mat & descriptors,
132  const cv::Mat & disparity,
133  float minDisparity);
134 
135  static void limitKeypoints(std::vector<cv::KeyPoint> & keypoints, int maxKeypoints);
136  static void limitKeypoints(std::vector<cv::KeyPoint> & keypoints, cv::Mat & descriptors, int maxKeypoints);
137  static void limitKeypoints(std::vector<cv::KeyPoint> & keypoints, std::vector<cv::Point3f> & keypoints3D, cv::Mat & descriptors, int maxKeypoints);
138  static void limitKeypoints(const std::vector<cv::KeyPoint> & keypoints, std::vector<bool> & inliers, int maxKeypoints);
139 
140  static cv::Rect computeRoi(const cv::Mat & image, const std::string & roiRatios);
141  static cv::Rect computeRoi(const cv::Mat & image, const std::vector<float> & roiRatios);
142 
143  int getMaxFeatures() const {return maxFeatures_;}
144  float getMinDepth() const {return _minDepth;}
145  float getMaxDepth() const {return _maxDepth;}
146 
147 public:
148  virtual ~Feature2D();
149 
150  std::vector<cv::KeyPoint> generateKeypoints(
151  const cv::Mat & image,
152  const cv::Mat & mask = cv::Mat()) const;
153  cv::Mat generateDescriptors(
154  const cv::Mat & image,
155  std::vector<cv::KeyPoint> & keypoints) const;
156  std::vector<cv::Point3f> generateKeypoints3D(
157  const SensorData & data,
158  const std::vector<cv::KeyPoint> & keypoints) const;
159 
160  virtual void parseParameters(const ParametersMap & parameters);
161  virtual const ParametersMap & getParameters() const {return parameters_;}
162  virtual Feature2D::Type getType() const = 0;
163 
164 protected:
165  Feature2D(const ParametersMap & parameters = ParametersMap());
166 
167 private:
168  virtual std::vector<cv::KeyPoint> generateKeypointsImpl(const cv::Mat & image, const cv::Rect & roi, const cv::Mat & mask = cv::Mat()) const = 0;
169  virtual cv::Mat generateDescriptorsImpl(const cv::Mat & image, std::vector<cv::KeyPoint> & keypoints) const = 0;
170 
171 private:
174  float _maxDepth; // 0=inf
175  float _minDepth;
176  std::vector<float> _roiRatios; // size 4
179  double _subPixEps;
182  // Stereo stuff
184 };
185 
186 //SURF
187 class RTABMAP_EXP SURF : public Feature2D
188 {
189 public:
190  SURF(const ParametersMap & parameters = ParametersMap());
191  virtual ~SURF();
192 
193  virtual void parseParameters(const ParametersMap & parameters);
194  virtual Feature2D::Type getType() const {return kFeatureSurf;}
195 
196 private:
197  virtual std::vector<cv::KeyPoint> generateKeypointsImpl(const cv::Mat & image, const cv::Rect & roi, const cv::Mat & mask = cv::Mat()) const;
198  virtual cv::Mat generateDescriptorsImpl(const cv::Mat & image, std::vector<cv::KeyPoint> & keypoints) const;
199 
200 private:
204  bool extended_;
205  bool upright_;
208 
209  cv::Ptr<CV_SURF> _surf;
210  cv::Ptr<CV_SURF_GPU> _gpuSurf;
211 };
212 
213 //SIFT
214 class RTABMAP_EXP SIFT : public Feature2D
215 {
216 public:
217  SIFT(const ParametersMap & parameters = ParametersMap());
218  virtual ~SIFT();
219 
220  virtual void parseParameters(const ParametersMap & parameters);
221  virtual Feature2D::Type getType() const {return kFeatureSift;}
222 
223 private:
224  virtual std::vector<cv::KeyPoint> generateKeypointsImpl(const cv::Mat & image, const cv::Rect & roi, const cv::Mat & mask = cv::Mat()) const;
225  virtual cv::Mat generateDescriptorsImpl(const cv::Mat & image, std::vector<cv::KeyPoint> & keypoints) const;
226 
227 private:
231  double sigma_;
232 
233  cv::Ptr<CV_SIFT> _sift;
234 };
235 
236 //ORB
237 class RTABMAP_EXP ORB : public Feature2D
238 {
239 public:
240  ORB(const ParametersMap & parameters = ParametersMap());
241  virtual ~ORB();
242 
243  virtual void parseParameters(const ParametersMap & parameters);
244  virtual Feature2D::Type getType() const {return kFeatureOrb;}
245 
246 private:
247  virtual std::vector<cv::KeyPoint> generateKeypointsImpl(const cv::Mat & image, const cv::Rect & roi, const cv::Mat & mask = cv::Mat()) const;
248  virtual cv::Mat generateDescriptorsImpl(const cv::Mat & image, std::vector<cv::KeyPoint> & keypoints) const;
249 
250 private:
252  int nLevels_;
255  int WTA_K_;
258  bool gpu_;
259 
262 
263  cv::Ptr<CV_ORB> _orb;
264  cv::Ptr<CV_ORB_GPU> _gpuOrb;
265 };
266 
267 //FAST
268 class RTABMAP_EXP FAST : public Feature2D
269 {
270 public:
271  FAST(const ParametersMap & parameters = ParametersMap());
272  virtual ~FAST();
273 
274  virtual void parseParameters(const ParametersMap & parameters);
275  virtual Feature2D::Type getType() const {return kFeatureUndef;}
276 
277 private:
278  virtual std::vector<cv::KeyPoint> generateKeypointsImpl(const cv::Mat & image, const cv::Rect & roi, const cv::Mat & mask = cv::Mat()) const;
279  virtual cv::Mat generateDescriptorsImpl(const cv::Mat & image, std::vector<cv::KeyPoint> & keypoints) const {return cv::Mat();}
280 
281 private:
284  bool gpu_;
290 
291  cv::Ptr<cv::FeatureDetector> _fast;
292  cv::Ptr<CV_FAST_GPU> _gpuFast;
293 };
294 
295 //FAST_BRIEF
297 {
298 public:
299  FAST_BRIEF(const ParametersMap & parameters = ParametersMap());
300  virtual ~FAST_BRIEF();
301 
302  virtual void parseParameters(const ParametersMap & parameters);
303  virtual Feature2D::Type getType() const {return kFeatureFastBrief;}
304 
305 private:
306  virtual cv::Mat generateDescriptorsImpl(const cv::Mat & image, std::vector<cv::KeyPoint> & keypoints) const;
307 
308 private:
309  int bytes_;
310 
311  cv::Ptr<CV_BRIEF> _brief;
312 };
313 
314 //FAST_FREAK
316 {
317 public:
318  FAST_FREAK(const ParametersMap & parameters = ParametersMap());
319  virtual ~FAST_FREAK();
320 
321  virtual void parseParameters(const ParametersMap & parameters);
322  virtual Feature2D::Type getType() const {return kFeatureFastFreak;}
323 
324 private:
325  virtual cv::Mat generateDescriptorsImpl(const cv::Mat & image, std::vector<cv::KeyPoint> & keypoints) const;
326 
327 private:
332 
333  cv::Ptr<CV_FREAK> _freak;
334 };
335 
336 //GFTT
337 class RTABMAP_EXP GFTT : public Feature2D
338 {
339 public:
340  GFTT(const ParametersMap & parameters = ParametersMap());
341  virtual ~GFTT();
342 
343  virtual void parseParameters(const ParametersMap & parameters);
344 
345 private:
346  virtual std::vector<cv::KeyPoint> generateKeypointsImpl(const cv::Mat & image, const cv::Rect & roi, const cv::Mat & mask = cv::Mat()) const;
347 
348 private:
350  double _minDistance;
353  double _k;
354 
355  cv::Ptr<CV_GFTT> _gftt;
356 };
357 
358 //GFTT_BRIEF
360 {
361 public:
362  GFTT_BRIEF(const ParametersMap & parameters = ParametersMap());
363  virtual ~GFTT_BRIEF();
364 
365  virtual void parseParameters(const ParametersMap & parameters);
366  virtual Feature2D::Type getType() const {return kFeatureGfttBrief;}
367 
368 private:
369  virtual cv::Mat generateDescriptorsImpl(const cv::Mat & image, std::vector<cv::KeyPoint> & keypoints) const;
370 
371 private:
372  int bytes_;
373 
374  cv::Ptr<CV_BRIEF> _brief;
375 };
376 
377 //GFTT_FREAK
379 {
380 public:
381  GFTT_FREAK(const ParametersMap & parameters = ParametersMap());
382  virtual ~GFTT_FREAK();
383 
384  virtual void parseParameters(const ParametersMap & parameters);
385  virtual Feature2D::Type getType() const {return kFeatureGfttFreak;}
386 
387 private:
388  virtual cv::Mat generateDescriptorsImpl(const cv::Mat & image, std::vector<cv::KeyPoint> & keypoints) const;
389 
390 private:
395 
396  cv::Ptr<CV_FREAK> _freak;
397 };
398 
399 //GFTT_ORB
400 class RTABMAP_EXP GFTT_ORB : public GFTT
401 {
402 public:
403  GFTT_ORB(const ParametersMap & parameters = ParametersMap());
404  virtual ~GFTT_ORB();
405 
406  virtual void parseParameters(const ParametersMap & parameters);
407  virtual Feature2D::Type getType() const {return kFeatureGfttOrb;}
408 
409 private:
410  virtual cv::Mat generateDescriptorsImpl(const cv::Mat & image, std::vector<cv::KeyPoint> & keypoints) const;
411 
412 private:
414 };
415 
416 //BRISK
418 {
419 public:
420  BRISK(const ParametersMap & parameters = ParametersMap());
421  virtual ~BRISK();
422 
423  virtual void parseParameters(const ParametersMap & parameters);
424  virtual Feature2D::Type getType() const {return kFeatureBrisk;}
425 
426 private:
427  virtual std::vector<cv::KeyPoint> generateKeypointsImpl(const cv::Mat & image, const cv::Rect & roi, const cv::Mat & mask = cv::Mat()) const;
428  virtual cv::Mat generateDescriptorsImpl(const cv::Mat & image, std::vector<cv::KeyPoint> & keypoints) const;
429 
430 private:
431  int thresh_;
432  int octaves_;
434 
435  cv::Ptr<CV_BRISK> brisk_;
436 };
437 
438 //KAZE
439 class RTABMAP_EXP KAZE : public Feature2D
440 {
441 public:
442  KAZE(const ParametersMap & parameters = ParametersMap());
443  virtual ~KAZE();
444 
445  virtual void parseParameters(const ParametersMap & parameters);
446  virtual Feature2D::Type getType() const { return kFeatureKaze; }
447 
448 private:
449  virtual std::vector<cv::KeyPoint> generateKeypointsImpl(const cv::Mat & image, const cv::Rect & roi, const cv::Mat & mask = cv::Mat()) const;
450  virtual cv::Mat generateDescriptorsImpl(const cv::Mat & image, std::vector<cv::KeyPoint> & keypoints) const;
451 
452 private:
453  bool extended_;
454  bool upright_;
455  float threshold_;
459 
460 #if CV_MAJOR_VERSION > 2
461  cv::Ptr<cv::KAZE> kaze_;
462 #endif
463 };
464 
465 
466 }
467 
468 #endif /* FEATURES2D_H_ */
GLM_FUNC_DECL genIType mask(genIType const &count)
virtual Feature2D::Type getType() const
Definition: Features2d.h:407
int nOctaveLayers_
Definition: Features2d.h:457
virtual Feature2D::Type getType() const
Definition: Features2d.h:244
double gpuKeypointsRatio_
Definition: Features2d.h:285
double _qualityLevel
Definition: Features2d.h:349
cv::Ptr< CV_FREAK > _freak
Definition: Features2d.h:333
cv::SIFT CV_SIFT
Definition: Features2d.h:50
double edgeThreshold_
Definition: Features2d.h:230
virtual Feature2D::Type getType() const
Definition: Features2d.h:275
float getMinDepth() const
Definition: Features2d.h:144
cv::Ptr< CV_ORB > _orb
Definition: Features2d.h:263
cv::Ptr< CV_FREAK > _freak
Definition: Features2d.h:396
float scaleFactor_
Definition: Features2d.h:251
cv::BriefDescriptorExtractor CV_BRIEF
Definition: Features2d.h:55
bool nonmaxSuppression_
Definition: Features2d.h:283
std::map< std::string, std::string > ParametersMap
Definition: Parameters.h:41
double contrastThreshold_
Definition: Features2d.h:229
std::vector< float > _roiRatios
Definition: Features2d.h:176
int nOctaveLayers_
Definition: Features2d.h:228
cv::Ptr< CV_BRISK > brisk_
Definition: Features2d.h:435
cv::Ptr< CV_ORB_GPU > _gpuOrb
Definition: Features2d.h:264
virtual Feature2D::Type getType() const
Definition: Features2d.h:221
Definition: Features2d.h:41
cv::FastFeatureDetector CV_FAST
Definition: Features2d.h:52
int getMaxFeatures() const
Definition: Features2d.h:143
float getMaxDepth() const
Definition: Features2d.h:145
cv::SURF CV_SURF
Definition: Features2d.h:51
virtual Feature2D::Type getType() const
Definition: Features2d.h:424
virtual Feature2D::Type getType() const
Definition: Features2d.h:366
cv::Ptr< CV_FAST_GPU > _gpuFast
Definition: Features2d.h:292
#define RTABMAP_EXP
Definition: RtabmapExp.h:38
cv::BRISK CV_BRISK
Definition: Features2d.h:56
virtual Feature2D::Type getType() const
Definition: Features2d.h:446
cv::Rect RTABMAP_EXP computeRoi(const cv::Mat &image, const std::string &roiRatios)
Definition: util2d.cpp:1108
virtual cv::Mat generateDescriptorsImpl(const cv::Mat &image, std::vector< cv::KeyPoint > &keypoints) const
Definition: Features2d.h:279
cv::gpu::SURF_GPU CV_SURF_GPU
Definition: Features2d.h:57
int fastThreshold_
Definition: Features2d.h:260
float patternScale_
Definition: Features2d.h:433
double sigma_
Definition: Features2d.h:231
cv::Ptr< CV_BRIEF > _brief
Definition: Features2d.h:311
cv::Ptr< CV_SURF > _surf
Definition: Features2d.h:209
int nOctaveLayers_
Definition: Features2d.h:203
float gpuKeypointsRatio_
Definition: Features2d.h:206
cv::FREAK CV_FREAK
Definition: Features2d.h:53
cv::Ptr< CV_BRIEF > _brief
Definition: Features2d.h:374
cv::Ptr< CV_SIFT > _sift
Definition: Features2d.h:233
float threshold_
Definition: Features2d.h:455
virtual Feature2D::Type getType() const
Definition: Features2d.h:385
virtual Feature2D::Type getType() const
Definition: Features2d.h:322
double _minDistance
Definition: Features2d.h:350
bool gpuVersion_
Definition: Features2d.h:207
int edgeThreshold_
Definition: Features2d.h:253
cv::gpu::ORB_GPU CV_ORB_GPU
Definition: Features2d.h:58
virtual const ParametersMap & getParameters() const
Definition: Features2d.h:161
cv::GFTTDetector CV_GFTT
Definition: Features2d.h:54
cv::gpu::FAST_GPU CV_FAST_GPU
Definition: Features2d.h:59
virtual Feature2D::Type getType() const
Definition: Features2d.h:194
bool nonmaxSuppresion_
Definition: Features2d.h:261
cv::Ptr< cv::FeatureDetector > _fast
Definition: Features2d.h:291
double hessianThreshold_
Definition: Features2d.h:201
cv::Ptr< CV_GFTT > _gftt
Definition: Features2d.h:355
ParametersMap parameters_
Definition: Features2d.h:172
bool _useHarrisDetector
Definition: Features2d.h:352
cv::Ptr< CV_SURF_GPU > _gpuSurf
Definition: Features2d.h:210
virtual Feature2D::Type getType() const
Definition: Features2d.h:303


rtabmap
Author(s): Mathieu Labbe
autogenerated on Wed Jun 5 2019 22:41:31