Main MRPT website > C++ reference for MRPT 1.9.9
TSimpleFeature.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #ifndef _mrpt_vision_TSimpleFeature_H
10 #define _mrpt_vision_TSimpleFeature_H
11 
12 #include <mrpt/utils/TPixelCoord.h>
13 #include <mrpt/utils/round.h>
15 #include <mrpt/math/CMatrixTemplate.h> // mrpt::math::CMatrixBool
17 #include <mrpt/vision/types.h>
18 #include <mrpt/utils/round.h>
19 
20 namespace mrpt
21 {
22 namespace vision
23 {
24 /** \addtogroup mrptvision_features
25  @{ */
26 
27 /** A simple structure for representing one image feature (without descriptor
28  * nor patch) - This is
29  * the template which allows you to select if pixels are represented as
30  * integers or floats.
31  * \sa TSimpleFeature, TSimpleFeaturef
32  */
33 template <typename PIXEL_COORD_TYPE>
35 {
36  /** The type of \a pt */
37  typedef PIXEL_COORD_TYPE pixel_coords_t;
38  /** The type of pt.x and pt.y */
39  typedef typename PIXEL_COORD_TYPE::pixel_coord_t pixel_coord_t;
40 
41  /** Coordinates in the image */
43  /** ID of the feature */
45  /** Status of the feature tracking process */
47  /** A measure of the "goodness" of the feature (typically, the KLT_response
48  * value) */
49  float response;
50  /** The image octave the image was found in: 0=original image, 1=1/2 image,
51  * 2=1/4 image, etc. */
53  /** A field for any other flags needed by the user (this has not a
54  * predefined meaning) */
56 
57  /** Constructor that only sets the pt.{x,y} values, leaving all other values
58  * to *undefined values*. */
59  template <typename COORD_TYPE>
60  inline TSimpleFeature_templ(const COORD_TYPE x, const COORD_TYPE y)
61  : pt(x, y)
62  {
63  }
64 
65  /** Default constructor, leaves all fields uninitialized */
67  template <typename OTHER_TSIMPLEFEATURE>
68  explicit TSimpleFeature_templ(const OTHER_TSIMPLEFEATURE& o)
69  : pt(o.pt.x, o.pt.y),
70  ID(o.ID),
72  response(o.response),
73  octave(o.octave),
75  {
76  }
77 };
78 
79 /** A simple structure for representing one image feature (without descriptor
80  * nor patch).
81  * \sa TSimpleFeaturef, CFeature, TSimpleFeatureList
82  */
84 
85 /** A version of TSimpleFeature with subpixel precision */
87 
88 template <typename FEATURE>
90 
91 template <>
93 {
94  typedef int coord_t;
95 
96  static inline coord_t f2coord(float f) { return mrpt::utils::round(f); }
97 };
98 
99 template <>
101 {
102  typedef float coord_t;
103 
104  static inline coord_t f2coord(float f) { return f; }
105 };
106 
107 /** A list of image features using the structure TSimpleFeature for each feature
108  * - capable of KD-tree computations
109  * Users normally use directly the typedef's: TSimpleFeatureList &
110  * TSimpleFeaturefList
111  */
112 template <typename FEATURE>
114 {
115  public:
116  typedef std::vector<FEATURE> TFeatureVector;
117  typedef FEATURE feature_t;
118 
119  /** @name Utilities
120  @{ */
121 
122  /** Returns a const ref to the actual std::vector<> container */
123  const TFeatureVector& getVector() const { return m_feats; }
124  /** Returns the maximum ID of all features in the list, or 0 if it's empty
125  */
127  {
128  if (this->empty()) return 0;
129  TFeatureID maxID = m_feats[0].ID;
130  size_t N = m_feats.size() - 1;
131  for (; N; --N) mrpt::utils::keep_max(maxID, m_feats[N].ID);
132  return maxID;
133  }
134 
135  /** Returns a vector with a LUT of the first feature index per row, to
136  * efficiently look for neighbors, etc.
137  * By default this vector is empty, so if a feature detector is used that
138  * doesn't fill this out, it will remain empty and useless.
139  * \note FASTER detectors do fill this out. In general, a feature list
140  * that dynamically changes will not use this LUT.
141  */
142  const std::vector<size_t>& getFirstIndexPerRowLUT() const
143  {
144  return m_first_index_per_row;
145  }
146  /// \overload
147  std::vector<size_t>& getFirstIndexPerRowLUT()
148  {
149  return m_first_index_per_row;
150  }
151 
152  /** Get a ref to the occupation matrix: this is a user-defined matrix, which
153  * is not updated automatically by this class. */
155  {
156  return m_occupied_sections;
157  }
159  {
160  return m_occupied_sections;
161  }
162 
163  /** @} */
164 
165  /** @name Method and datatypes to emulate a STL container
166  @{ */
169 
170  typedef typename TFeatureVector::reverse_iterator reverse_iterator;
171  typedef
172  typename TFeatureVector::const_reverse_iterator const_reverse_iterator;
173 
174  inline iterator begin() { return m_feats.begin(); }
175  inline iterator end() { return m_feats.end(); }
176  inline const_iterator begin() const { return m_feats.begin(); }
177  inline const_iterator end() const { return m_feats.end(); }
178  inline reverse_iterator rbegin() { return m_feats.rbegin(); }
179  inline reverse_iterator rend() { return m_feats.rend(); }
180  inline const_reverse_iterator rbegin() const { return m_feats.rbegin(); }
181  inline const_reverse_iterator rend() const { return m_feats.rend(); }
182  inline iterator erase(const iterator& it) { return m_feats.erase(it); }
183  inline bool empty() const { return m_feats.empty(); }
184  inline size_t size() const { return m_feats.size(); }
185  inline void clear()
186  {
187  m_feats.clear();
188  m_first_index_per_row.clear();
189  }
190  inline void resize(size_t N) { m_feats.resize(N); }
191  inline void reserve(size_t N) { m_feats.reserve(N); }
192  inline void push_back(const FEATURE& f) { m_feats.push_back(f); }
193  inline void push_back_fast(const FEATURE& f) { m_feats.push_back(f); }
194  inline void push_back_fast(const int x, const int y)
195  {
196  m_feats.push_back(FEATURE(x, y));
197  }
198 
199  inline FEATURE& operator[](const unsigned int index)
200  {
201  return m_feats[index];
202  }
203  inline const FEATURE& operator[](const unsigned int index) const
204  {
205  return m_feats[index];
206  }
207 
208  inline FEATURE& back() { return m_feats.back(); }
209  inline const FEATURE& back() const { return m_feats.back(); }
210  inline FEATURE& front() { return m_feats.front(); }
211  inline const FEATURE& front() const { return m_feats.front(); }
212  /** @} */
213 
214  /** @name getFeature*() methods for template-based access to feature list
215  @{ */
217  size_t i) const
218  {
219  return m_feats[i].pt.x;
220  }
222  size_t i) const
223  {
224  return m_feats[i].pt.y;
225  }
226  inline TFeatureID getFeatureID(size_t i) const { return m_feats[i].ID; }
227  inline float getFeatureResponse(size_t i) const
228  {
229  return m_feats[i].response;
230  }
231  inline bool isPointFeature(size_t i) const
232  {
234  return true;
235  }
236  inline float getScale(size_t i) const
237  {
238  return static_cast<float>(1 << m_feats[i].octave);
239  }
241  {
242  return m_feats[i].track_status;
243  }
244 
245  inline void setFeatureX(
246  size_t i, typename TSimpleFeatureTraits<FEATURE>::coord_t x)
247  {
248  m_feats[i].pt.x = x;
249  }
250  inline void setFeatureY(
251  size_t i, typename TSimpleFeatureTraits<FEATURE>::coord_t y)
252  {
253  m_feats[i].pt.y = y;
254  }
255 
256  inline void setFeatureXf(size_t i, float x)
257  {
259  }
260  inline void setFeatureYf(size_t i, float y)
261  {
263  }
264 
265  inline void setFeatureID(size_t i, TFeatureID id) { m_feats[i]->ID = id; }
266  inline void setFeatureResponse(size_t i, float r)
267  {
268  m_feats[i]->response = r;
269  }
270  inline void setScale(size_t i, float s)
271  {
272  m_feats[i]->octave = mrpt::utils::round(std::log(s) / std::log(2));
273  }
274  inline void setTrackStatus(size_t i, TFeatureTrackStatus s)
275  {
276  m_feats[i].track_status = s;
277  }
278 
279  inline void mark_as_outdated() const {}
280  /** @} */
281 
282  private:
283  /** The actual container with the list of features */
285  /** A LUT of the first feature index per row, to efficiently look for
286  * neighbors, etc. */
287  std::vector<size_t> m_first_index_per_row;
289 
290 }; // end of class
291 
292 /** A list of image features using the structure TSimpleFeature for each feature
293  * - capable of KD-tree computations */
295 
296 /** A list of image features using the structure TSimpleFeaturef for each
297  * feature - capable of KD-tree computations */
299 
300 /** A helper struct to sort keypoints by their response: It can be used with
301  *these types:
302  * - std::vector<cv::KeyPoint>
303  * - mrpt::vision::TSimpleFeatureList
304  */
305 template <typename FEATURE_LIST>
307  : public std::binary_function<size_t, size_t, bool>
308 {
309  const FEATURE_LIST& m_data;
310  KeypointResponseSorter(const FEATURE_LIST& data) : m_data(data) {}
311  bool operator()(size_t k1, size_t k2) const
312  {
313  return (m_data[k1].response > m_data[k2].response);
314  }
315 };
316 
317 /** Helper class: KD-tree search class for vector<KeyPoint>:
318  * Call mark_as_outdated() to force rebuilding the kd-tree after modifying the
319  * linked feature list.
320  * \tparam FEAT Can be cv::KeyPoint or mrpt::vision::TSimpleFeature
321  */
322 template <typename FEAT>
324  : public mrpt::math::KDTreeCapable<CFeatureListKDTree<FEAT>>
325 {
326  public:
327  inline void mark_as_outdated()
328  {
331  }
332 
333  const std::vector<FEAT>& m_data;
334  CFeatureListKDTree(const std::vector<FEAT>& data) : m_data(data) {}
335  /** @name Methods that MUST be implemented by children classes of
336  KDTreeCapable
337  @{ */
338 
339  /// Must return the number of data points
340  inline size_t kdtree_get_point_count() const { return m_data.size(); }
341  /// Returns the dim'th component of the idx'th point in the class:
342  inline float kdtree_get_pt(const size_t idx, int dim) const
343  {
344  ASSERTDEB_(dim == 0 || dim == 1)
345  if (dim == 0)
346  return m_data[idx].pt.x;
347  else
348  return m_data[idx].pt.y;
349  }
350 
351  /// Returns the distance between the vector "p1[0:size-1]" and the data
352  /// point with index "idx_p2" stored in the class:
353  inline float kdtree_distance(
354  const float* p1, const size_t idx_p2, size_t size) const
355  {
356  MRPT_UNUSED_PARAM(size); // in release mode
357  ASSERTDEB_(size == 2)
358 
359  const float d0 = p1[0] - m_data[idx_p2].pt.x;
360  const float d1 = p1[1] - m_data[idx_p2].pt.y;
361  return d0 * d0 + d1 * d1;
362  }
363 
364  // Optional bounding-box computation: return false to default to a standard
365  // bbox computation loop.
366  // Return true if the BBOX was already computed by the class and returned
367  // in "bb" so it can be avoided to redo it again.
368  // Look at bb.size() to find out the expected dimensionality (e.g. 2 or 3
369  // for point clouds)
370  template <typename BBOX>
371  bool kdtree_get_bbox(BBOX& bb) const
372  {
373  MRPT_UNUSED_PARAM(bb);
374  return false;
375  }
376 
377  /** @} */
378 
379 }; // end CFeatureListKDTree
380 
381 /** @} */ // End of add to module: mrptvision_features
382 
383 } // end of namespace
384 
385 } // end of namespace
386 
387 #endif
mrpt::math::CMatrixBool m_occupied_sections
Helper class: KD-tree search class for vector<KeyPoint>: Call mark_as_outdated() to force rebuilding ...
void setFeatureResponse(size_t i, float r)
void setFeatureYf(size_t i, float y)
Declares a matrix of booleans (non serializable).
TFeatureVector::const_reverse_iterator const_reverse_iterator
TSimpleFeatureList_templ< TSimpleFeaturef > TSimpleFeaturefList
A list of image features using the structure TSimpleFeaturef for each feature - capable of KD-tree co...
CFeatureListKDTree(const std::vector< FEAT > &data)
const mrpt::math::CMatrixBool & getOccupiedSectionsMatrix() const
Scalar * iterator
Definition: eigen_plugins.h:26
TFeatureVector::const_iterator const_iterator
float kdtree_get_pt(const size_t idx, int dim) const
Returns the dim&#39;th component of the idx&#39;th point in the class:
void setFeatureID(size_t i, TFeatureID id)
const Scalar * const_iterator
Definition: eigen_plugins.h:27
TFeatureVector m_feats
The actual container with the list of features.
GLdouble s
Definition: glext.h:3676
std::vector< size_t > m_first_index_per_row
A LUT of the first feature index per row, to efficiently look for neighbors, etc. ...
TFeatureTrackStatus track_status
Status of the feature tracking process.
unsigned char uint8_t
Definition: rptypes.h:41
A helper struct to sort keypoints by their response: It can be used with these types: ...
mrpt::math::CMatrixBool & getOccupiedSectionsMatrix()
Get a ref to the occupation matrix: this is a user-defined matrix, which is not updated automatically...
A generic adaptor class for providing Nearest Neighbor (NN) lookup via the nanoflann library...
Definition: KDTreeCapable.h:81
void setFeatureX(size_t i, typename TSimpleFeatureTraits< FEATURE >::coord_t x)
PIXEL_COORD_TYPE pixel_coords_t
The type of pt.
TSimpleFeatureTraits< FEATURE >::coord_t getFeatureX(size_t i) const
TSimpleFeature_templ()
Default constructor, leaves all fields uninitialized.
const TFeatureVector & getVector() const
Returns a const ref to the actual std::vector<> container.
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
GLuint index
Definition: glext.h:4054
const FEATURE & operator[](const unsigned int index) const
PIXEL_COORD_TYPE::pixel_coord_t pixel_coord_t
The type of pt.x and pt.y.
uint8_t octave
The image octave the image was found in: 0=original image, 1=1/2 image, 2=1/4 image, etc.
uint64_t TFeatureID
Definition of a feature ID.
FEATURE & operator[](const unsigned int index)
uint8_t user_flags
A field for any other flags needed by the user (this has not a predefined meaning) ...
TSimpleFeatureList_templ< TSimpleFeature > TSimpleFeatureList
A list of image features using the structure TSimpleFeature for each feature.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
#define ASSERTDEB_(f)
Defines an assertion mechanism - only when compiled in debug.
GLdouble GLdouble GLdouble r
Definition: glext.h:3705
TFeatureID ID
ID of the feature.
std::vector< size_t > & getFirstIndexPerRowLUT()
TSimpleFeature_templ< mrpt::utils::TPixelCoordf > TSimpleFeaturef
A version of TSimpleFeature with subpixel precision.
TSimpleFeature_templ< mrpt::utils::TPixelCoord > TSimpleFeature
A simple structure for representing one image feature (without descriptor nor patch).
pixel_coords_t pt
Coordinates in the image.
float response
A measure of the "goodness" of the feature (typically, the KLT_response value)
TFeatureVector::reverse_iterator reverse_iterator
void kdtree_mark_as_outdated() const
To be called by child classes when KD tree data changes.
GLuint id
Definition: glext.h:3909
float kdtree_distance(const float *p1, const size_t idx_p2, size_t size) const
Returns the distance between the vector "p1[0:size-1]" and the data point with index "idx_p2" stored ...
const std::vector< FEAT > & m_data
void setTrackStatus(size_t i, TFeatureTrackStatus s)
A simple structure for representing one image feature (without descriptor nor patch) - This is the te...
const_reverse_iterator rend() const
int round(const T value)
Returns the closer integer (int) to x.
Definition: round.h:25
void setFeatureXf(size_t i, float x)
GLenum GLint GLint y
Definition: glext.h:3538
TFeatureID getMaxID() const
Returns the maximum ID of all features in the list, or 0 if it&#39;s empty.
A list of image features using the structure TSimpleFeature for each feature.
GLsizeiptr size
Definition: glext.h:3923
TSimpleFeatureTraits< FEATURE >::coord_t getFeatureY(size_t i) const
TFeatureTrackStatus getTrackStatus(size_t i)
TSimpleFeature_templ(const OTHER_TSIMPLEFEATURE &o)
GLenum GLint x
Definition: glext.h:3538
void push_back_fast(const int x, const int y)
const std::vector< size_t > & getFirstIndexPerRowLUT() const
Returns a vector with a LUT of the first feature index per row, to efficiently look for neighbors...
const_reverse_iterator rbegin() const
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: glext.h:3546
iterator erase(const iterator &it)
TFeatureID getFeatureID(size_t i) const
TSimpleFeature_templ(const COORD_TYPE x, const COORD_TYPE y)
Constructor that only sets the pt.
size_t kdtree_get_point_count() const
Must return the number of data points.
void keep_max(T &var, const K test_val)
If the second argument is above the first one, set the first argument to this higher value...
float getFeatureResponse(size_t i) const
bool operator()(size_t k1, size_t k2) const
bool kdtree_get_bbox(BBOX &bb) const
KeypointResponseSorter(const FEATURE_LIST &data)
void setFeatureY(size_t i, typename TSimpleFeatureTraits< FEATURE >::coord_t y)



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019