Point Cloud Library (PCL)  1.7.1
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 #ifndef PCL_SUSAN_KEYPOINT_H_
40 #define PCL_SUSAN_KEYPOINT_H_
41 
42 #include <pcl/keypoints/keypoint.h>
43 #include <pcl/common/intensity.h>
44 
45 namespace pcl
46 {
47  /** \brief SUSANKeypoint implements a RGB-D extension of the SUSAN detector inluding normal
48  * directions variation in top of intensity variation.
49  * It is different from Harris in that it exploits normals directly so it is faster.
50  * Original paper "SUSAN — A New Approach to Low Level Image Processing", Smith,
51  * Stephen M. and Brady, J. Michael
52  *
53  * \author Nizar Sallem
54  * \ingroup keypoints
55  */
56  template <typename PointInT, typename PointOutT, typename NormalT = pcl::Normal, typename IntensityT= pcl::common::IntensityFieldAccessor<PointInT> >
57  class SUSANKeypoint : public Keypoint<PointInT, PointOutT>
58  {
59  public:
60  typedef boost::shared_ptr<SUSANKeypoint<PointInT, PointOutT, NormalT, IntensityT> > Ptr;
61  typedef boost::shared_ptr<const SUSANKeypoint<PointInT, PointOutT, NormalT, Intensity> > ConstPtr;
62 
67 
69  typedef typename PointCloudN::Ptr PointCloudNPtr;
71 
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  , out_fields_ ()
99  {
100  name_ = "SUSANKeypoint";
101  search_radius_ = radius;
102  geometric_validation_ = false;
103  tolerance_ = 2 * distance_threshold_;
104  }
105 
106  /** \brief Empty destructor */
107  virtual ~SUSANKeypoint () {}
108 
109  /** \brief set the radius for normal estimation and non maxima supression.
110  * \param[in] radius
111  */
112  void
113  setRadius (float radius);
114 
115  void
116  setDistanceThreshold (float distance_threshold);
117 
118  /** \brief set the angular_threshold value for detecting corners. Normals are considered as
119  * parallel if 1 - angular_threshold <= (Ni.Nj) <= 1
120  * \param[in] angular_threshold
121  */
122  void
123  setAngularThreshold (float angular_threshold);
124 
125  /** \brief set the intensity_threshold value for detecting corners.
126  * \param[in] intensity_threshold
127  */
128  void
129  setIntensityThreshold (float intensity_threshold);
130 
131  /**
132  * \brief set normals if precalculated normals are available.
133  * \param normals
134  */
135  void
136  setNormals (const PointCloudNConstPtr &normals);
137 
138  virtual void
139  setSearchSurface (const PointCloudInConstPtr &cloud);
140 
141  /** \brief Initialize the scheduler and set the number of threads to use.
142  * \param nr_threads the number of hardware threads to use (0 sets the value back to automatic)
143  */
144  void
145  setNumberOfThreads (unsigned int nr_threads);
146 
147  /** \brief Apply non maxima suppression to the responses to keep strongest corners.
148  * \note in SUSAN points with less response or stronger corners
149  */
150  void
151  setNonMaxSupression (bool nonmax);
152 
153  /** \brief Filetr false positive using geometric criteria.
154  * The nucleus and the centroid should at least distance_threshold_ from each other AND all the
155  * points belonging to the USAN must be within the segment [nucleus centroid].
156  * \param[in] validate
157  */
158  void
159  setGeometricValidation (bool validate);
160 
161  protected:
162  bool
163  initCompute ();
164 
165  void
166  detectKeypoints (PointCloudOut &output);
167  /** \brief return true if a point lies within the line between the nucleus and the centroid
168  * \param[in] nucleus coordinate of the nucleus
169  * \param[in] centroid of the USAN
170  * \parma[in] nucleus to centroid vector (used to speed up since it is constant for a given
171  * neighborhood)
172  * \param[in] point the query point to test against
173  * \return true if the point lies within [nucleus centroid]
174  */
175  bool
176  isWithinNucleusCentroid (const Eigen::Vector3f& nucleus,
177  const Eigen::Vector3f& centroid,
178  const Eigen::Vector3f& nc,
179  const PointInT& point) const;
180  private:
181  float distance_threshold_;
182  float angular_threshold_;
183  float intensity_threshold_;
184  float tolerance_;
185  PointCloudNConstPtr normals_;
186  unsigned int threads_;
187  bool geometric_validation_;
188  bool nonmax_;
189  /// intensity field accessor
190  IntensityT intensity_;
191  /** \brief Set to a value different than -1 if the output cloud has a "label" field and we have
192  * to save the keypoints indices.
193  */
194  int label_idx_;
195  /** \brief The list of fields present in the output point cloud data. */
196  std::vector<pcl::PCLPointField> out_fields_;
198  };
199 }
200 
201 #include <pcl/keypoints/impl/susan.hpp>
202 
203 #endif // #ifndef PCL_SUSAN_KEYPOINT_H_