Point Cloud Library (PCL)  1.13.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  , threads_ (0)
97  , label_idx_ (-1)
98  {
99  name_ = "SUSANKeypoint";
100  search_radius_ = radius;
101  geometric_validation_ = false;
102  tolerance_ = 2 * distance_threshold_;
103  }
104 
105  /** \brief Empty destructor */
106  ~SUSANKeypoint () override = default;
107 
108  /** \brief set the radius for normal estimation and non maxima supression.
109  * \param[in] radius
110  */
111  void
112  setRadius (float radius);
113 
114  void
115  setDistanceThreshold (float distance_threshold);
116 
117  /** \brief set the angular_threshold value for detecting corners. Normals are considered as
118  * parallel if 1 - angular_threshold <= (Ni.Nj) <= 1
119  * \param[in] angular_threshold
120  */
121  void
122  setAngularThreshold (float angular_threshold);
123 
124  /** \brief set the intensity_threshold value for detecting corners.
125  * \param[in] intensity_threshold
126  */
127  void
128  setIntensityThreshold (float intensity_threshold);
129 
130  /**
131  * \brief set normals if precalculated normals are available.
132  * \param normals
133  */
134  void
135  setNormals (const PointCloudNConstPtr &normals);
136 
137  void
138  setSearchSurface (const PointCloudInConstPtr &cloud) override;
139 
140  /** \brief Initialize the scheduler and set the number of threads to use.
141  * \param nr_threads the number of hardware threads to use (0 sets the value back to automatic)
142  */
143  void
144  setNumberOfThreads (unsigned int nr_threads);
145 
146  /** \brief Apply non maxima suppression to the responses to keep strongest corners.
147  * \note in SUSAN points with less response or stronger corners
148  */
149  void
150  setNonMaxSupression (bool nonmax);
151 
152  /** \brief Filetr false positive using geometric criteria.
153  * The nucleus and the centroid should at least distance_threshold_ from each other AND all the
154  * points belonging to the USAN must be within the segment [nucleus centroid].
155  * \param[in] validate
156  */
157  void
158  setGeometricValidation (bool validate);
159 
160  protected:
161  bool
162  initCompute () override;
163 
164  void
165  detectKeypoints (PointCloudOut &output) override;
166  /** \brief return true if a point lies within the line between the nucleus and the centroid
167  * \param[in] nucleus coordinate of the nucleus
168  * \param[in] centroid of the SUSAN
169  * \param[in] nc to centroid vector (used to speed up since it is constant for a given
170  * neighborhood)
171  * \param[in] point the query point to test against
172  * \return true if the point lies within [nucleus centroid]
173  */
174  bool
175  isWithinNucleusCentroid (const Eigen::Vector3f& nucleus,
176  const Eigen::Vector3f& centroid,
177  const Eigen::Vector3f& nc,
178  const PointInT& point) const;
179  private:
180  float distance_threshold_;
181  float angular_threshold_;
182  float intensity_threshold_;
183  float tolerance_;
184  PointCloudNConstPtr normals_;
185  unsigned int threads_;
186  bool geometric_validation_;
187  bool nonmax_;
188  /// intensity field accessor
189  IntensityT intensity_;
190  /** \brief Set to a value different than -1 if the output cloud has a "label" field and we have
191  * to save the keypoints indices.
192  */
193  int label_idx_;
194  /** \brief The list of fields present in the output point cloud data. */
195  std::vector<pcl::PCLPointField> out_fields_;
197  };
198 }
199 
200 #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:169
double search_radius_
The nearest neighbors search radius for each point.
Definition: keypoint.h:187
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.