Point Cloud Library (PCL) 1.13.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#pragma once
41
42#include <pcl/keypoints/keypoint.h>
43#include <pcl/common/intensity.h>
44
45namespace 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:
56 using Ptr = shared_ptr<HarrisKeypoint2D<PointInT, PointOutT, IntensityT> >;
57 using ConstPtr = shared_ptr<const HarrisKeypoint2D<PointInT, PointOutT, IntensityT> >;
58
62 using PointCloudInConstPtr = typename PointCloudIn::ConstPtr;
63
64 using Keypoint<PointInT, PointOutT>::name_;
65 using Keypoint<PointInT, PointOutT>::input_;
66 using Keypoint<PointInT, PointOutT>::indices_;
67 using Keypoint<PointInT, PointOutT>::keypoints_indices_;
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
158 /// corner refinement
160 /// non maximas suppression
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>
HarrisKeypoint2D detects Harris corners family points.
Definition: harris_2d.h:54
unsigned int threads_
number of threads to be used
Definition: harris_2d.h:165
void setNumberOfThreads(unsigned int nr_threads=0)
Initialize the scheduler and set the number of threads to use.
Definition: harris_2d.h:133
ResponseMethod method_
cornerness computation method
Definition: harris_2d.h:163
void setNonMaxSupression(bool=false)
whether non maxima suppression should be applied or the response for each point should be returned
Definition: harris_2d.hpp:71
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
typename Keypoint< PointInT, PointOutT >::KdTree KdTree
Definition: harris_2d.h:61
void setSkippedPixels(int skipped_pixels)
Set number of pixels to skip.
Definition: harris_2d.hpp:92
void responseTomasi(PointCloudOut &output) const
Definition: harris_2d.hpp:443
void responseLowe(PointCloudOut &output) const
Definition: harris_2d.hpp:397
void setRefine(bool do_refine)
whether the detected key points should be refined or not.
Definition: harris_2d.hpp:64
void detectKeypoints(PointCloudOut &output) override
Definition: harris_2d.hpp:178
void responseNoble(PointCloudOut &output) const
Definition: harris_2d.hpp:351
void setMinimalDistance(int min_distance)
Set minimal distance between candidate keypoints.
Definition: harris_2d.hpp:99
void setMethod(ResponseMethod type)
set the method of the response to be calculated.
Definition: harris_2d.hpp:50
shared_ptr< HarrisKeypoint2D< PointInT, PointOutT, IntensityT > > Ptr
Definition: harris_2d.h:56
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:106
void setWindowHeight(int window_height)
Set window height.
Definition: harris_2d.hpp:85
shared_ptr< const HarrisKeypoint2D< PointInT, PointOutT, IntensityT > > ConstPtr
Definition: harris_2d.h:57
void responseHarris(PointCloudOut &output) const
gets the corner response for valid input points
Definition: harris_2d.hpp:305
bool nonmax_
non maximas suppression
Definition: harris_2d.h:161
float threshold_
threshold for non maxima suppression
Definition: harris_2d.h:157
typename Keypoint< PointInT, PointOutT >::PointCloudOut PointCloudOut
Definition: harris_2d.h:60
bool initCompute() override
Definition: harris_2d.hpp:132
void setThreshold(float threshold)
set the threshold value for detecting corners.
Definition: harris_2d.hpp:57
typename PointCloudIn::ConstPtr PointCloudInConstPtr
Definition: harris_2d.h:62
void setWindowWidth(int window_width)
Set window width.
Definition: harris_2d.hpp:78
typename Keypoint< PointInT, PointOutT >::PointCloudIn PointCloudIn
Definition: harris_2d.h:59
bool refine_
corner refinement
Definition: harris_2d.h:159
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
pcl::PointIndicesPtr keypoints_indices_
Indices of the keypoints in the input cloud.
Definition: keypoint.h:193
PointCloudConstPtr input_
The input point cloud dataset.
Definition: pcl_base.h:147
IndicesPtr indices_
A pointer to the vector of point indices to use.
Definition: pcl_base.h:150
const PointT & at(int column, int row) const
Obtain the point given by the (column, row) coordinates.
Definition: point_cloud.h:262
shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:413