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