Point Cloud Library (PCL)  1.8.0
harris_2d.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 
40 #ifndef PCL_HARRIS_KEYPOINT_2D_H_
41 #define PCL_HARRIS_KEYPOINT_2D_H_
42 
43 #include <pcl/keypoints/keypoint.h>
44 #include <pcl/common/intensity.h>
45 
46 namespace pcl
47 {
48  /** \brief HarrisKeypoint2D detects Harris corners family points
49  *
50  * \author Nizar Sallem
51  * \ingroup keypoints
52  */
53  template <typename PointInT, typename PointOutT, typename IntensityT = pcl::common::IntensityFieldAccessor<PointInT> >
54  class HarrisKeypoint2D : public Keypoint<PointInT, PointOutT>
55  {
56  public:
57  typedef boost::shared_ptr<HarrisKeypoint2D<PointInT, PointOutT, IntensityT> > Ptr;
58  typedef boost::shared_ptr<const HarrisKeypoint2D<PointInT, PointOutT, IntensityT> > ConstPtr;
59 
64 
69 
70  typedef enum {HARRIS = 1, NOBLE, LOWE, TOMASI} ResponseMethod;
71 
72  /** \brief Constructor
73  * \param[in] method the method to be used to determine the corner responses
74  * \param window_width
75  * \param window_height
76  * \param min_distance
77  * \param[in] threshold the threshold to filter out weak corners
78  */
79  HarrisKeypoint2D (ResponseMethod method = HARRIS, int window_width = 3, int window_height = 3, int min_distance = 5, float threshold = 0.0)
80  : threshold_ (threshold)
81  , refine_ (false)
82  , nonmax_ (true)
83  , method_ (method)
84  , threads_ (0)
85  , response_ (new pcl::PointCloud<PointOutT> ())
86  , window_width_ (window_width)
87  , window_height_ (window_height)
88  , skipped_pixels_ (0)
89  , min_distance_ (min_distance)
90  {
91  name_ = "HarrisKeypoint2D";
92  }
93 
94  /** \brief set the method of the response to be calculated.
95  * \param[in] type
96  */
97  void setMethod (ResponseMethod type);
98 
99  ///Set window width
100  void setWindowWidth (int window_width);
101 
102  ///Set window height
103  void setWindowHeight (int window_height);
104 
105  ///Set number of pixels to skip
106  void setSkippedPixels (int skipped_pixels);
107 
108  ///Set minimal distance between candidate keypoints
109  void setMinimalDistance (int min_distance);
110 
111  /** \brief set the threshold value for detecting corners. This is only evaluated if non maxima suppression is turned on.
112  * \brief note non maxima suppression needs to be activated in order to use this feature.
113  * \param[in] threshold
114  */
115  void setThreshold (float threshold);
116 
117  /** \brief whether non maxima suppression should be applied or the response for each point should be returned
118  * \note this value needs to be turned on in order to apply thresholding and refinement
119  * \param[in] nonmax default is false
120  */
121  void setNonMaxSupression (bool = false);
122 
123  /** \brief whether the detected key points should be refined or not. If turned of, the key points are a subset of
124  * the original point cloud. Otherwise the key points may be arbitrary.
125  * \brief note non maxima supression needs to be on in order to use this feature.
126  * \param[in] do_refine
127  */
128  void setRefine (bool do_refine);
129 
130  /** \brief Initialize the scheduler and set the number of threads to use.
131  * \param nr_threads the number of hardware threads to use (0 sets the value back to automatic)
132  */
133  inline void
134  setNumberOfThreads (unsigned int nr_threads = 0) { threads_ = nr_threads; }
135 
136  protected:
137  bool
138  initCompute ();
139  void
140  detectKeypoints (PointCloudOut &output);
141  /** \brief gets the corner response for valid input points*/
142  void
143  responseHarris (PointCloudOut &output) const;
144  void
145  responseNoble (PointCloudOut &output) const;
146  void
147  responseLowe (PointCloudOut &output) const;
148  void
149  responseTomasi (PointCloudOut &output) const;
150 // void refineCorners (PointCloudOut &corners) const;
151  /** \brief calculates the upper triangular part of unnormalized
152  * covariance matrix over intensities given by the 2D coordinates
153  * and window_width_ and window_height_
154  */
155  void
156  computeSecondMomentMatrix (std::size_t pos, float* coefficients) const;
157  /// threshold for non maxima suppression
158  float threshold_;
159  /// corner refinement
160  bool refine_;
161  /// non maximas suppression
162  bool nonmax_;
163  /// cornerness computation methode
164  ResponseMethod method_;
165  /// number of threads to be used
166  unsigned int threads_;
167 
168  private:
169  Eigen::MatrixXf derivatives_rows_;
170  Eigen::MatrixXf derivatives_cols_;
171  /// intermediate holder for computed responses
172  boost::shared_ptr<pcl::PointCloud<PointOutT> > response_;
173  /// comparator for responses intensity
174  bool
175  greaterIntensityAtIndices (int a, int b) const
176  {
177  return (response_->at (a).intensity > response_->at (b).intensity);
178  }
179  /// Window width
180  int window_width_;
181  /// Window height
182  int window_height_;
183  /// half window width
184  int half_window_width_;
185  /// half window height
186  int half_window_height_;
187  /// number of pixels to skip within search window
188  int skipped_pixels_;
189  /// minimum distance between two keypoints
190  int min_distance_;
191  /// intensity field accessor
192  IntensityT intensity_;
193  };
194 }
195 
196 #include <pcl/keypoints/impl/harris_2d.hpp>
197 
198 #endif // #ifndef PCL_HARRIS_KEYPOINT_2D_H_
void setMethod(ResponseMethod type)
set the method of the response to be calculated.
Definition: harris_2d.hpp:45
void setWindowHeight(int window_height)
Set window height.
Definition: harris_2d.hpp:80
std::string name_
The key point detection method&#39;s name.
Definition: keypoint.h:173
void setNonMaxSupression(bool=false)
whether non maxima suppression should be applied or the response for each point should be returned ...
Definition: harris_2d.hpp:66
void setMinimalDistance(int min_distance)
Set minimal distance between candidate keypoints.
Definition: harris_2d.hpp:94
void responseTomasi(PointCloudOut &output) const
Definition: harris_2d.hpp:401
void setRefine(bool do_refine)
whether the detected key points should be refined or not.
Definition: harris_2d.hpp:59
bool nonmax_
non maximas suppression
Definition: harris_2d.h:162
ResponseMethod method_
cornerness computation methode
Definition: harris_2d.h:164
Keypoint represents the base class for key points.
Definition: keypoint.h:49
boost::shared_ptr< const HarrisKeypoint2D< PointInT, PointOutT, IntensityT > > ConstPtr
Definition: harris_2d.h:58
Keypoint< PointInT, PointOutT >::PointCloudOut PointCloudOut
Definition: harris_2d.h:61
boost::shared_ptr< HarrisKeypoint2D< PointInT, PointOutT, IntensityT > > Ptr
Definition: harris_2d.h:57
unsigned int threads_
number of threads to be used
Definition: harris_2d.h:166
boost::shared_ptr< const PointCloud< PointInT > > ConstPtr
Definition: point_cloud.h:429
HarrisKeypoint2D(ResponseMethod method=HARRIS, int window_width=3, int window_height=3, int min_distance=5, float threshold=0.0)
Constructor.
Definition: harris_2d.h:79
void responseHarris(PointCloudOut &output) const
gets the corner response for valid input points
Definition: harris_2d.hpp:293
void responseLowe(PointCloudOut &output) const
Definition: harris_2d.hpp:365
float threshold_
threshold for non maxima suppression
Definition: harris_2d.h:158
bool refine_
corner refinement
Definition: harris_2d.h:160
void detectKeypoints(PointCloudOut &output)
Abstract key point detection method.
Definition: harris_2d.hpp:173
void setSkippedPixels(int skipped_pixels)
Set number of pixels to skip.
Definition: harris_2d.hpp:87
void setWindowWidth(int window_width)
Set window width.
Definition: harris_2d.hpp:73
void setThreshold(float threshold)
set the threshold value for detecting corners.
Definition: harris_2d.hpp:52
void setNumberOfThreads(unsigned int nr_threads=0)
Initialize the scheduler and set the number of threads to use.
Definition: harris_2d.h:134
PointCloudIn::ConstPtr PointCloudInConstPtr
Definition: harris_2d.h:63
HarrisKeypoint2D detects Harris corners family points.
Definition: harris_2d.h:54
Keypoint< PointInT, PointOutT >::PointCloudIn PointCloudIn
Definition: harris_2d.h:60
void computeSecondMomentMatrix(std::size_t pos, float *coefficients) const
calculates the upper triangular part of unnormalized covariance matrix over intensities given by the ...
Definition: harris_2d.hpp:101
void responseNoble(PointCloudOut &output) const
Definition: harris_2d.hpp:329
Keypoint< PointInT, PointOutT >::KdTree KdTree
Definition: harris_2d.h:62