Point Cloud Library (PCL) 1.15.1-dev
Loading...
Searching...
No Matches
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#include <pcl/point_types.h> // for PointNormal, PointXYZRGB, PointXYZRGBA
40
41namespace pcl
42{
43 template<typename PointT>
45 {
46 inline float
47 operator () (const PointT & p) const
48 {
49 return p.intensity;
50 }
51 };
52 template<>
54 {
55 inline float
56 operator () (const PointNormal & p) const
57 {
58 return p.curvature;
59 }
60 };
61 template<>
63 {
64 inline float
65 operator () (const PointXYZRGB & p) const
66 {
67 return (static_cast<float> (299*p.r + 587*p.g + 114*p.b) / 1000.0f);
68 }
69 };
70 template<>
72 {
73 inline float
74 operator () (const PointXYZRGBA & p) const
75 {
76 return (static_cast<float> (299*p.r + 587*p.g + 114*p.b) / 1000.0f);
77 }
78 };
79
80 /** \brief @b SIFTKeypoint detects the Scale Invariant Feature Transform
81 * keypoints for a given point cloud dataset containing points and intensity.
82 * This implementation adapts the original algorithm from images to point
83 * clouds.
84 *
85 * For more information about the image-based SIFT interest operator, see:
86 *
87 * David G. Lowe, "Distinctive image features from scale-invariant keypoints,"
88 * International Journal of Computer Vision, 60, 2 (2004), pp. 91-110.
89 *
90 * \author Michael Dixon
91 * \ingroup keypoints
92 */
93 template <typename PointInT, typename PointOutT>
94 class SIFTKeypoint : public Keypoint<PointInT, PointOutT>
95 {
96 public:
97 using Ptr = shared_ptr<SIFTKeypoint<PointInT, PointOutT> >;
98 using ConstPtr = shared_ptr<const SIFTKeypoint<PointInT, PointOutT> >;
99
103
104 using Keypoint<PointInT, PointOutT>::name_;
105 using Keypoint<PointInT, PointOutT>::input_;
106 using Keypoint<PointInT, PointOutT>::indices_;
107 using Keypoint<PointInT, PointOutT>::surface_;
108 using Keypoint<PointInT, PointOutT>::tree_;
109 using Keypoint<PointInT, PointOutT>::initCompute;
110
111 /** \brief Empty constructor. */
113 min_contrast_ (-std::numeric_limits<float>::max ()),
114 getFieldValue_ ()
115 {
116 name_ = "SIFTKeypoint";
117 }
118
119 /** \brief Specify the range of scales over which to search for keypoints
120 * \param min_scale the standard deviation of the smallest scale in the scale space
121 * \param nr_octaves the number of octaves (i.e. doublings of scale) to compute
122 * \param nr_scales_per_octave the number of scales to compute within each octave
123 */
124 void
125 setScales (float min_scale, int nr_octaves, int nr_scales_per_octave);
126
127 /** \brief Provide a threshold to limit detection of keypoints without sufficient contrast
128 * \param min_contrast the minimum contrast required for detection
129 */
130 void
131 setMinimumContrast (float min_contrast);
132
133 protected:
134 bool
135 initCompute () override;
136
137 /** \brief Detect the SIFT keypoints for a set of points given in setInputCloud () using the spatial locator in
138 * setSearchMethod ().
139 * \param output the resultant cloud of keypoints
140 */
141 void
142 detectKeypoints (PointCloudOut &output) override;
143
144 private:
145 /** \brief Detect the SIFT keypoints for a given point cloud for a single octave.
146 * \param input the point cloud to detect keypoints in
147 * \param tree a k-D tree of the points in \a input
148 * \param base_scale the first (smallest) scale in the octave
149 * \param nr_scales_per_octave the number of scales to to compute
150 * \param output the resultant point cloud containing the SIFT keypoints
151 */
152 void
153 detectKeypointsForOctave (const PointCloudIn &input, KdTree &tree,
154 float base_scale, int nr_scales_per_octave,
155 PointCloudOut &output);
156
157 /** \brief Compute the difference-of-Gaussian (DoG) scale space for the given input and scales
158 * \param input the point cloud for which the DoG scale space will be computed
159 * \param tree a k-D tree of the points in \a input
160 * \param scales a vector containing the scales over which to compute the DoG scale space
161 * \param diff_of_gauss the resultant DoG scale space (in a number-of-points by number-of-scales matrix)
162 */
163 void
164 computeScaleSpace (const PointCloudIn &input, KdTree &tree,
165 const std::vector<float> &scales,
166 Eigen::MatrixXf &diff_of_gauss);
167
168 /** \brief Find the local minima and maxima in the provided difference-of-Gaussian (DoG) scale space
169 * \param input the input point cloud
170 * \param tree a k-D tree of the points in \a input
171 * \param diff_of_gauss the DoG scale space (in a number-of-points by number-of-scales matrix)
172 * \param extrema_indices the resultant vector containing the point indices of each keypoint
173 * \param extrema_scales the resultant vector containing the scale indices of each keypoint
174 */
175 void
176 findScaleSpaceExtrema (const PointCloudIn &input, KdTree &tree,
177 const Eigen::MatrixXf &diff_of_gauss,
178 pcl::Indices &extrema_indices, std::vector<int> &extrema_scales);
179
180
181 /** \brief The standard deviation of the smallest scale in the scale space.*/
182 float min_scale_{0.0};
183
184 /** \brief The number of octaves (i.e. doublings of scale) over which to search for keypoints.*/
185 int nr_octaves_{0};
186
187 /** \brief The number of scales to be computed for each octave.*/
188 int nr_scales_per_octave_{0};
189
190 /** \brief The minimum contrast required for detection.*/
191 float min_contrast_;
192
193 /** \brief Set to a value different than -1 if the output cloud has a "scale" field and we have to save
194 * the keypoints scales. */
195 int scale_idx_{-1};
196
197 /** \brief The list of fields present in the output point cloud data. */
198 std::vector<pcl::PCLPointField> out_fields_;
199
200 SIFTKeypointFieldSelector<PointInT> getFieldValue_;
201 };
202}
203
204#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
KdTreePtr tree_
A pointer to the spatial search object.
Definition keypoint.h:179
PointCloudInConstPtr surface_
An input point cloud describing the surface that is to be used for nearest neighbors estimation.
Definition keypoint.h:176
PointCloudConstPtr input_
The input point cloud dataset.
Definition pcl_base.h:147
IndicesPtr indices_
A pointer to the vector of point indices to use.
Definition pcl_base.h:150
SIFTKeypoint detects the Scale Invariant Feature Transform keypoints for a given point cloud dataset ...
shared_ptr< SIFTKeypoint< PointInT, PointOutT > > Ptr
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
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
typename Keypoint< PointInT, PointOutT >::PointCloudOut PointCloudOut
Defines all the PCL implemented PointT point type structures.
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