Point Cloud Library (PCL)  1.14.0-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  {
85  name_ = "TrajkovicKeypoint2D";
86  }
87 
88  /** \brief set the method of the response to be calculated.
89  * \param[in] method either 4 corners or 8 corners
90  */
91  inline void
92  setMethod (ComputationMethod method) { method_ = method; }
93 
94  /// \brief \return the computation method
95  inline ComputationMethod
96  getMethod () const { return (method_); }
97 
98  /// \brief Set window size
99  inline void
100  setWindowSize (int window_size) { window_size_= window_size; }
101 
102  /// \brief \return window size i.e. window width or height
103  inline int
104  getWindowSize () const { return (window_size_); }
105 
106  /** \brief set the first_threshold to reject corners in the simple cornerness
107  * computation stage.
108  * \param[in] threshold
109  */
110  inline void
111  setFirstThreshold (float threshold) { first_threshold_= threshold; }
112 
113  /// \brief \return first threshold
114  inline float
115  getFirstThreshold () const { return (first_threshold_); }
116 
117  /** \brief set the second threshold to reject corners in the final cornerness
118  * computation stage.
119  * \param[in] threshold
120  */
121  inline void
122  setSecondThreshold (float threshold) { second_threshold_= threshold; }
123 
124  /// \brief \return second threshold
125  inline float
126  getSecondThreshold () const { return (second_threshold_); }
127 
128  /** \brief Initialize the scheduler and set the number of threads to use.
129  * \param nr_threads the number of hardware threads to use, 0 for automatic.
130  */
131  inline void
132  setNumberOfThreads (unsigned int nr_threads = 0) { threads_ = nr_threads; }
133 
134  /// \brief \return the number of threads
135  inline unsigned int
136  getNumberOfThreads () const { return (threads_); }
137 
138  protected:
139  bool
140  initCompute () override;
141 
142  void
143  detectKeypoints (PointCloudOut &output) override;
144 
145  private:
146  /// comparator for responses intensity
147  inline bool
148  greaterCornernessAtIndices (int a, int b) const
149  {
150  return (response_->points [a] > response_->points [b]);
151  }
152 
153  /// computation method
154  ComputationMethod method_;
155  /// Window size
156  int window_size_;
157  /// half window size
158  int half_window_size_;
159  /// intensity field accessor
160  IntensityT intensity_;
161  /// first threshold for quick rejection
162  float first_threshold_;
163  /// second threshold for corner evaluation
164  float second_threshold_;
165  /// number of threads to be used
166  unsigned int threads_{1};
167  /// point cloud response
168  pcl::PointCloud<float>::Ptr response_;
169  };
170 }
171 
172 #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:167
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:136
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:122
void setNumberOfThreads(unsigned int nr_threads=0)
Initialize the scheduler and set the number of threads to use.
Definition: trajkovic_2d.h:132
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:96
void detectKeypoints(PointCloudOut &output) override
void setWindowSize(int window_size)
Set window size.
Definition: trajkovic_2d.h:100
float getSecondThreshold() const
Definition: trajkovic_2d.h:126
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:115
bool initCompute() override
void setMethod(ComputationMethod method)
set the method of the response to be calculated.
Definition: trajkovic_2d.h:92
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:111