Point Cloud Library (PCL)  1.14.1-dev
sift_keypoint.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2010, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Willow Garage, Inc. nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *
34  */
35 
36 #pragma once
37 
38 #include <pcl/keypoints/keypoint.h>
39 
40 namespace pcl
41 {
42  template<typename PointT>
44  {
45  inline float
46  operator () (const PointT & p) const
47  {
48  return p.intensity;
49  }
50  };
51  template<>
53  {
54  inline float
55  operator () (const PointNormal & p) const
56  {
57  return p.curvature;
58  }
59  };
60  template<>
62  {
63  inline float
64  operator () (const PointXYZRGB & p) const
65  {
66  return (static_cast<float> (299*p.r + 587*p.g + 114*p.b) / 1000.0f);
67  }
68  };
69  template<>
71  {
72  inline float
73  operator () (const PointXYZRGBA & p) const
74  {
75  return (static_cast<float> (299*p.r + 587*p.g + 114*p.b) / 1000.0f);
76  }
77  };
78 
79  /** \brief @b SIFTKeypoint detects the Scale Invariant Feature Transform
80  * keypoints for a given point cloud dataset containing points and intensity.
81  * This implementation adapts the original algorithm from images to point
82  * clouds.
83  *
84  * For more information about the image-based SIFT interest operator, see:
85  *
86  * David G. Lowe, "Distinctive image features from scale-invariant keypoints,"
87  * International Journal of Computer Vision, 60, 2 (2004), pp. 91-110.
88  *
89  * \author Michael Dixon
90  * \ingroup keypoints
91  */
92  template <typename PointInT, typename PointOutT>
93  class SIFTKeypoint : public Keypoint<PointInT, PointOutT>
94  {
95  public:
96  using Ptr = shared_ptr<SIFTKeypoint<PointInT, PointOutT> >;
97  using ConstPtr = shared_ptr<const SIFTKeypoint<PointInT, PointOutT> >;
98 
102 
109 
110  /** \brief Empty constructor. */
112  min_contrast_ (-std::numeric_limits<float>::max ()),
113  getFieldValue_ ()
114  {
115  name_ = "SIFTKeypoint";
116  }
117 
118  /** \brief Specify the range of scales over which to search for keypoints
119  * \param min_scale the standard deviation of the smallest scale in the scale space
120  * \param nr_octaves the number of octaves (i.e. doublings of scale) to compute
121  * \param nr_scales_per_octave the number of scales to compute within each octave
122  */
123  void
124  setScales (float min_scale, int nr_octaves, int nr_scales_per_octave);
125 
126  /** \brief Provide a threshold to limit detection of keypoints without sufficient contrast
127  * \param min_contrast the minimum contrast required for detection
128  */
129  void
130  setMinimumContrast (float min_contrast);
131 
132  protected:
133  bool
134  initCompute () override;
135 
136  /** \brief Detect the SIFT keypoints for a set of points given in setInputCloud () using the spatial locator in
137  * setSearchMethod ().
138  * \param output the resultant cloud of keypoints
139  */
140  void
141  detectKeypoints (PointCloudOut &output) override;
142 
143  private:
144  /** \brief Detect the SIFT keypoints for a given point cloud for a single octave.
145  * \param input the point cloud to detect keypoints in
146  * \param tree a k-D tree of the points in \a input
147  * \param base_scale the first (smallest) scale in the octave
148  * \param nr_scales_per_octave the number of scales to to compute
149  * \param output the resultant point cloud containing the SIFT keypoints
150  */
151  void
152  detectKeypointsForOctave (const PointCloudIn &input, KdTree &tree,
153  float base_scale, int nr_scales_per_octave,
154  PointCloudOut &output);
155 
156  /** \brief Compute the difference-of-Gaussian (DoG) scale space for the given input and scales
157  * \param input the point cloud for which the DoG scale space will be computed
158  * \param tree a k-D tree of the points in \a input
159  * \param scales a vector containing the scales over which to compute the DoG scale space
160  * \param diff_of_gauss the resultant DoG scale space (in a number-of-points by number-of-scales matrix)
161  */
162  void
163  computeScaleSpace (const PointCloudIn &input, KdTree &tree,
164  const std::vector<float> &scales,
165  Eigen::MatrixXf &diff_of_gauss);
166 
167  /** \brief Find the local minima and maxima in the provided difference-of-Gaussian (DoG) scale space
168  * \param input the input point cloud
169  * \param tree a k-D tree of the points in \a input
170  * \param diff_of_gauss the DoG scale space (in a number-of-points by number-of-scales matrix)
171  * \param extrema_indices the resultant vector containing the point indices of each keypoint
172  * \param extrema_scales the resultant vector containing the scale indices of each keypoint
173  */
174  void
175  findScaleSpaceExtrema (const PointCloudIn &input, KdTree &tree,
176  const Eigen::MatrixXf &diff_of_gauss,
177  pcl::Indices &extrema_indices, std::vector<int> &extrema_scales);
178 
179 
180  /** \brief The standard deviation of the smallest scale in the scale space.*/
181  float min_scale_{0.0};
182 
183  /** \brief The number of octaves (i.e. doublings of scale) over which to search for keypoints.*/
184  int nr_octaves_{0};
185 
186  /** \brief The number of scales to be computed for each octave.*/
187  int nr_scales_per_octave_{0};
188 
189  /** \brief The minimum contrast required for detection.*/
190  float min_contrast_;
191 
192  /** \brief Set to a value different than -1 if the output cloud has a "scale" field and we have to save
193  * the keypoints scales. */
194  int scale_idx_{-1};
195 
196  /** \brief The list of fields present in the output point cloud data. */
197  std::vector<pcl::PCLPointField> out_fields_;
198 
199  SIFTKeypointFieldSelector<PointInT> getFieldValue_;
200  };
201 }
202 
203 #include <pcl/keypoints/impl/sift_keypoint.hpp>
KdTree represents the base spatial locator class for kd-tree implementations.
Definition: kdtree.h:56
Keypoint represents the base class for key points.
Definition: keypoint.h:49
std::string name_
The key point detection method's name.
Definition: keypoint.h:167
SIFTKeypoint detects the Scale Invariant Feature Transform keypoints for a given point cloud dataset ...
Definition: sift_keypoint.h:94
shared_ptr< SIFTKeypoint< PointInT, PointOutT > > Ptr
Definition: sift_keypoint.h:96
bool initCompute() override
void setMinimumContrast(float min_contrast)
Provide a threshold to limit detection of keypoints without sufficient contrast.
typename Keypoint< PointInT, PointOutT >::KdTree KdTree
SIFTKeypoint()
Empty constructor.
shared_ptr< const SIFTKeypoint< PointInT, PointOutT > > ConstPtr
Definition: sift_keypoint.h:97
void setScales(float min_scale, int nr_octaves, int nr_scales_per_octave)
Specify the range of scales over which to search for keypoints.
void detectKeypoints(PointCloudOut &output) override
Detect the SIFT keypoints for a set of points given in setInputCloud () using the spatial locator in ...
typename Keypoint< PointInT, PointOutT >::PointCloudIn PointCloudIn
Definition: sift_keypoint.h:99
typename Keypoint< PointInT, PointOutT >::PointCloudOut PointCloudOut
IndicesAllocator<> Indices
Type used for indices in PCL.
Definition: types.h:133
A point structure representing Euclidean xyz coordinates, together with normal coordinates and the su...
A point structure representing Euclidean xyz coordinates, and the RGBA color.
A point structure representing Euclidean xyz coordinates, and the RGB color.
float operator()(const PointT &p) const
Definition: sift_keypoint.h:46