31#include "rtabmap/core/rtabmap_core_export.h"
33#include <opencv2/highgui/highgui.hpp>
34#include <opencv2/core/core.hpp>
35#if CV_MAJOR_VERSION < 5
36#include <opencv2/features2d/features2d.hpp>
38#include <opencv2/features.hpp>
42#include "rtabmap/core/Parameters.h"
43#include "rtabmap/core/SensorData.h"
45#if CV_MAJOR_VERSION < 3
53 class GoodFeaturesToTrackDetector_GPU;
56typedef cv::SIFT CV_SIFT;
57typedef cv::SURF CV_SURF;
58typedef cv::FastFeatureDetector CV_FAST;
59typedef cv::FREAK CV_FREAK;
60typedef cv::GFTTDetector CV_GFTT;
61typedef cv::BriefDescriptorExtractor CV_BRIEF;
62typedef cv::BRISK CV_BRISK;
63typedef cv::gpu::SURF_GPU CV_SURF_GPU;
64typedef cv::gpu::ORB_GPU CV_ORB_GPU;
65typedef cv::gpu::FAST_GPU CV_FAST_GPU;
66typedef cv::gpu::GoodFeaturesToTrackDetector_GPU CV_GFTT_GPU;
69namespace xfeatures2d {
72class BriefDescriptorExtractor;
73#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)))
77#if (CV_MAJOR_VERSION == 5)
83class FastFeatureDetector;
89#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)))
90typedef cv::xfeatures2d::SIFT CV_SIFT;
92typedef cv::SIFT CV_SIFT;
94typedef cv::xfeatures2d::SURF CV_SURF;
95typedef cv::FastFeatureDetector CV_FAST;
96typedef cv::xfeatures2d::FREAK CV_FREAK;
97typedef cv::xfeatures2d::DAISY CV_DAISY;
98typedef cv::GFTTDetector CV_GFTT;
99typedef cv::xfeatures2d::BriefDescriptorExtractor CV_BRIEF;
100#if (CV_MAJOR_VERSION < 5)
101typedef cv::BRISK CV_BRISK;
102typedef cv::KAZE CV_KAZE;
104typedef cv::xfeatures2d::BRISK CV_BRISK;
105typedef cv::xfeatures2d::KAZE CV_KAZE;
107typedef cv::ORB CV_ORB;
108typedef cv::cuda::SURF_CUDA CV_SURF_GPU;
109typedef cv::cuda::ORB CV_ORB_GPU;
110typedef cv::cuda::FastFeatureDetector CV_FAST_GPU;
111typedef cv::cuda::CornersDetector CV_GFTT_GPU;
121class SPDetectorRpautrat;
124#if CV_MAJOR_VERSION < 3
159 kFeatureOrbOctree=10,
160 kFeatureSuperPointTorch=11,
161 kFeatureSurfFreak=12,
162 kFeatureGfttDaisy=13,
163 kFeatureSurfDaisy=14,
164 kFeaturePyDetector=15,
165 kFeatureSuperPointRpautrat=16,
178 case kFeatureFastFreak:
180 case kFeatureFastBrief:
182 case kFeatureGfttFreak:
184 case kFeatureGfttBrief:
188 case kFeatureGfttOrb:
192 case kFeatureOrbOctree:
194 case kFeatureSuperPointTorch:
196 case kFeatureSurfFreak:
198 case kFeatureGfttDaisy:
200 case kFeatureSurfDaisy:
202 case kFeaturePyDetector:
204 case kFeatureSuperPointRpautrat:
205 return "SUPERPOINT-RPAUTRAT";
221 std::vector<cv::KeyPoint> & keypoints,
222 const cv::Mat & depth,
225 static void filterKeypointsByDepth(
226 std::vector<cv::KeyPoint> & keypoints,
227 cv::Mat & descriptors,
228 const cv::Mat & depth,
231 static void filterKeypointsByDepth(
232 std::vector<cv::KeyPoint> & keypoints,
233 cv::Mat & descriptors,
234 std::vector<cv::Point3f> & keypoints3D,
240 std::vector<cv::KeyPoint> & keypoints,
241 const cv::Mat & disparity,
243 static void filterKeypointsByDisparity(
244 std::vector<cv::KeyPoint> & keypoints,
245 cv::Mat & descriptors,
246 const cv::Mat & disparity,
250 static void limitKeypoints(std::vector<cv::KeyPoint> & keypoints,
int maxKeypoints,
const cv::Size & imageSize = cv::Size(),
bool ssc =
false);
251 static void limitKeypoints(std::vector<cv::KeyPoint> & keypoints, cv::Mat & descriptors,
int maxKeypoints,
const cv::Size & imageSize = cv::Size(),
bool ssc =
false);
252 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);
253 static void limitKeypoints(
const std::vector<cv::KeyPoint> & keypoints, std::vector<bool> & inliers,
int maxKeypoints,
const cv::Size & imageSize = cv::Size(),
bool ssc =
false);
254 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);
257 static cv::Rect
computeRoi(
const cv::Mat & image,
const std::string & roiRatios);
258 static cv::Rect computeRoi(
const cv::Mat & image,
const std::vector<float> & roiRatios);
260 int getMaxFeatures()
const {
return maxFeatures_;}
261 bool getSSC()
const {
return SSC_;}
262 float getMinDepth()
const {
return _minDepth;}
263 float getMaxDepth()
const {
return _maxDepth;}
264 int getGridRows()
const {
return gridRows_;}
265 int getGridCols()
const {
return gridCols_;}
268 virtual ~Feature2D();
272 const cv::Mat & image,
273 const cv::Mat & mask = cv::Mat());
276 const cv::Mat & image,
277 std::vector<cv::KeyPoint> & keypoints)
const;
281 const std::vector<cv::KeyPoint> & keypoints)
const;
283 virtual void parseParameters(
const ParametersMap & parameters);
284 virtual const ParametersMap & getParameters()
const {
return parameters_;}
300 virtual std::vector<cv::KeyPoint> generateKeypointsImpl(
const cv::Mat & image,
const cv::Rect & roi,
const cv::Mat & mask = cv::Mat()) = 0;
301 virtual cv::Mat generateDescriptorsImpl(
const cv::Mat & image, std::vector<cv::KeyPoint> & keypoints)
const = 0;
309 std::vector<float> _roiRatios;
311 int _subPixIterations;
326 virtual void parseParameters(
const ParametersMap & parameters)
override;
327 virtual Feature2D::Type getType()
const override {
return kFeatureSurf;}
331 virtual std::vector<cv::KeyPoint> generateKeypointsImpl(
const cv::Mat & image,
const cv::Rect & roi,
const cv::Mat & mask = cv::Mat())
override;
332 virtual cv::Mat generateDescriptorsImpl(
const cv::Mat & image, std::vector<cv::KeyPoint> & keypoints)
const override;
335 double hessianThreshold_;
340 float gpuKeypointsRatio_;
343 cv::Ptr<CV_SURF> _surf;
344 cv::Ptr<CV_SURF_GPU> _gpuSurf;
354 virtual void parseParameters(
const ParametersMap & parameters)
override;
355 virtual Feature2D::Type getType()
const override {
return kFeatureSift;}
359 virtual std::vector<cv::KeyPoint> generateKeypointsImpl(
const cv::Mat & image,
const cv::Rect & roi,
const cv::Mat & mask = cv::Mat())
override;
360 virtual cv::Mat generateDescriptorsImpl(
const cv::Mat & image, std::vector<cv::KeyPoint> & keypoints)
const override;
364 double contrastThreshold_;
365 double edgeThreshold_;
367 bool preciseUpscale_;
370 float gaussianThreshold_;
371 float maxGaussianThreshold_;
374 cv::Ptr<CV_SIFT> sift_;
375 SiftData * cudaSiftData_;
376 float * cudaSiftMemory_;
377 cv::Size cudaSiftMemorySize_;
378 cv::Mat cudaSiftDescriptors_;
379 bool cudaSiftUpscaling_;
389 virtual void parseParameters(
const ParametersMap & parameters)
override;
394 virtual std::vector<cv::KeyPoint> generateKeypointsImpl(
const cv::Mat & image,
const cv::Rect & roi,
const cv::Mat & mask = cv::Mat())
override;
395 virtual cv::Mat generateDescriptorsImpl(
const cv::Mat & image, std::vector<cv::KeyPoint> & keypoints)
const override;
408 bool nonmaxSuppresion_;
410 cv::Ptr<CV_ORB> _orb;
411 cv::Ptr<CV_ORB_GPU> _gpuOrb;
421 virtual void parseParameters(
const ParametersMap & parameters)
override;
422 virtual Feature2D::Type getType()
const override {
return kFeatureUndef;}
426 virtual std::vector<cv::KeyPoint> generateKeypointsImpl(
const cv::Mat & image,
const cv::Rect & roi,
const cv::Mat & mask = cv::Mat())
override;
427 virtual cv::Mat generateDescriptorsImpl(
const cv::Mat &, std::vector<cv::KeyPoint> &)
const override {
return cv::Mat();}
431 bool nonmaxSuppression_;
433 double gpuKeypointsRatio_;
441 int fastCVMaxFeatures_;
442 int fastCVLastImageHeight_;
443 uint32_t* fastCVCorners_= NULL;
444 uint32_t* fastCVCornerScores_ = NULL;
445 void* fastCVTempBuf_ = NULL;
447 cv::Ptr<cv::FeatureDetector> _fast;
448 cv::Ptr<CV_FAST_GPU> _gpuFast;
458 virtual void parseParameters(
const ParametersMap & parameters)
override;
459 virtual Feature2D::Type getType()
const override {
return kFeatureFastBrief;}
462 virtual cv::Mat generateDescriptorsImpl(
const cv::Mat & image, std::vector<cv::KeyPoint> & keypoints)
const override;
467 cv::Ptr<CV_BRIEF> _brief;
477 virtual void parseParameters(
const ParametersMap & parameters)
override;
478 virtual Feature2D::Type getType()
const override {
return kFeatureFastFreak;}
481 virtual cv::Mat generateDescriptorsImpl(
const cv::Mat & image, std::vector<cv::KeyPoint> & keypoints)
const override;
484 bool orientationNormalized_;
485 bool scaleNormalized_;
489 cv::Ptr<CV_FREAK> _freak;
499 virtual void parseParameters(
const ParametersMap & parameters)
override;
503 virtual std::vector<cv::KeyPoint> generateKeypointsImpl(
const cv::Mat & image,
const cv::Rect & roi,
const cv::Mat & mask = cv::Mat())
override;
506 double _qualityLevel;
509 bool _useHarrisDetector;
513 cv::Ptr<CV_GFTT> _gftt;
514 cv::Ptr<CV_GFTT_GPU> _gpuGftt;
524 virtual void parseParameters(
const ParametersMap & parameters)
override;
525 virtual Feature2D::Type getType()
const override {
return kFeatureGfttBrief;}
528 virtual cv::Mat generateDescriptorsImpl(
const cv::Mat & image, std::vector<cv::KeyPoint> & keypoints)
const override;
533 cv::Ptr<CV_BRIEF> _brief;
543 virtual void parseParameters(
const ParametersMap & parameters)
override;
544 virtual Feature2D::Type getType()
const override {
return kFeatureGfttFreak;}
547 virtual cv::Mat generateDescriptorsImpl(
const cv::Mat & image, std::vector<cv::KeyPoint> & keypoints)
const override;
550 bool orientationNormalized_;
551 bool scaleNormalized_;
555 cv::Ptr<CV_FREAK> _freak;
565 virtual void parseParameters(
const ParametersMap & parameters)
override;
566 virtual Feature2D::Type getType()
const override {
return kFeatureSurfFreak;}
569 virtual cv::Mat generateDescriptorsImpl(
const cv::Mat & image, std::vector<cv::KeyPoint> & keypoints)
const override;
572 bool orientationNormalized_;
573 bool scaleNormalized_;
577 cv::Ptr<CV_FREAK> _freak;
587 virtual void parseParameters(
const ParametersMap & parameters)
override;
588 virtual Feature2D::Type getType()
const override {
return kFeatureGfttOrb;}
591 virtual cv::Mat generateDescriptorsImpl(
const cv::Mat & image, std::vector<cv::KeyPoint> & keypoints)
const override;
604 virtual void parseParameters(
const ParametersMap & parameters)
override;
605 virtual Feature2D::Type getType()
const override {
return kFeatureBrisk;}
608 virtual std::vector<cv::KeyPoint> generateKeypointsImpl(
const cv::Mat & image,
const cv::Rect & roi,
const cv::Mat & mask = cv::Mat())
override;
609 virtual cv::Mat generateDescriptorsImpl(
const cv::Mat & image, std::vector<cv::KeyPoint> & keypoints)
const override;
616 cv::Ptr<CV_BRISK> brisk_;
626 virtual void parseParameters(
const ParametersMap & parameters)
override;
627 virtual Feature2D::Type getType()
const override {
return kFeatureKaze; }
630 virtual std::vector<cv::KeyPoint> generateKeypointsImpl(
const cv::Mat & image,
const cv::Rect & roi,
const cv::Mat & mask = cv::Mat())
override;
631 virtual cv::Mat generateDescriptorsImpl(
const cv::Mat & image, std::vector<cv::KeyPoint> & keypoints)
const override;
641#if CV_MAJOR_VERSION > 2
642 cv::Ptr<CV_KAZE> kaze_;
653 virtual void parseParameters(
const ParametersMap & parameters)
override;
654 virtual Feature2D::Type getType()
const override {
return kFeatureOrbOctree;}
657 virtual std::vector<cv::KeyPoint> generateKeypointsImpl(
const cv::Mat & image,
const cv::Rect & roi,
const cv::Mat & mask = cv::Mat())
override;
658 virtual cv::Mat generateDescriptorsImpl(
const cv::Mat & image, std::vector<cv::KeyPoint> & keypoints)
const override;
666 int fastMinThreshold_;
668 cv::Ptr<ORBextractor> _orb;
669 cv::Mat descriptors_;
679 virtual void parseParameters(
const ParametersMap & parameters)
override;
680 virtual Feature2D::Type getType()
const override {
return kFeatureSuperPointTorch; }
684 virtual std::vector<cv::KeyPoint> generateKeypointsImpl(
const cv::Mat & image,
const cv::Rect & roi,
const cv::Mat & mask = cv::Mat())
override;
685 virtual cv::Mat generateDescriptorsImpl(
const cv::Mat & image, std::vector<cv::KeyPoint> & keypoints)
const override;
687 cv::Ptr<SPDetector> superPoint_;
703 virtual void parseParameters(
const ParametersMap & parameters)
override;
704 virtual Feature2D::Type getType()
const override {
return kFeatureSuperPointRpautrat; }
708 virtual std::vector<cv::KeyPoint> generateKeypointsImpl(
const cv::Mat & image,
const cv::Rect & roi,
const cv::Mat & mask = cv::Mat())
override;
709 virtual cv::Mat generateDescriptorsImpl(
const cv::Mat & image, std::vector<cv::KeyPoint> & keypoints)
const override;
711 cv::Ptr<SPDetectorRpautrat> superPoint_;
713 std::string superpointWeightsPath_;
714 std::string superpointModelPath_;
715 std::string outputDir_;
729 virtual void parseParameters(
const ParametersMap & parameters)
override;
730 virtual Feature2D::Type getType()
const override {
return kFeatureGfttDaisy;}
733 virtual cv::Mat generateDescriptorsImpl(
const cv::Mat & image, std::vector<cv::KeyPoint> & keypoints)
const override;
736 bool orientationNormalized_;
737 bool scaleNormalized_;
741#if CV_MAJOR_VERSION > 2
742 cv::Ptr<CV_DAISY> _daisy;
753 virtual void parseParameters(
const ParametersMap & parameters)
override;
754 virtual Feature2D::Type getType()
const override {
return kFeatureSurfDaisy;}
757 virtual cv::Mat generateDescriptorsImpl(
const cv::Mat & image, std::vector<cv::KeyPoint> & keypoints)
const override;
760 bool orientationNormalized_;
761 bool scaleNormalized_;
765#if CV_MAJOR_VERSION > 2
766 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).