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