SaDVIO
aFeatureDetector.h
Go to the documentation of this file.
1 #ifndef AFEATUREDETECTOR_H
2 #define AFEATUREDETECTOR_H
3 
4 #include <opencv2/core.hpp>
5 #include <opencv2/features2d.hpp>
6 
10 #include "isaeslam/typedefs.h"
11 #include "utilities/geometry.h"
12 
13 namespace isae {
14 
15 class Point2D;
16 
23  public:
24  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
26  AFeatureDetector(int n, int n_per_cell) : _n_total(n), _n_per_cell(n_per_cell) {}
28 
34  virtual void init() = 0;
35 
45  virtual void detectAndCompute(const cv::Mat &img,
46  const cv::Mat &mask,
47  std::vector<cv::KeyPoint> &keypoints,
48  cv::Mat &descriptors,
49  int n_points = 0) = 0;
50 
57  virtual void computeDescriptor(const cv::Mat &img, std::vector<std::shared_ptr<AFeature>> &features) = 0;
58 
66  virtual std::vector<std::shared_ptr<AFeature>> detectAndComputeGrid(
67  const cv::Mat &img,
68  const cv::Mat &mask,
69  std::vector<std::shared_ptr<AFeature>> existing_features = std::vector<std::shared_ptr<AFeature>>()) = 0;
70 
77  virtual double computeDist(const cv::Mat &desc1, const cv::Mat &desc2) const = 0;
78 
79  size_t getNbDesiredFeatures() { return _n_total; }
80  double getMaxMatchingDist() const { return _max_matching_dist; }
81 
92  bool getFeaturesInBox(int x,
93  int y,
94  int w,
95  int h,
96  const std::vector<std::shared_ptr<AFeature>> &features,
97  std::vector<std::shared_ptr<AFeature>> &features_in_box) const;
98 
99  void deleteUndescribedFeatures(std::vector<std::shared_ptr<AFeature>> &features);
100 
109  static void KeypointToFeature(std::vector<cv::KeyPoint> keypoints,
110  cv::Mat descriptors,
111  std::vector<std::shared_ptr<AFeature>> &features,
112  const std::string &featurelabel = "pointxd");
113 
121  static void FeatureToKeypoint(std::vector<std::shared_ptr<AFeature>> features,
122  std::vector<cv::KeyPoint> &keypoints,
123  cv::Mat &descriptors);
124 
131  static void FeatureToP2f(std::vector<std::shared_ptr<AFeature>> features, std::vector<cv::Point2f> &p2fs);
132 
133  protected:
134  int _n_total;
137 };
138 
139 } // namespace isae
140 
141 #endif // AFEATUREDETECTOR_H
isae::AFeatureDetector::deleteUndescribedFeatures
void deleteUndescribedFeatures(std::vector< std::shared_ptr< AFeature >> &features)
Definition: aFeatureDetector.cpp:37
geometry.h
Point2D.h
isae::AFeatureDetector::FeatureToP2f
static void FeatureToP2f(std::vector< std::shared_ptr< AFeature >> features, std::vector< cv::Point2f > &p2fs)
Convert a vector of AFeature pointers to a vector of cv::Point2f.
Definition: aFeatureDetector.cpp:84
isae::AFeatureDetector::detectAndComputeGrid
virtual std::vector< std::shared_ptr< AFeature > > detectAndComputeGrid(const cv::Mat &img, const cv::Mat &mask, std::vector< std::shared_ptr< AFeature >> existing_features=std::vector< std::shared_ptr< AFeature >>())=0
Virtual function to detect and compute features in a grid (bucketting).
isae::AFeatureDetector::_n_total
int _n_total
the maximum amount of features the detector should find for any given image
Definition: aFeatureDetector.h:134
isae::AFeatureDetector::AFeatureDetector
EIGEN_MAKE_ALIGNED_OPERATOR_NEW AFeatureDetector()
Definition: aFeatureDetector.h:25
isae::AFeatureDetector::computeDescriptor
virtual void computeDescriptor(const cv::Mat &img, std::vector< std::shared_ptr< AFeature >> &features)=0
Virtual function to compute descriptors for a set of features.
isae::AFeatureDetector::AFeatureDetector
AFeatureDetector(int n, int n_per_cell)
Definition: aFeatureDetector.h:26
isae::AFeatureDetector::getNbDesiredFeatures
size_t getNbDesiredFeatures()
Definition: aFeatureDetector.h:79
typedefs.h
isae::AFeatureDetector::detectAndCompute
virtual void detectAndCompute(const cv::Mat &img, const cv::Mat &mask, std::vector< cv::KeyPoint > &keypoints, cv::Mat &descriptors, int n_points=0)=0
Virtual function to detect and compute features in an image.
isae
Definition: AFeature2D.h:8
isae::AFeatureDetector::_max_matching_dist
double _max_matching_dist
distance threshold for matching
Definition: aFeatureDetector.h:136
isae::AFeatureDetector::getFeaturesInBox
bool getFeaturesInBox(int x, int y, int w, int h, const std::vector< std::shared_ptr< AFeature >> &features, std::vector< std::shared_ptr< AFeature >> &features_in_box) const
Get features from a feature set in a bounding box defined by (x, y, w, h).
Definition: aFeatureDetector.cpp:10
isae::AFeatureDetector::computeDist
virtual double computeDist(const cv::Mat &desc1, const cv::Mat &desc2) const =0
Virtual function to compute the distance between two feature descriptors.
isae::AFeatureDetector::_n_per_cell
int _n_per_cell
the number of features per cell
Definition: aFeatureDetector.h:135
isae::AFeatureDetector
Abstract class for feature detectors.
Definition: aFeatureDetector.h:22
isae::AFeatureDetector::KeypointToFeature
static void KeypointToFeature(std::vector< cv::KeyPoint > keypoints, cv::Mat descriptors, std::vector< std::shared_ptr< AFeature >> &features, const std::string &featurelabel="pointxd")
Convert OpenCV keypoints and descriptors to a vector of AFeature pointers.
Definition: aFeatureDetector.cpp:45
isae::AFeatureDetector::FeatureToKeypoint
static void FeatureToKeypoint(std::vector< std::shared_ptr< AFeature >> features, std::vector< cv::KeyPoint > &keypoints, cv::Mat &descriptors)
Convert a vector of AFeature pointers to OpenCV keypoints and descriptors.
Definition: aFeatureDetector.cpp:68
Line2D.h
isae::AFeatureDetector::getMaxMatchingDist
double getMaxMatchingDist() const
Definition: aFeatureDetector.h:80
isae::AFeatureDetector::init
virtual void init()=0
Virtual function to initialize the feature detector.
ASensor.h
isae::AFeatureDetector::~AFeatureDetector
~AFeatureDetector()
Definition: aFeatureDetector.h:27