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