Point Cloud Library (PCL)  1.7.2
trajkovic_2d.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2013-, Open Perception 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  */
37 
38 #ifndef PCL_TRAJKOVIC_KEYPOINT_2D_H_
39 #define PCL_TRAJKOVIC_KEYPOINT_2D_H_
40 
41 #include <pcl/keypoints/keypoint.h>
42 #include <pcl/common/intensity.h>
43 
44 namespace pcl
45 {
46  /** \brief TrajkovicKeypoint2D implements Trajkovic and Hedley corner detector on
47  * organized pooint cloud using intensity information.
48  * It uses first order statistics to find variation of intensities in horizontal
49  * or vertical directions.
50  *
51  * \author Nizar Sallem
52  * \ingroup keypoints
53  */
54  template <typename PointInT, typename PointOutT, typename IntensityT = pcl::common::IntensityFieldAccessor<PointInT> >
55  class TrajkovicKeypoint2D : public Keypoint<PointInT, PointOutT>
56  {
57  public:
58  typedef boost::shared_ptr<TrajkovicKeypoint2D<PointInT, PointOutT, IntensityT> > Ptr;
59  typedef boost::shared_ptr<const TrajkovicKeypoint2D<PointInT, PointOutT, IntensityT> > ConstPtr;
63 
68 
70 
71  /** \brief Constructor
72  * \param[in] method the method to be used to determine the corner responses
73  * \param[in] window_size
74  * \param[in] first_threshold the threshold used in the simple cornerness test.
75  * \param[in] second_threshold the threshold used to reject weak corners.
76  */
78  int window_size = 3,
79  float first_threshold = 0.1,
80  float second_threshold = 100.0)
81  : method_ (method)
82  , window_size_ (window_size)
83  , first_threshold_ (first_threshold)
84  , second_threshold_ (second_threshold)
85  , threads_ (1)
86  {
87  name_ = "TrajkovicKeypoint2D";
88  }
89 
90  /** \brief set the method of the response to be calculated.
91  * \param[in] method either 4 corners or 8 corners
92  */
93  inline void
94  setMethod (ComputationMethod method) { method_ = method; }
95 
96  /// \brief \return the computation method
97  inline ComputationMethod
98  getMethod () const { return (method_); }
99 
100  /// \brief Set window size
101  inline void
102  setWindowSize (int window_size) { window_size_= window_size; }
103 
104  /// \brief \return window size i.e. window width or height
105  inline int
106  getWindowSize () const { return (window_size_); }
107 
108  /** \brief set the first_threshold to reject corners in the simple cornerness
109  * computation stage.
110  * \param[in] threshold
111  */
112  inline void
113  setFirstThreshold (float threshold) { first_threshold_= threshold; }
114 
115  /// \brief \return first threshold
116  inline float
117  getFirstThreshold () const { return (first_threshold_); }
118 
119  /** \brief set the second threshold to reject corners in the final cornerness
120  * computation stage.
121  * \param[in] threshold
122  */
123  inline void
124  setSecondThreshold (float threshold) { second_threshold_= threshold; }
125 
126  /// \brief \return second threshold
127  inline float
128  getSecondThreshold () const { return (second_threshold_); }
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 for automatic.
132  */
133  inline void
134  setNumberOfThreads (unsigned int nr_threads = 0) { threads_ = nr_threads; }
135 
136  /// \brief \return the number of threads
137  inline unsigned int
138  getNumberOfThreads () const { return (threads_); }
139 
140  protected:
141  bool
142  initCompute ();
143 
144  void
145  detectKeypoints (PointCloudOut &output);
146 
147  private:
148  /// comparator for responses intensity
149  inline bool
150  greaterCornernessAtIndices (int a, int b) const
151  {
152  return (response_->points [a] > response_->points [b]);
153  }
154 
155  /// computation method
156  ComputationMethod method_;
157  /// Window size
158  int window_size_;
159  /// half window size
160  int half_window_size_;
161  /// intensity field accessor
162  IntensityT intensity_;
163  /// first threshold for quick rejection
164  float first_threshold_;
165  /// second threshold for corner evaluation
166  float second_threshold_;
167  /// number of threads to be used
168  unsigned int threads_;
169  /// point cloud response
170  pcl::PointCloud<float>::Ptr response_;
171  };
172 }
173 
174 #include <pcl/keypoints/impl/trajkovic_2d.hpp>
175 
176 #endif // #ifndef PCL_TRAJKOVIC_KEYPOINT_2D_H_
boost::shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:428
void setSecondThreshold(float threshold)
set the second threshold to reject corners in the final cornerness computation stage.
Definition: trajkovic_2d.h:124
void detectKeypoints(PointCloudOut &output)
Abstract key point detection method.
std::string name_
The key point detection method's name.
Definition: keypoint.h:173
void setMethod(ComputationMethod method)
set the method of the response to be calculated.
Definition: trajkovic_2d.h:94
ComputationMethod getMethod() const
Definition: trajkovic_2d.h:98
void setNumberOfThreads(unsigned int nr_threads=0)
Initialize the scheduler and set the number of threads to use.
Definition: trajkovic_2d.h:134
TrajkovicKeypoint2D implements Trajkovic and Hedley corner detector on organized pooint cloud using i...
Definition: trajkovic_2d.h:55
PointCloudIn::ConstPtr PointCloudInConstPtr
Definition: trajkovic_2d.h:62
std::vector< PointT, Eigen::aligned_allocator< PointT > > points
The point data.
Definition: point_cloud.h:410
boost::shared_ptr< TrajkovicKeypoint2D< PointInT, PointOutT, IntensityT > > Ptr
Definition: trajkovic_2d.h:58
boost::shared_ptr< const PointCloud< PointInT > > ConstPtr
Definition: point_cloud.h:429
Keypoint represents the base class for key points.
Definition: keypoint.h:55
float getSecondThreshold() const
Definition: trajkovic_2d.h:128
unsigned int getNumberOfThreads() const
Definition: trajkovic_2d.h:138
boost::shared_ptr< const TrajkovicKeypoint2D< PointInT, PointOutT, IntensityT > > ConstPtr
Definition: trajkovic_2d.h:59
TrajkovicKeypoint2D(ComputationMethod method=FOUR_CORNERS, int window_size=3, float first_threshold=0.1, float second_threshold=100.0)
Constructor.
Definition: trajkovic_2d.h:77
Keypoint< PointInT, PointOutT >::PointCloudOut PointCloudOut
Definition: trajkovic_2d.h:61
int getWindowSize() const
Definition: trajkovic_2d.h:106
Keypoint< PointInT, PointOutT >::PointCloudIn PointCloudIn
Definition: trajkovic_2d.h:60
void setWindowSize(int window_size)
Set window size.
Definition: trajkovic_2d.h:102
void setFirstThreshold(float threshold)
set the first_threshold to reject corners in the simple cornerness computation stage.
Definition: trajkovic_2d.h:113
float getFirstThreshold() const
Definition: trajkovic_2d.h:117