Point Cloud Library (PCL)  1.8.1
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 #ifndef PCL_FEATURES_BRISK_2D_H_
41 #define PCL_FEATURES_BRISK_2D_H_
42 
43 // PCL includes
44 #include <pcl/features/feature.h>
45 #include <pcl/common/eigen.h>
46 #include <pcl/common/centroid.h>
47 #include <pcl/common/intensity.h>
48 
49 namespace pcl
50 {
51  /** \brief Implementation of the BRISK-descriptor, based on the original code and paper reference by
52  *
53  * \par
54  * Stefan Leutenegger,Margarita Chli and Roland Siegwart,
55  * BRISK: Binary Robust Invariant Scalable Keypoints,
56  * in Proceedings of the IEEE International Conference on Computer Vision (ICCV2011).
57  *
58  * \warning The input keypoints cloud is not const, and it will be modified: keypoints for which descriptors can not
59  * be computed will be deleted from the cloud.
60  *
61  * \author Radu B. Rusu, Stefan Holzer
62  * \ingroup features
63  */
64  template <typename PointInT,
65  typename PointOutT = pcl::BRISKSignature512,
66  typename KeypointT = pcl::PointWithScale,
67  typename IntensityT = pcl::common::IntensityFieldAccessor<PointInT> >
68  class BRISK2DEstimation// : public Feature<PointT, KeyPointT>
69  {
70  public:
71  typedef boost::shared_ptr<BRISK2DEstimation<PointInT, PointOutT, KeypointT, IntensityT> > Ptr;
72  typedef boost::shared_ptr<const BRISK2DEstimation<PointInT, PointOutT, KeypointT, IntensityT> > ConstPtr;
73 
76 
80 
82 
83  /** \brief Constructor. */
85 
86  /** \brief Destructor. */
87  virtual ~BRISK2DEstimation ();
88 
89  /** \brief Determines whether rotation invariance is enabled.
90  * \param[in] enable determines whether rotation invariance is enabled.
91  */
92  inline void
93  setRotationInvariance (const bool enable)
94  {
95  rotation_invariance_enabled_ = enable;
96  }
97 
98  /** \brief Determines whether scale invariance is enabled.
99  * \param[in] enable determines whether scale invariance is enabled.
100  */
101  inline void
102  setScaleInvariance (const bool enable)
103  {
104  scale_invariance_enabled_ = enable;
105  }
106 
107  /** \brief Sets the input cloud.
108  * \param[in] cloud the input cloud.
109  */
110  inline void
111  setInputCloud (const PointCloudInTConstPtr & cloud)
112  {
113  input_cloud_ = cloud;
114  }
115 
116  /** \brief Sets the input keypoints.
117  * \param[in] keypoints the input cloud containing the keypoints.
118  */
119  inline void
120  setKeypoints (const KeypointPointCloudTPtr &keypoints)
121  {
122  // Make a copy as we will have to erase keypoints that we don't use
123  // TO DO: change this later
124  //keypoints_.reset (new KeypointPointCloudT (*keypoints));
125  keypoints_ = keypoints;
126  }
127 
128  /** \brief Computes the descriptors for the previously specified
129  * points and input data.
130  * \param[out] output descriptors the destination for the computed descriptors.
131  */
132  void
133  compute (PointCloudOutT &output);
134  //td::vector<pcl::features::brisk::BRISKDescriptor> & descriptors) const;
135 
136  protected:
137  /** \brief Call this to generate the kernel:
138  * circle of radius r (pixels), with n points;
139  * short pairings with dMax, long pairings with dMin
140  *
141  * \note This should never be called by a regular user. We use a fixed type in PCL
142  * (BRISKSignature512) and tampering with the parameters might lead to a different
143  * size descriptor which the user needs to accomodate in a new point type.
144  */
145  void
146  generateKernel (std::vector<float> &radius_list,
147  std::vector<int> &number_list,
148  float d_max = 5.85f, float d_min = 8.2f,
149  std::vector<int> index_change = std::vector<int> ());
150 
151  /** \brief Compute the smoothed intensity for a given x/y position in the image. */
152  inline int
153  smoothedIntensity (const std::vector<unsigned char>& image,
154  int image_width, int image_height,
155  const std::vector<int>& integral_image,
156  const float key_x, const float key_y, const unsigned int scale,
157  const unsigned int rot, const unsigned int point) const;
158 
159  private:
160  /** \brief ROI predicate comparator. */
161  bool
162  RoiPredicate (const float min_x, const float min_y,
163  const float max_x, const float max_y, const KeypointT& key_pt);
164 
165  /** \brief Specifies whether rotation invariance is enabled. */
166  bool rotation_invariance_enabled_;
167 
168  /** \brief Specifies whether scale invariance is enabled. */
169  bool scale_invariance_enabled_;
170 
171  /** \brief Specifies the scale of the pattern. */
172  const float pattern_scale_;
173 
174  /** \brief the input cloud. */
175  PointCloudInTConstPtr input_cloud_;
176 
177  /** \brief the input keypoints. */
178  KeypointPointCloudTPtr keypoints_;
179 
180  // TODO: set
181  float scale_range_;
182 
183  // Some helper structures for the Brisk pattern representation
184  struct BriskPatternPoint
185  {
186  /** x coordinate relative to center. */
187  float x;
188  /** x coordinate relative to center. */
189  float y;
190  /** Gaussian smoothing sigma. */
191  float sigma;
192  };
193 
194  struct BriskShortPair
195  {
196  /** index of the first pattern point. */
197  unsigned int i;
198  /** index of other pattern point. */
199  unsigned int j;
200  };
201 
202  struct BriskLongPair
203  {
204  /** index of the first pattern point. */
205  unsigned int i;
206  /** index of other pattern point. */
207  unsigned int j;
208  /** 1024.0/dx. */
209  int weighted_dx;
210  /** 1024.0/dy. */
211  int weighted_dy;
212  };
213 
214  // pattern properties
215  /** [i][rotation][scale]. */
216  BriskPatternPoint* pattern_points_;
217 
218  /** Total number of collocation points. */
219  unsigned int points_;
220 
221  /** Discretization of the rotation look-up. */
222  const unsigned int n_rot_;
223 
224  /** Lists the scaling per scale index [scale]. */
225  float* scale_list_;
226 
227  /** Lists the total pattern size per scale index [scale]. */
228  unsigned int* size_list_;
229 
230  /** Scales discretization. */
231  const unsigned int scales_;
232 
233  /** Span of sizes 40->4 Octaves - else, this needs to be adjusted... */
234  const float scalerange_;
235 
236  // general
237  const float basic_size_;
238 
239  // pairs
240  /** Number of uchars the descriptor consists of. */
241  int strings_;
242  /** Short pair maximum distance. */
243  float d_max_;
244  /** Long pair maximum distance. */
245  float d_min_;
246  /** d<_d_max. */
247  BriskShortPair* short_pairs_;
248  /** d>_d_min. */
249  BriskLongPair* long_pairs_;
250  /** Number of short pairs. */
251  unsigned int no_short_pairs_;
252  /** Number of long pairs. */
253  unsigned int no_long_pairs_;
254 
255  /** \brief Intensity field accessor. */
256  IntensityT intensity_;
257 
258  /** \brief The name of the class. */
259  std::string name_;
260  };
261 
262 }
263 
264 #include <pcl/features/impl/brisk_2d.hpp>
265 
266 #endif //#ifndef PCL_FEATURES_BRISK_2D_H_
void compute(PointCloudOutT &output)
Computes the descriptors for the previously specified points and input data.
Definition: brisk_2d.hpp:447
pcl::PointCloud< KeypointT >::ConstPtr KeypointPointCloudTConstPtr
Definition: brisk_2d.h:79
pcl::PointCloud< KeypointT > KeypointPointCloudT
Definition: brisk_2d.h:77
void setRotationInvariance(const bool enable)
Determines whether rotation invariance is enabled.
Definition: brisk_2d.h:93
void setScaleInvariance(const bool enable)
Determines whether scale invariance is enabled.
Definition: brisk_2d.h:102
A point structure representing the Binary Robust Invariant Scalable Keypoints (BRISK).
pcl::PointCloud< PointInT >::ConstPtr PointCloudInTConstPtr
Definition: brisk_2d.h:75
Implementation of the BRISK-descriptor, based on the original code and paper reference by...
Definition: brisk_2d.h:68
void setKeypoints(const KeypointPointCloudTPtr &keypoints)
Sets the input keypoints.
Definition: brisk_2d.h:120
boost::shared_ptr< BRISK2DEstimation< PointInT, PointOutT, KeypointT, IntensityT > > Ptr
Definition: brisk_2d.h:71
boost::shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:428
pcl::PointCloud< PointOutT > PointCloudOutT
Definition: brisk_2d.h:81
boost::shared_ptr< const BRISK2DEstimation< PointInT, PointOutT, KeypointT, IntensityT > > ConstPtr
Definition: brisk_2d.h:72
boost::shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:429
void setInputCloud(const PointCloudInTConstPtr &cloud)
Sets the input cloud.
Definition: brisk_2d.h:111
pcl::PointCloud< PointInT > PointCloudInT
Definition: brisk_2d.h:74
virtual ~BRISK2DEstimation()
Destructor.
Definition: brisk_2d.hpp:86
A point structure representing a 3-D position and scale.
BRISK2DEstimation()
Constructor.
Definition: brisk_2d.hpp:45
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:97
pcl::PointCloud< KeypointT >::Ptr KeypointPointCloudTPtr
Definition: brisk_2d.h:78
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
Define methods for centroid estimation and covariance matrix calculus.