Point Cloud Library (PCL)  1.14.1-dev
susan.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010-2011, Willow Garage, Inc.
6  *
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * * Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * * Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  * * Neither the name of Willow Garage, Inc. nor the names of its
20  * contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  *
36  * $Id$
37  */
38 
39 #pragma once
40 
41 #include <pcl/keypoints/keypoint.h>
42 #include <pcl/common/intensity.h>
43 
44 namespace pcl
45 {
46  /** \brief SUSANKeypoint implements a RGB-D extension of the SUSAN detector including normal
47  * directions variation in top of intensity variation.
48  * It is different from Harris in that it exploits normals directly so it is faster.
49  * Original paper "SUSAN — A New Approach to Low Level Image Processing", Smith,
50  * Stephen M. and Brady, J. Michael
51  *
52  * \author Nizar Sallem
53  * \ingroup keypoints
54  */
55  template <typename PointInT, typename PointOutT, typename NormalT = pcl::Normal, typename IntensityT= pcl::common::IntensityFieldAccessor<PointInT> >
56  class SUSANKeypoint : public Keypoint<PointInT, PointOutT>
57  {
58  public:
59  using Ptr = shared_ptr<SUSANKeypoint<PointInT, PointOutT, NormalT, IntensityT> >;
60  using ConstPtr = shared_ptr<const SUSANKeypoint<PointInT, PointOutT, NormalT, Intensity> >;
61 
65  using PointCloudInConstPtr = typename PointCloudIn::ConstPtr;
66 
68  using PointCloudNPtr = typename PointCloudN::Ptr;
70 
81 
82  /** \brief Constructor
83  * \param[in] radius the radius for normal estimation as well as for non maxima suppression
84  * \param[in] distance_threshold to test if the nucleus is far enough from the centroid
85  * \param[in] angular_threshold to test if normals are parallel
86  * \param[in] intensity_threshold to test if points are of same color
87  */
88  SUSANKeypoint (float radius = 0.01f,
89  float distance_threshold = 0.001f,
90  float angular_threshold = 0.0001f,
91  float intensity_threshold = 7.0f)
92  : distance_threshold_ (distance_threshold)
93  , angular_threshold_ (angular_threshold)
94  , intensity_threshold_ (intensity_threshold)
95  , normals_ (new pcl::PointCloud<NormalT>)
96  {
97  name_ = "SUSANKeypoint";
98  search_radius_ = radius;
99  geometric_validation_ = false;
100  tolerance_ = 2 * distance_threshold_;
101  }
102 
103  /** \brief Empty destructor */
104  ~SUSANKeypoint () override = default;
105 
106  /** \brief set the radius for normal estimation and non maxima supression.
107  * \param[in] radius
108  */
109  void
110  setRadius (float radius);
111 
112  void
113  setDistanceThreshold (float distance_threshold);
114 
115  /** \brief set the angular_threshold value for detecting corners. Normals are considered as
116  * parallel if 1 - angular_threshold <= (Ni.Nj) <= 1
117  * \param[in] angular_threshold
118  */
119  void
120  setAngularThreshold (float angular_threshold);
121 
122  /** \brief set the intensity_threshold value for detecting corners.
123  * \param[in] intensity_threshold
124  */
125  void
126  setIntensityThreshold (float intensity_threshold);
127 
128  /**
129  * \brief set normals if precalculated normals are available.
130  * \param normals
131  */
132  void
133  setNormals (const PointCloudNConstPtr &normals);
134 
135  void
136  setSearchSurface (const PointCloudInConstPtr &cloud) override;
137 
138  /** \brief Initialize the scheduler and set the number of threads to use.
139  * \param nr_threads the number of hardware threads to use (0 sets the value back to automatic)
140  */
141  void
142  setNumberOfThreads (unsigned int nr_threads);
143 
144  /** \brief Apply non maxima suppression to the responses to keep strongest corners.
145  * \note in SUSAN points with less response or stronger corners
146  */
147  void
148  setNonMaxSupression (bool nonmax);
149 
150  /** \brief Filetr false positive using geometric criteria.
151  * The nucleus and the centroid should at least distance_threshold_ from each other AND all the
152  * points belonging to the USAN must be within the segment [nucleus centroid].
153  * \param[in] validate
154  */
155  void
156  setGeometricValidation (bool validate);
157 
158  protected:
159  bool
160  initCompute () override;
161 
162  void
163  detectKeypoints (PointCloudOut &output) override;
164  /** \brief return true if a point lies within the line between the nucleus and the centroid
165  * \param[in] nucleus coordinate of the nucleus
166  * \param[in] centroid of the SUSAN
167  * \param[in] nc to centroid vector (used to speed up since it is constant for a given
168  * neighborhood)
169  * \param[in] point the query point to test against
170  * \return true if the point lies within [nucleus centroid]
171  */
172  bool
173  isWithinNucleusCentroid (const Eigen::Vector3f& nucleus,
174  const Eigen::Vector3f& centroid,
175  const Eigen::Vector3f& nc,
176  const PointInT& point) const;
177  private:
178  float distance_threshold_;
179  float angular_threshold_;
180  float intensity_threshold_;
181  float tolerance_;
182  PointCloudNConstPtr normals_;
183  unsigned int threads_{0};
184  bool geometric_validation_;
185  bool nonmax_;
186  /// intensity field accessor
187  IntensityT intensity_;
188  /** \brief Set to a value different than -1 if the output cloud has a "label" field and we have
189  * to save the keypoints indices.
190  */
191  int label_idx_{-1};
192  /** \brief The list of fields present in the output point cloud data. */
193  std::vector<pcl::PCLPointField> out_fields_;
195  };
196 }
197 
198 #include <pcl/keypoints/impl/susan.hpp>
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
double search_radius_
The nearest neighbors search radius for each point.
Definition: keypoint.h:185
shared_ptr< PointCloud< NormalT > > Ptr
Definition: point_cloud.h:413
shared_ptr< const PointCloud< NormalT > > ConstPtr
Definition: point_cloud.h:414
SUSANKeypoint implements a RGB-D extension of the SUSAN detector including normal directions variatio...
Definition: susan.h:57
shared_ptr< const SUSANKeypoint< PointInT, PointOutT, NormalT, Intensity > > ConstPtr
Definition: susan.h:60
void setIntensityThreshold(float intensity_threshold)
set the intensity_threshold value for detecting corners.
Definition: susan.hpp:83
void setGeometricValidation(bool validate)
Filetr false positive using geometric criteria.
Definition: susan.hpp:55
bool isWithinNucleusCentroid(const Eigen::Vector3f &nucleus, const Eigen::Vector3f &centroid, const Eigen::Vector3f &nc, const PointInT &point) const
return true if a point lies within the line between the nucleus and the centroid
Definition: susan.hpp:256
void setRadius(float radius)
set the radius for normal estimation and non maxima supression.
Definition: susan.hpp:62
typename Keypoint< PointInT, PointOutT >::KdTree KdTree
Definition: susan.h:64
void setNonMaxSupression(bool nonmax)
Apply non maxima suppression to the responses to keep strongest corners.
Definition: susan.hpp:48
~SUSANKeypoint() override=default
Empty destructor.
typename PointCloudN::Ptr PointCloudNPtr
Definition: susan.h:68
typename PointCloudIn::ConstPtr PointCloudInConstPtr
Definition: susan.h:65
void detectKeypoints(PointCloudOut &output) override
Definition: susan.hpp:304
void setDistanceThreshold(float distance_threshold)
Definition: susan.hpp:69
void setSearchSurface(const PointCloudInConstPtr &cloud) override
Definition: susan.hpp:97
shared_ptr< SUSANKeypoint< PointInT, PointOutT, NormalT, IntensityT > > Ptr
Definition: susan.h:59
bool initCompute() override
Definition: susan.hpp:216
typename PointCloudN::ConstPtr PointCloudNConstPtr
Definition: susan.h:69
typename Keypoint< PointInT, PointOutT >::PointCloudOut PointCloudOut
Definition: susan.h:63
void setNumberOfThreads(unsigned int nr_threads)
Initialize the scheduler and set the number of threads to use.
Definition: susan.hpp:105
typename Keypoint< PointInT, PointOutT >::PointCloudIn PointCloudIn
Definition: susan.h:62
void setAngularThreshold(float angular_threshold)
set the angular_threshold value for detecting corners.
Definition: susan.hpp:76
void setNormals(const PointCloudNConstPtr &normals)
set normals if precalculated normals are available.
Definition: susan.hpp:90
SUSANKeypoint(float radius=0.01f, float distance_threshold=0.001f, float angular_threshold=0.0001f, float intensity_threshold=7.0f)
Constructor.
Definition: susan.h:88
A point structure representing normal coordinates and the surface curvature estimate.