Point Cloud Library (PCL)
1.7.0
|
00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Point Cloud Library (PCL) - www.pointclouds.org 00005 * Copyright (c) 2010-2011, Willow Garage, Inc. 00006 * 00007 * All rights reserved. 00008 * 00009 * Redistribution and use in source and binary forms, with or without 00010 * modification, are permitted provided that the following conditions 00011 * are met: 00012 * 00013 * * Redistributions of source code must retain the above copyright 00014 * notice, this list of conditions and the following disclaimer. 00015 * * Redistributions in binary form must reproduce the above 00016 * copyright notice, this list of conditions and the following 00017 * disclaimer in the documentation and/or other materials provided 00018 * with the distribution. 00019 * * Neither the name of Willow Garage, Inc. nor the names of its 00020 * contributors may be used to endorse or promote products derived 00021 * from this software without specific prior written permission. 00022 * 00023 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00024 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00025 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00026 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00027 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00028 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00029 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00030 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00031 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00032 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00033 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00034 * POSSIBILITY OF SUCH DAMAGE. 00035 * 00036 * $Id$ 00037 * 00038 */ 00039 00040 #ifndef PCL_HARRIS_KEYPOINT_2D_H_ 00041 #define PCL_HARRIS_KEYPOINT_2D_H_ 00042 00043 #include <pcl/keypoints/keypoint.h> 00044 #include <pcl/common/intensity.h> 00045 00046 namespace pcl 00047 { 00048 /** \brief HarrisKeypoint2D detects Harris corners family points 00049 * 00050 * \author Nizar Sallem 00051 * \ingroup keypoints 00052 */ 00053 template <typename PointInT, typename PointOutT, typename IntensityT = pcl::common::IntensityFieldAccessor<PointInT> > 00054 class HarrisKeypoint2D : public Keypoint<PointInT, PointOutT> 00055 { 00056 public: 00057 typedef boost::shared_ptr<HarrisKeypoint2D<PointInT, PointOutT, IntensityT> > Ptr; 00058 typedef boost::shared_ptr<const HarrisKeypoint2D<PointInT, PointOutT, IntensityT> > ConstPtr; 00059 00060 typedef typename Keypoint<PointInT, PointOutT>::PointCloudIn PointCloudIn; 00061 typedef typename Keypoint<PointInT, PointOutT>::PointCloudOut PointCloudOut; 00062 typedef typename Keypoint<PointInT, PointOutT>::KdTree KdTree; 00063 typedef typename PointCloudIn::ConstPtr PointCloudInConstPtr; 00064 00065 using Keypoint<PointInT, PointOutT>::name_; 00066 using Keypoint<PointInT, PointOutT>::input_; 00067 using Keypoint<PointInT, PointOutT>::indices_; 00068 00069 typedef enum {HARRIS = 1, NOBLE, LOWE, TOMASI} ResponseMethod; 00070 00071 /** \brief Constructor 00072 * \param[in] method the method to be used to determine the corner responses 00073 * \param[in] threshold the threshold to filter out weak corners 00074 */ 00075 HarrisKeypoint2D (ResponseMethod method = HARRIS, int window_width = 3, int window_height = 3, int min_distance = 5, float threshold = 0.0) 00076 : threshold_ (threshold) 00077 , refine_ (false) 00078 , nonmax_ (true) 00079 , method_ (method) 00080 , threads_ (0) 00081 , response_ (new pcl::PointCloud<PointOutT> ()) 00082 , window_width_ (window_width) 00083 , window_height_ (window_height) 00084 , skipped_pixels_ (0) 00085 , min_distance_ (min_distance) 00086 { 00087 name_ = "HarrisKeypoint2D"; 00088 } 00089 00090 /** \brief set the method of the response to be calculated. 00091 * \param[in] type 00092 */ 00093 void setMethod (ResponseMethod type); 00094 00095 ///Set window width 00096 void setWindowWidth (int window_width); 00097 00098 ///Set window height 00099 void setWindowHeight (int window_height); 00100 00101 ///Set number of pixels to skip 00102 void setSkippedPixels (int skipped_pixels); 00103 00104 ///Set minimal distance between candidate keypoints 00105 void setMinimalDistance (int min_distance); 00106 00107 /** \brief set the threshold value for detecting corners. This is only evaluated if non maxima suppression is turned on. 00108 * \brief note non maxima suppression needs to be activated in order to use this feature. 00109 * \param[in] threshold 00110 */ 00111 void setThreshold (float threshold); 00112 00113 /** \brief whether non maxima suppression should be applied or the response for each point should be returned 00114 * \note this value needs to be turned on in order to apply thresholding and refinement 00115 * \param[in] nonmax default is false 00116 */ 00117 void setNonMaxSupression (bool = false); 00118 00119 /** \brief whether the detected key points should be refined or not. If turned of, the key points are a subset of 00120 * the original point cloud. Otherwise the key points may be arbitrary. 00121 * \brief note non maxima supression needs to be on in order to use this feature. 00122 * \param[in] do_refine 00123 */ 00124 void setRefine (bool do_refine); 00125 00126 /** \brief Initialize the scheduler and set the number of threads to use. 00127 * \param nr_threads the number of hardware threads to use (0 sets the value back to automatic) 00128 */ 00129 inline void 00130 setNumberOfThreads (unsigned int nr_threads = 0) { threads_ = nr_threads; } 00131 00132 protected: 00133 bool 00134 initCompute (); 00135 void 00136 detectKeypoints (PointCloudOut &output); 00137 /** \brief gets the corner response for valid input points*/ 00138 void 00139 responseHarris (PointCloudOut &output, float& highest_response) const; 00140 void 00141 responseNoble (PointCloudOut &output, float& highest_response) const; 00142 void 00143 responseLowe (PointCloudOut &output, float& highest_response) const; 00144 void 00145 responseTomasi (PointCloudOut &output, float& highest_response) const; 00146 // void refineCorners (PointCloudOut &corners) const; 00147 /** \brief calculates the upper triangular part of unnormalized 00148 * covariance matrix over intensities given by the 2D coordinates 00149 * and window_width_ and window_height_ 00150 */ 00151 void 00152 computeSecondMomentMatrix (std::size_t pos, float* coefficients) const; 00153 /// threshold for non maxima suppression 00154 float threshold_; 00155 /// corner refinement 00156 bool refine_; 00157 /// non maximas suppression 00158 bool nonmax_; 00159 /// cornerness computation methode 00160 ResponseMethod method_; 00161 /// number of threads to be used 00162 unsigned int threads_; 00163 00164 private: 00165 Eigen::MatrixXf derivatives_rows_; 00166 Eigen::MatrixXf derivatives_cols_; 00167 /// intermediate holder for computed responses 00168 boost::shared_ptr<pcl::PointCloud<PointOutT> > response_; 00169 /// comparator for responses intensity 00170 bool 00171 greaterIntensityAtIndices (int a, int b) const 00172 { 00173 return (response_->at (a).intensity > response_->at (b).intensity); 00174 } 00175 /// Window width 00176 int window_width_; 00177 /// Window height 00178 int window_height_; 00179 /// half window width 00180 int half_window_width_; 00181 /// half window height 00182 int half_window_height_; 00183 /// number of pixels to skip within search window 00184 int skipped_pixels_; 00185 /// minimum distance between two keypoints 00186 int min_distance_; 00187 /// intensity field accessor 00188 IntensityT intensity_; 00189 }; 00190 } 00191 00192 #include <pcl/keypoints/impl/harris_2d.hpp> 00193 00194 #endif // #ifndef PCL_HARRIS_KEYPOINT_2D_H_