31#include "rtabmap/core/rtabmap_core_export.h"
33#include <opencv2/imgcodecs.hpp>
34#include <opencv2/videoio.hpp>
35#include <opencv2/core/core.hpp>
36#if CV_MAJOR_VERSION < 5
37#include <opencv2/features2d/features2d.hpp>
39#include <opencv2/features.hpp>
43#include "rtabmap/core/Parameters.h"
44#include "rtabmap/core/SensorData.h"
46#if CV_MAJOR_VERSION < 3
54 class GoodFeaturesToTrackDetector_GPU;
57typedef cv::SIFT CV_SIFT;
58typedef cv::SURF CV_SURF;
59typedef cv::FastFeatureDetector CV_FAST;
60typedef cv::FREAK CV_FREAK;
61typedef cv::GFTTDetector CV_GFTT;
62typedef cv::BriefDescriptorExtractor CV_BRIEF;
63typedef cv::BRISK CV_BRISK;
64typedef cv::gpu::SURF_GPU CV_SURF_GPU;
65typedef cv::gpu::ORB_GPU CV_ORB_GPU;
66typedef cv::gpu::FAST_GPU CV_FAST_GPU;
67typedef cv::gpu::GoodFeaturesToTrackDetector_GPU CV_GFTT_GPU;
70namespace xfeatures2d {
73class BriefDescriptorExtractor;
74#if (CV_MAJOR_VERSION == 4 && CV_MINOR_VERSION <= 3) || (CV_MAJOR_VERSION == 3 && (CV_MINOR_VERSION < 4 || (CV_MINOR_VERSION==4 && CV_SUBMINOR_VERSION<11)))
78#if (CV_MAJOR_VERSION == 5)
84class FastFeatureDetector;
90#if (CV_MAJOR_VERSION == 4 && CV_MINOR_VERSION <= 3) || (CV_MAJOR_VERSION == 3 && (CV_MINOR_VERSION < 4 || (CV_MINOR_VERSION==4 && CV_SUBMINOR_VERSION<11)))
91typedef cv::xfeatures2d::SIFT CV_SIFT;
93typedef cv::SIFT CV_SIFT;
95typedef cv::xfeatures2d::SURF CV_SURF;
96typedef cv::FastFeatureDetector CV_FAST;
97typedef cv::xfeatures2d::FREAK CV_FREAK;
98typedef cv::xfeatures2d::DAISY CV_DAISY;
99typedef cv::GFTTDetector CV_GFTT;
100typedef cv::xfeatures2d::BriefDescriptorExtractor CV_BRIEF;
101#if (CV_MAJOR_VERSION < 5)
102typedef cv::BRISK CV_BRISK;
103typedef cv::KAZE CV_KAZE;
105typedef cv::xfeatures2d::BRISK CV_BRISK;
106typedef cv::xfeatures2d::KAZE CV_KAZE;
108typedef cv::ORB CV_ORB;
109typedef cv::cuda::SURF_CUDA CV_SURF_GPU;
110typedef cv::cuda::ORB CV_ORB_GPU;
111typedef cv::cuda::FastFeatureDetector CV_FAST_GPU;
112typedef cv::cuda::CornersDetector CV_GFTT_GPU;
122class SPDetectorRpautrat;
125#if CV_MAJOR_VERSION < 3
160 kFeatureOrbOctree=10,
161 kFeatureSuperPointTorch=11,
162 kFeatureSurfFreak=12,
163 kFeatureGfttDaisy=13,
164 kFeatureSurfDaisy=14,
165 kFeaturePyDetector=15,
166 kFeatureSuperPointRpautrat=16,
167 kFeatureOnnxDetector=17,
180 case kFeatureFastFreak:
182 case kFeatureFastBrief:
184 case kFeatureGfttFreak:
186 case kFeatureGfttBrief:
190 case kFeatureGfttOrb:
194 case kFeatureOrbOctree:
196 case kFeatureSuperPointTorch:
198 case kFeatureSurfFreak:
200 case kFeatureGfttDaisy:
202 case kFeatureSurfDaisy:
204 case kFeaturePyDetector:
206 case kFeatureSuperPointRpautrat:
207 return "SUPERPOINT-RPAUTRAT";
208 case kFeatureOnnxDetector:
209 return "OnnxDetector";
225 std::vector<cv::KeyPoint> & keypoints,
226 const cv::Mat & depth,
229 static void filterKeypointsByDepth(
230 std::vector<cv::KeyPoint> & keypoints,
231 cv::Mat & descriptors,
232 const cv::Mat & depth,
235 static void filterKeypointsByDepth(
236 std::vector<cv::KeyPoint> & keypoints,
237 cv::Mat & descriptors,
238 std::vector<cv::Point3f> & keypoints3D,
244 std::vector<cv::KeyPoint> & keypoints,
245 const cv::Mat & disparity,
247 static void filterKeypointsByDisparity(
248 std::vector<cv::KeyPoint> & keypoints,
249 cv::Mat & descriptors,
250 const cv::Mat & disparity,
254 static void limitKeypoints(std::vector<cv::KeyPoint> & keypoints,
int maxKeypoints,
const cv::Size & imageSize = cv::Size(),
bool ssc =
false);
255 static void limitKeypoints(std::vector<cv::KeyPoint> & keypoints, cv::Mat & descriptors,
int maxKeypoints,
const cv::Size & imageSize = cv::Size(),
bool ssc =
false);
256 static void limitKeypoints(std::vector<cv::KeyPoint> & keypoints, std::vector<cv::Point3f> & keypoints3D, cv::Mat & descriptors,
int maxKeypoints,
const cv::Size & imageSize = cv::Size(),
bool ssc =
false);
257 static void limitKeypoints(
const std::vector<cv::KeyPoint> & keypoints, std::vector<bool> & inliers,
int maxKeypoints,
const cv::Size & imageSize = cv::Size(),
bool ssc =
false);
258 static void limitKeypoints(
const std::vector<cv::KeyPoint> & keypoints, std::vector<bool> & inliers,
int maxKeypoints,
const cv::Size & imageSize,
int gridRows,
int gridCols,
bool ssc =
false);
261 static cv::Rect
computeRoi(
const cv::Mat & image,
const std::string & roiRatios);
262 static cv::Rect computeRoi(
const cv::Mat & image,
const std::vector<float> & roiRatios);
264 int getMaxFeatures()
const {
return maxFeatures_;}
265 bool getSSC()
const {
return SSC_;}
266 float getMinDepth()
const {
return _minDepth;}
267 float getMaxDepth()
const {
return _maxDepth;}
268 int getGridRows()
const {
return gridRows_;}
269 int getGridCols()
const {
return gridCols_;}
272 virtual ~Feature2D();
276 const cv::Mat & image,
277 const cv::Mat & mask = cv::Mat());
280 const cv::Mat & image,
281 std::vector<cv::KeyPoint> & keypoints)
const;
285 const std::vector<cv::KeyPoint> & keypoints)
const;
287 virtual void parseParameters(
const ParametersMap & parameters);
288 virtual const ParametersMap & getParameters()
const {
return parameters_;}
304 virtual std::vector<cv::KeyPoint> generateKeypointsImpl(
const cv::Mat & image,
const cv::Rect & roi,
const cv::Mat & mask = cv::Mat()) = 0;
305 virtual cv::Mat generateDescriptorsImpl(
const cv::Mat & image, std::vector<cv::KeyPoint> & keypoints)
const = 0;
313 std::vector<float> _roiRatios;
315 int _subPixIterations;
330 virtual void parseParameters(
const ParametersMap & parameters)
override;
331 virtual Feature2D::Type getType()
const override {
return kFeatureSurf;}
335 virtual std::vector<cv::KeyPoint> generateKeypointsImpl(
const cv::Mat & image,
const cv::Rect & roi,
const cv::Mat & mask = cv::Mat())
override;
336 virtual cv::Mat generateDescriptorsImpl(
const cv::Mat & image, std::vector<cv::KeyPoint> & keypoints)
const override;
339 double hessianThreshold_;
344 float gpuKeypointsRatio_;
347 cv::Ptr<CV_SURF> _surf;
348 cv::Ptr<CV_SURF_GPU> _gpuSurf;
358 virtual void parseParameters(
const ParametersMap & parameters)
override;
359 virtual Feature2D::Type getType()
const override {
return kFeatureSift;}
363 virtual std::vector<cv::KeyPoint> generateKeypointsImpl(
const cv::Mat & image,
const cv::Rect & roi,
const cv::Mat & mask = cv::Mat())
override;
364 virtual cv::Mat generateDescriptorsImpl(
const cv::Mat & image, std::vector<cv::KeyPoint> & keypoints)
const override;
368 double contrastThreshold_;
369 double edgeThreshold_;
371 bool preciseUpscale_;
374 float gaussianThreshold_;
375 float maxGaussianThreshold_;
378 cv::Ptr<CV_SIFT> sift_;
379 SiftData * cudaSiftData_;
380 float * cudaSiftMemory_;
381 cv::Size cudaSiftMemorySize_;
382 cv::Mat cudaSiftDescriptors_;
383 bool cudaSiftUpscaling_;
393 virtual void parseParameters(
const ParametersMap & parameters)
override;
398 virtual std::vector<cv::KeyPoint> generateKeypointsImpl(
const cv::Mat & image,
const cv::Rect & roi,
const cv::Mat & mask = cv::Mat())
override;
399 virtual cv::Mat generateDescriptorsImpl(
const cv::Mat & image, std::vector<cv::KeyPoint> & keypoints)
const override;
412 bool nonmaxSuppresion_;
414 cv::Ptr<CV_ORB> _orb;
415 cv::Ptr<CV_ORB_GPU> _gpuOrb;
425 virtual void parseParameters(
const ParametersMap & parameters)
override;
426 virtual Feature2D::Type getType()
const override {
return kFeatureUndef;}
430 virtual std::vector<cv::KeyPoint> generateKeypointsImpl(
const cv::Mat & image,
const cv::Rect & roi,
const cv::Mat & mask = cv::Mat())
override;
431 virtual cv::Mat generateDescriptorsImpl(
const cv::Mat &, std::vector<cv::KeyPoint> &)
const override {
return cv::Mat();}
435 bool nonmaxSuppression_;
437 double gpuKeypointsRatio_;
445 int fastCVMaxFeatures_;
446 int fastCVLastImageHeight_;
447 uint32_t* fastCVCorners_= NULL;
448 uint32_t* fastCVCornerScores_ = NULL;
449 void* fastCVTempBuf_ = NULL;
451 cv::Ptr<cv::FeatureDetector> _fast;
452 cv::Ptr<CV_FAST_GPU> _gpuFast;
462 virtual void parseParameters(
const ParametersMap & parameters)
override;
463 virtual Feature2D::Type getType()
const override {
return kFeatureFastBrief;}
466 virtual cv::Mat generateDescriptorsImpl(
const cv::Mat & image, std::vector<cv::KeyPoint> & keypoints)
const override;
471 cv::Ptr<CV_BRIEF> _brief;
481 virtual void parseParameters(
const ParametersMap & parameters)
override;
482 virtual Feature2D::Type getType()
const override {
return kFeatureFastFreak;}
485 virtual cv::Mat generateDescriptorsImpl(
const cv::Mat & image, std::vector<cv::KeyPoint> & keypoints)
const override;
488 bool orientationNormalized_;
489 bool scaleNormalized_;
493 cv::Ptr<CV_FREAK> _freak;
503 virtual void parseParameters(
const ParametersMap & parameters)
override;
507 virtual std::vector<cv::KeyPoint> generateKeypointsImpl(
const cv::Mat & image,
const cv::Rect & roi,
const cv::Mat & mask = cv::Mat())
override;
510 double _qualityLevel;
513 bool _useHarrisDetector;
517 cv::Ptr<CV_GFTT> _gftt;
518 cv::Ptr<CV_GFTT_GPU> _gpuGftt;
528 virtual void parseParameters(
const ParametersMap & parameters)
override;
529 virtual Feature2D::Type getType()
const override {
return kFeatureGfttBrief;}
532 virtual cv::Mat generateDescriptorsImpl(
const cv::Mat & image, std::vector<cv::KeyPoint> & keypoints)
const override;
537 cv::Ptr<CV_BRIEF> _brief;
547 virtual void parseParameters(
const ParametersMap & parameters)
override;
548 virtual Feature2D::Type getType()
const override {
return kFeatureGfttFreak;}
551 virtual cv::Mat generateDescriptorsImpl(
const cv::Mat & image, std::vector<cv::KeyPoint> & keypoints)
const override;
554 bool orientationNormalized_;
555 bool scaleNormalized_;
559 cv::Ptr<CV_FREAK> _freak;
569 virtual void parseParameters(
const ParametersMap & parameters)
override;
570 virtual Feature2D::Type getType()
const override {
return kFeatureSurfFreak;}
573 virtual cv::Mat generateDescriptorsImpl(
const cv::Mat & image, std::vector<cv::KeyPoint> & keypoints)
const override;
576 bool orientationNormalized_;
577 bool scaleNormalized_;
581 cv::Ptr<CV_FREAK> _freak;
591 virtual void parseParameters(
const ParametersMap & parameters)
override;
592 virtual Feature2D::Type getType()
const override {
return kFeatureGfttOrb;}
595 virtual cv::Mat generateDescriptorsImpl(
const cv::Mat & image, std::vector<cv::KeyPoint> & keypoints)
const override;
608 virtual void parseParameters(
const ParametersMap & parameters)
override;
609 virtual Feature2D::Type getType()
const override {
return kFeatureBrisk;}
612 virtual std::vector<cv::KeyPoint> generateKeypointsImpl(
const cv::Mat & image,
const cv::Rect & roi,
const cv::Mat & mask = cv::Mat())
override;
613 virtual cv::Mat generateDescriptorsImpl(
const cv::Mat & image, std::vector<cv::KeyPoint> & keypoints)
const override;
620 cv::Ptr<CV_BRISK> brisk_;
630 virtual void parseParameters(
const ParametersMap & parameters)
override;
631 virtual Feature2D::Type getType()
const override {
return kFeatureKaze; }
634 virtual std::vector<cv::KeyPoint> generateKeypointsImpl(
const cv::Mat & image,
const cv::Rect & roi,
const cv::Mat & mask = cv::Mat())
override;
635 virtual cv::Mat generateDescriptorsImpl(
const cv::Mat & image, std::vector<cv::KeyPoint> & keypoints)
const override;
645#if CV_MAJOR_VERSION > 2
646 cv::Ptr<CV_KAZE> kaze_;
657 virtual void parseParameters(
const ParametersMap & parameters)
override;
658 virtual Feature2D::Type getType()
const override {
return kFeatureOrbOctree;}
661 virtual std::vector<cv::KeyPoint> generateKeypointsImpl(
const cv::Mat & image,
const cv::Rect & roi,
const cv::Mat & mask = cv::Mat())
override;
662 virtual cv::Mat generateDescriptorsImpl(
const cv::Mat & image, std::vector<cv::KeyPoint> & keypoints)
const override;
670 int fastMinThreshold_;
672 cv::Ptr<ORBextractor> _orb;
673 cv::Mat descriptors_;
683 virtual void parseParameters(
const ParametersMap & parameters)
override;
684 virtual Feature2D::Type getType()
const override {
return kFeatureSuperPointTorch; }
688 virtual std::vector<cv::KeyPoint> generateKeypointsImpl(
const cv::Mat & image,
const cv::Rect & roi,
const cv::Mat & mask = cv::Mat())
override;
689 virtual cv::Mat generateDescriptorsImpl(
const cv::Mat & image, std::vector<cv::KeyPoint> & keypoints)
const override;
691 cv::Ptr<SPDetector> superPoint_;
707 virtual void parseParameters(
const ParametersMap & parameters)
override;
708 virtual Feature2D::Type getType()
const override {
return kFeatureSuperPointRpautrat; }
712 virtual std::vector<cv::KeyPoint> generateKeypointsImpl(
const cv::Mat & image,
const cv::Rect & roi,
const cv::Mat & mask = cv::Mat())
override;
713 virtual cv::Mat generateDescriptorsImpl(
const cv::Mat & image, std::vector<cv::KeyPoint> & keypoints)
const override;
715 cv::Ptr<SPDetectorRpautrat> superPoint_;
717 std::string superpointWeightsPath_;
718 std::string superpointModelPath_;
719 std::string outputDir_;
733 virtual void parseParameters(
const ParametersMap & parameters)
override;
734 virtual Feature2D::Type getType()
const override {
return kFeatureGfttDaisy;}
737 virtual cv::Mat generateDescriptorsImpl(
const cv::Mat & image, std::vector<cv::KeyPoint> & keypoints)
const override;
740 bool orientationNormalized_;
741 bool scaleNormalized_;
745#if CV_MAJOR_VERSION > 2
746 cv::Ptr<CV_DAISY> _daisy;
757 virtual void parseParameters(
const ParametersMap & parameters)
override;
758 virtual Feature2D::Type getType()
const override {
return kFeatureSurfDaisy;}
761 virtual cv::Mat generateDescriptorsImpl(
const cv::Mat & image, std::vector<cv::KeyPoint> & keypoints)
const override;
764 bool orientationNormalized_;
765 bool scaleNormalized_;
769#if CV_MAJOR_VERSION > 2
770 cv::Ptr<CV_DAISY> _daisy;
BRISK detector and descriptor.
FAST corners + BRIEF descriptors.
FAST corners + FREAK descriptors.
FAST corner detector only (no descriptor).
virtual bool isGpuAvailable() const override
Returns true when a GPU/CUDA code path could be used by this detector on this host: i....
Abstract 2D feature detector and descriptor extractor for visual SLAM.
static void filterKeypointsByDisparity(std::vector< cv::KeyPoint > &keypoints, const cv::Mat &disparity, float minDisparity)
Keeps keypoints with stereo disparity ≥ minDisparity.
static Feature2D * create(const ParametersMap ¶meters=ParametersMap())
Creates a detector from Kp/DetectorStrategy in parameters. Caller owns the pointer.
static bool isAvailable(Feature2D::Type type)
Returns true if type is available (RTAB-Map is built with it).
Type
Built-in detector/descriptor strategy (Kp/DetectorStrategy).
std::vector< cv::KeyPoint > generateKeypoints(const cv::Mat &image, const cv::Mat &mask=cv::Mat())
Detects keypoints in a grayscale image (CV_8UC1); optional depth or 8U mask.
static cv::Rect computeRoi(const cv::Mat &image, const std::string &roiRatios)
ROI from Kp/RoiRatios string ("left top right bottom" fractions).
virtual bool isGpuAvailable() const
Returns true when a GPU/CUDA code path could be used by this detector on this host: i....
static std::string typeName(Type type)
static void limitKeypoints(std::vector< cv::KeyPoint > &keypoints, int maxKeypoints, const cv::Size &imageSize=cv::Size(), bool ssc=false)
Reduces keypoint count (by response or SSC spatial distribution).
static void filterKeypointsByDepth(std::vector< cv::KeyPoint > &keypoints, const cv::Mat &depth, float minDepth, float maxDepth)
Keeps keypoints whose depth at (u,v) is in (minDepth, maxDepth).
static Feature2D * create(Feature2D::Type type, const ParametersMap ¶meters=ParametersMap())
Creates a detector of the given type. Caller owns the pointer.
cv::Mat generateDescriptors(const cv::Mat &image, std::vector< cv::KeyPoint > &keypoints) const
Computes descriptors for keypoints (may shrink the list in some detectors).
std::vector< cv::Point3f > generateKeypoints3D(const SensorData &data, const std::vector< cv::KeyPoint > &keypoints) const
Back-projects keypoints to 3D using depth or stereo in data.
GFTT corners + BRIEF descriptors.
GFTT corners + DAISY descriptors (OpenCV 3+ xfeatures2d).
GFTT corners + FREAK descriptors.
GFTT corners + ORB descriptors (common default when SURF is unavailable).
Good-features-to-track detector (Shi–Tomasi / Harris).
virtual bool isGpuAvailable() const override
Returns true when a GPU/CUDA code path could be used by this detector on this host: i....
KAZE detector and descriptor (OpenCV 3+).
ORB with octree spatial distribution (RTAB-Map must be built with OCTREE enabled).
ORB detector and descriptor (optional GPU).
virtual bool isGpuAvailable() const override
Returns true when a GPU/CUDA code path could be used by this detector on this host: i....
SIFT detector and descriptor (optional GPU / CudaSift).
virtual bool isGpuAvailable() const override
Returns true when a GPU/CUDA code path could be used by this detector on this host: i....
SURF detector + DAISY descriptors (OpenCV 3+ xfeatures2d).
SURF detector + FREAK descriptors.
SURF detector and descriptor (non-free / xfeatures2d depending on OpenCV build).
virtual bool isGpuAvailable() const override
Returns true when a GPU/CUDA code path could be used by this detector on this host: i....
Container class for all sensor data captured at a specific time.
Sparse stereo matching using block matching.
SuperPoint (rpautrat) via Torch + Python (RTAB-Map must be built with libtorch and Python support).
virtual bool isGpuAvailable() const override
Returns true when a GPU/CUDA code path could be used by this detector on this host: i....
SuperPoint via LibTorch (RTAB-Map must be built with libtorch support).
virtual bool isGpuAvailable() const override
Returns true when a GPU/CUDA code path could be used by this detector on this host: i....
std::map< std::string, std::string > ParametersMap
Parameter keys mapped to their values, as used by every configurable class (see Parameters).