Point Cloud Library (PCL)  1.12.1-dev
brisk_2d.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2012-, Open Perception , Inc.
6  * Copyright (C) 2011 The Autonomous Systems Lab (ASL), ETH Zurich,
7  * Stefan Leutenegger, Simon Lynen and Margarita Chli.
8  *
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  *
15  * * Redistributions of source code must retain the above copyright
16  * notice, this list of conditions and the following disclaimer.
17  * * Redistributions in binary form must reproduce the above
18  * copyright notice, this list of conditions and the following
19  * disclaimer in the documentation and/or other materials provided
20  * with the distribution.
21  * * Neither the name of the copyright holder(s) nor the names of its
22  * contributors may be used to endorse or promote products derived
23  * from this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
28  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
29  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
30  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  *
38  */
39 
40 #pragma once
41 
42 // PCL includes
43 #include <pcl/features/feature.h>
44 #include <pcl/common/centroid.h>
45 #include <pcl/common/intensity.h>
46 
47 namespace pcl
48 {
49  /** \brief Implementation of the BRISK-descriptor, based on the original code and paper reference by
50  *
51  * \par
52  * Stefan Leutenegger,Margarita Chli and Roland Siegwart,
53  * BRISK: Binary Robust Invariant Scalable Keypoints,
54  * in Proceedings of the IEEE International Conference on Computer Vision (ICCV2011).
55  *
56  * \warning The input keypoints cloud is not const, and it will be modified: keypoints for which descriptors can not
57  * be computed will be deleted from the cloud.
58  *
59  * \author Radu B. Rusu, Stefan Holzer
60  * \ingroup features
61  */
62  template <typename PointInT,
63  typename PointOutT = pcl::BRISKSignature512,
64  typename KeypointT = pcl::PointWithScale,
65  typename IntensityT = pcl::common::IntensityFieldAccessor<PointInT> >
66  class BRISK2DEstimation// : public Feature<PointT, KeyPointT>
67  {
68  public:
69  using Ptr = shared_ptr<BRISK2DEstimation<PointInT, PointOutT, KeypointT, IntensityT> >;
70  using ConstPtr = shared_ptr<const BRISK2DEstimation<PointInT, PointOutT, KeypointT, IntensityT> >;
71 
74 
78 
80 
81  /** \brief Constructor. */
83 
84  /** \brief Destructor. */
85  virtual ~BRISK2DEstimation ();
86 
87  /** \brief Determines whether rotation invariance is enabled.
88  * \param[in] enable determines whether rotation invariance is enabled.
89  */
90  inline void
91  setRotationInvariance (const bool enable)
92  {
93  rotation_invariance_enabled_ = enable;
94  }
95 
96  /** \brief Determines whether scale invariance is enabled.
97  * \param[in] enable determines whether scale invariance is enabled.
98  */
99  inline void
100  setScaleInvariance (const bool enable)
101  {
102  scale_invariance_enabled_ = enable;
103  }
104 
105  /** \brief Sets the input cloud.
106  * \param[in] cloud the input cloud.
107  */
108  inline void
110  {
111  input_cloud_ = cloud;
112  }
113 
114  /** \brief Sets the input keypoints.
115  * \param[in] keypoints the input cloud containing the keypoints.
116  */
117  inline void
119  {
120  // Make a copy as we will have to erase keypoints that we don't use
121  // TO DO: change this later
122  //keypoints_.reset (new KeypointPointCloudT (*keypoints));
123  keypoints_ = keypoints;
124  }
125 
126  /** \brief Computes the descriptors for the previously specified
127  * points and input data.
128  * \param[out] output descriptors the destination for the computed descriptors.
129  */
130  void
131  compute (PointCloudOutT &output);
132  //td::vector<pcl::features::brisk::BRISKDescriptor> & descriptors) const;
133 
134  protected:
135  /** \brief Call this to generate the kernel:
136  * circle of radius r (pixels), with n points;
137  * short pairings with dMax, long pairings with dMin
138  *
139  * \note This should never be called by a regular user. We use a fixed type in PCL
140  * (BRISKSignature512) and tampering with the parameters might lead to a different
141  * size descriptor which the user needs to accommodate in a new point type.
142  */
143  void
144  generateKernel (std::vector<float> &radius_list,
145  std::vector<int> &number_list,
146  float d_max = 5.85f, float d_min = 8.2f,
147  std::vector<int> index_change = std::vector<int> ());
148 
149  /** \brief Compute the smoothed intensity for a given x/y position in the image. */
150  inline int
151  smoothedIntensity (const std::vector<unsigned char>& image,
152  int image_width, int image_height,
153  const std::vector<int>& integral_image,
154  const float key_x, const float key_y, const unsigned int scale,
155  const unsigned int rot, const unsigned int point) const;
156 
157  private:
158  /** \brief ROI predicate comparator. */
159  bool
160  RoiPredicate (const float min_x, const float min_y,
161  const float max_x, const float max_y, const KeypointT& key_pt);
162 
163  /** \brief Specifies whether rotation invariance is enabled. */
164  bool rotation_invariance_enabled_;
165 
166  /** \brief Specifies whether scale invariance is enabled. */
167  bool scale_invariance_enabled_;
168 
169  /** \brief Specifies the scale of the pattern. */
170  const float pattern_scale_;
171 
172  /** \brief the input cloud. */
173  PointCloudInTConstPtr input_cloud_;
174 
175  /** \brief the input keypoints. */
176  KeypointPointCloudTPtr keypoints_;
177 
178  // TODO: set
179  float scale_range_;
180 
181  // Some helper structures for the Brisk pattern representation
182  struct BriskPatternPoint
183  {
184  /** x coordinate relative to center. */
185  float x;
186  /** x coordinate relative to center. */
187  float y;
188  /** Gaussian smoothing sigma. */
189  float sigma;
190  };
191 
192  struct BriskShortPair
193  {
194  /** index of the first pattern point. */
195  unsigned int i;
196  /** index of other pattern point. */
197  unsigned int j;
198  };
199 
200  struct BriskLongPair
201  {
202  /** index of the first pattern point. */
203  unsigned int i;
204  /** index of other pattern point. */
205  unsigned int j;
206  /** 1024.0/dx. */
207  int weighted_dx;
208  /** 1024.0/dy. */
209  int weighted_dy;
210  };
211 
212  // pattern properties
213  /** [i][rotation][scale]. */
214  BriskPatternPoint* pattern_points_;
215 
216  /** Total number of collocation points. */
217  unsigned int points_;
218 
219  /** Discretization of the rotation look-up. */
220  const unsigned int n_rot_;
221 
222  /** Lists the scaling per scale index [scale]. */
223  float* scale_list_;
224 
225  /** Lists the total pattern size per scale index [scale]. */
226  unsigned int* size_list_;
227 
228  /** Scales discretization. */
229  const unsigned int scales_;
230 
231  /** Span of sizes 40->4 Octaves - else, this needs to be adjusted... */
232  const float scalerange_;
233 
234  // general
235  const float basic_size_;
236 
237  // pairs
238  /** Number of uchars the descriptor consists of. */
239  int strings_;
240  /** Short pair maximum distance. */
241  float d_max_;
242  /** Long pair maximum distance. */
243  float d_min_;
244  /** d<_d_max. */
245  BriskShortPair* short_pairs_;
246  /** d>_d_min. */
247  BriskLongPair* long_pairs_;
248  /** Number of short pairs. */
249  unsigned int no_short_pairs_;
250  /** Number of long pairs. */
251  unsigned int no_long_pairs_;
252 
253  /** \brief Intensity field accessor. */
254  IntensityT intensity_;
255 
256  /** \brief The name of the class. */
257  std::string name_;
258  };
259 
260 }
261 
262 #include <pcl/features/impl/brisk_2d.hpp>
Define methods for centroid estimation and covariance matrix calculus.
Implementation of the BRISK-descriptor, based on the original code and paper reference by.
Definition: brisk_2d.h:67
void setRotationInvariance(const bool enable)
Determines whether rotation invariance is enabled.
Definition: brisk_2d.h:91
shared_ptr< BRISK2DEstimation< PointInT, PointOutT, KeypointT, IntensityT > > Ptr
Definition: brisk_2d.h:69
BRISK2DEstimation()
Constructor.
Definition: brisk_2d.hpp:49
typename PointCloudInT::ConstPtr PointCloudInTConstPtr
Definition: brisk_2d.h:73
typename KeypointPointCloudT::ConstPtr KeypointPointCloudTConstPtr
Definition: brisk_2d.h:77
void setScaleInvariance(const bool enable)
Determines whether scale invariance is enabled.
Definition: brisk_2d.h:100
void setInputCloud(const PointCloudInTConstPtr &cloud)
Sets the input cloud.
Definition: brisk_2d.h:109
virtual ~BRISK2DEstimation()
Destructor.
Definition: brisk_2d.hpp:90
void generateKernel(std::vector< float > &radius_list, std::vector< int > &number_list, float d_max=5.85f, float d_min=8.2f, std::vector< int > index_change=std::vector< int >())
Call this to generate the kernel: circle of radius r (pixels), with n points; short pairings with dMa...
Definition: brisk_2d.hpp:101
void compute(PointCloudOutT &output)
Computes the descriptors for the previously specified points and input data.
Definition: brisk_2d.hpp:446
typename KeypointPointCloudT::Ptr KeypointPointCloudTPtr
Definition: brisk_2d.h:76
void setKeypoints(const KeypointPointCloudTPtr &keypoints)
Sets the input keypoints.
Definition: brisk_2d.h:118
shared_ptr< const BRISK2DEstimation< PointInT, PointOutT, KeypointT, IntensityT > > ConstPtr
Definition: brisk_2d.h:70
int smoothedIntensity(const std::vector< unsigned char > &image, int image_width, int image_height, const std::vector< int > &integral_image, const float key_x, const float key_y, const unsigned int scale, const unsigned int rot, const unsigned int point) const
Compute the smoothed intensity for a given x/y position in the image.
Definition: brisk_2d.hpp:219
pcl::PointCloud< PointOutT > PointCloudOutT
Definition: brisk_2d.h:79
shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:413
shared_ptr< const PointCloud< PointInT > > ConstPtr
Definition: point_cloud.h:414
A point structure representing the Binary Robust Invariant Scalable Keypoints (BRISK).
A point structure representing a 3-D position and scale.