Point Cloud Library (PCL)  1.7.0
/tmp/buildd/pcl-1.7-1.7.0/keypoints/include/pcl/keypoints/agast_2d.h
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  *  Copyright (c) 2012-, Open Perception, Inc.
00007  *
00008  *  All rights reserved.
00009  *
00010  *  Redistribution and use in source and binary forms, with or without
00011  *  modification, are permitted provided that the following conditions
00012  *  are met:
00013  *
00014  *   * Redistributions of source code must retain the above copyright
00015  *     notice, this list of conditions and the following disclaimer.
00016  *   * Redistributions in binary form must reproduce the above
00017  *     copyright notice, this list of conditions and the following
00018  *     disclaimer in the documentation and/or other materials provided
00019  *     with the distribution.
00020  *   * Neither the name of Willow Garage, Inc. nor the names of its
00021  *     contributors may be used to endorse or promote products derived
00022  *     from this software without specific prior written permission.
00023  *
00024  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00025  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00026  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00027  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00028  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00029  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00030  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00031  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00032  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00033  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00034  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00035  *  POSSIBILITY OF SUCH DAMAGE.
00036  *
00037  */
00038 
00039 #ifndef PCL_KEYPOINTS_AGAST_KEYPOINT_2D_H_
00040 #define PCL_KEYPOINTS_AGAST_KEYPOINT_2D_H_
00041 
00042 #include <pcl/point_cloud.h>
00043 #include <pcl/point_types.h>
00044 #include <pcl/keypoints/keypoint.h>
00045 #include <pcl/common/intensity.h>
00046 
00047 namespace pcl
00048 {
00049   namespace keypoints
00050   {
00051     namespace agast
00052     {
00053 
00054       /** \brief Abstract detector class for AGAST corner point detectors.
00055         *        
00056         * Adapted from the C++ implementation of Elmar Mair 
00057         * (http://www6.in.tum.de/Main/ResearchAgast).
00058         *
00059         * \author Stefan Holzer
00060         * \ingroup keypoints
00061         */
00062       class PCL_EXPORTS AbstractAgastDetector
00063       {
00064         public:
00065           typedef boost::shared_ptr<AbstractAgastDetector> Ptr;
00066           typedef boost::shared_ptr<const AbstractAgastDetector> ConstPtr;
00067 
00068           /** \brief Constructor. 
00069             * \param[in] width the width of the image to process
00070             * \param[in] height the height of the image to process
00071             * \param[in] threshold the corner detection threshold
00072             * \param[in] bmax the max image value (default: 255)
00073             */
00074           AbstractAgastDetector (const size_t width, 
00075                                  const size_t height, 
00076                                  const double threshold,
00077                                  const double bmax) 
00078             : width_ (width)
00079             , height_ (height)
00080             , threshold_ (threshold)
00081             , nr_max_keypoints_ (std::numeric_limits<unsigned int>::max ())
00082             , bmax_ (bmax)
00083           {}
00084 
00085           /** \brief Destructor. */
00086           virtual ~AbstractAgastDetector () {}
00087 
00088           /** \brief Detects corner points. 
00089             * \param intensity_data
00090             * \param output
00091             */
00092           void 
00093           detectKeypoints (const std::vector<unsigned char> &intensity_data, 
00094                            pcl::PointCloud<pcl::PointUV> &output);
00095 
00096           /** \brief Detects corner points. 
00097             * \param intensity_data
00098             * \param output
00099             */
00100           void 
00101           detectKeypoints (const std::vector<float> &intensity_data, 
00102                            pcl::PointCloud<pcl::PointUV> &output);
00103 
00104           /** \brief Applies non-max-suppression. 
00105             * \param[in] intensity_data the image data
00106             * \param[in] input the keypoint positions
00107             * \param[out] output the resultant keypoints after non-max-supression
00108             */
00109           void
00110           applyNonMaxSuppression (const std::vector<unsigned char>& intensity_data, 
00111                                   const pcl::PointCloud<pcl::PointUV> &input, 
00112                                   pcl::PointCloud<pcl::PointUV> &output);
00113 
00114           /** \brief Applies non-max-suppression. 
00115             * \param[in] intensity_data the image data
00116             * \param[in] input the keypoint positions
00117             * \param[out] output the resultant keypoints after non-max-supression
00118             */
00119           void
00120           applyNonMaxSuppression (const std::vector<float>& intensity_data, 
00121                                   const pcl::PointCloud<pcl::PointUV> &input, 
00122                                   pcl::PointCloud<pcl::PointUV> &output);
00123 
00124           /** \brief Computes corner score. 
00125             * \param[in] im the pixels to compute the score at
00126             */
00127           virtual int 
00128           computeCornerScore (const unsigned char* im) const = 0;
00129 
00130           /** \brief Computes corner score. 
00131             * \param[in] im the pixels to compute the score at
00132             * \param[in] bmax 
00133             */
00134           virtual int 
00135           computeCornerScore (const float* im) const = 0;
00136 
00137           /** \brief Sets the threshold for corner detection.
00138             * \param[in] threshold the threshold used for corner detection.
00139             */
00140           inline void
00141           setThreshold (const double threshold)
00142           {
00143             threshold_ = threshold;
00144           }
00145 
00146           /** \brief Get the threshold for corner detection, as set by the user. */
00147           inline double
00148           getThreshold ()
00149           {
00150             return (threshold_);
00151           }
00152 
00153           /** \brief Sets the maximum number of keypoints to return. The
00154             * estimated keypoints are sorted by their internal score.
00155             * \param[in] nr_max_keypoints set the maximum number of keypoints to return
00156             */
00157           inline void
00158           setMaxKeypoints (const unsigned int nr_max_keypoints)
00159           {
00160             nr_max_keypoints_ = nr_max_keypoints;
00161           }
00162 
00163           /** \brief Get the maximum nuber of keypoints to return, as set by the user. */
00164           inline unsigned int 
00165           getMaxKeypoints ()
00166           {
00167             return (nr_max_keypoints_);
00168           }
00169 
00170           /** \brief Detects points of interest (i.e., keypoints) in the given image
00171             * \param[in] im the image to detect keypoints in 
00172             * \param[out] corners_all the resultant set of keypoints detected
00173             */
00174           virtual void 
00175           detect (const unsigned char* im, 
00176                   std::vector<pcl::PointUV, Eigen::aligned_allocator<pcl::PointUV> > &corners_all) const = 0;
00177 
00178           /** \brief Detects points of interest (i.e., keypoints) in the given image
00179             * \param[in] im the image to detect keypoints in 
00180             * \param[out] corners_all the resultant set of keypoints detected
00181             */
00182           virtual void 
00183           detect (const float* im, 
00184                   std::vector<pcl::PointUV, Eigen::aligned_allocator<pcl::PointUV> > &) const = 0;
00185 
00186         protected:
00187 
00188           /** \brief Structure holding an index and the associated keypoint score. */
00189           struct ScoreIndex
00190           {
00191             int idx;
00192             int score;
00193           };
00194 
00195           /** \brief Score index comparator. */
00196           struct CompareScoreIndex
00197           {
00198             /** \brief Comparator
00199               * \param[i1] the first score index
00200               * \param[i2] the second score index
00201               */
00202             inline bool
00203             operator() (const ScoreIndex &i1, const ScoreIndex &i2)
00204             {
00205               return (i1.score > i2.score);
00206             }
00207           };
00208 
00209           /** \brief Initializes the sample pattern. */
00210           virtual void
00211           initPattern () = 0;
00212 
00213           /** \brief Non-max-suppression helper method.
00214             * \param[in] input the keypoint positions
00215             * \param[in] scores the keypoint scores computed on the image data
00216             * \param[out] output the resultant keypoints after non-max-supression
00217             */
00218           void
00219           applyNonMaxSuppression (const pcl::PointCloud<pcl::PointUV> &input, 
00220                                   const std::vector<ScoreIndex>& scores, 
00221                                   pcl::PointCloud<pcl::PointUV> &output);
00222 
00223           /** \brief Computes corner scores for the specified points. 
00224             * \param im
00225             * \param corners_all
00226             * \param scores
00227             */
00228           void 
00229           computeCornerScores (const unsigned char* im, 
00230                                const std::vector<pcl::PointUV, Eigen::aligned_allocator<pcl::PointUV> > & corners_all, 
00231                                std::vector<ScoreIndex> & scores);
00232 
00233           /** \brief Computes corner scores for the specified points. 
00234             * \param im
00235             * \param corners_all
00236             * \param scores
00237             */
00238           void 
00239           computeCornerScores (const float* im, 
00240                                const std::vector<pcl::PointUV, Eigen::aligned_allocator<pcl::PointUV> > & corners_all, 
00241                                std::vector<ScoreIndex> & scores);
00242 
00243           /** \brief Width of the image to process. */
00244           size_t width_;
00245           /** \brief Height of the image to process. */
00246           size_t height_;
00247 
00248           /** \brief Threshold for corner detection. */
00249           double threshold_;
00250 
00251           /** \brief The maximum number of keypoints to return. */
00252           unsigned int nr_max_keypoints_;
00253 
00254           /** \brief Max image value. */
00255           double bmax_;
00256       };
00257 
00258       /** \brief Detector class for AGAST corner point detector (7_12s). 
00259         *        
00260         * Adapted from the C++ implementation of Elmar Mair 
00261         * (http://www6.in.tum.de/Main/ResearchAgast).
00262         *
00263         * \author Stefan Holzer
00264         * \ingroup keypoints
00265         */
00266       class PCL_EXPORTS AgastDetector7_12s : public AbstractAgastDetector
00267       {
00268         public:
00269           typedef boost::shared_ptr<AgastDetector7_12s> Ptr;
00270           typedef boost::shared_ptr<const AgastDetector7_12s> ConstPtr;
00271 
00272           /** \brief Constructor. 
00273             * \param[in] width the width of the image to process
00274             * \param[in] height the height of the image to process
00275             * \param[in] threshold the corner detection threshold
00276             * \param[in] bmax the max image value (default: 255)
00277             */
00278           AgastDetector7_12s (const size_t width, 
00279                               const size_t height, 
00280                               const double threshold,
00281                               const double bmax = 255) 
00282             : AbstractAgastDetector (width, height, threshold, bmax)
00283           {
00284             initPattern ();
00285           }
00286 
00287           /** \brief Destructor. */
00288           ~AgastDetector7_12s () {}
00289 
00290           /** \brief Computes corner score. 
00291             * \param im 
00292             */
00293           int 
00294           computeCornerScore (const unsigned char* im) const;
00295 
00296           /** \brief Computes corner score. 
00297             * \param im 
00298             */
00299           int 
00300           computeCornerScore (const float* im) const;
00301 
00302           /** \brief Detects points of interest (i.e., keypoints) in the given image
00303             * \param[in] im the image to detect keypoints in 
00304             * \param[out] corners_all the resultant set of keypoints detected
00305             */
00306           void 
00307           detect (const unsigned char* im, std::vector<pcl::PointUV, Eigen::aligned_allocator<pcl::PointUV> > &corners_all) const;
00308 
00309           /** \brief Detects points of interest (i.e., keypoints) in the given image
00310             * \param[in] im the image to detect keypoints in 
00311             * \param[out] corners_all the resultant set of keypoints detected
00312             */
00313           void 
00314           detect (const float* im, std::vector<pcl::PointUV, Eigen::aligned_allocator<pcl::PointUV> > &corners_all) const;
00315 
00316         protected:
00317           /** \brief Initializes the sample pattern. */
00318           void 
00319           initPattern ();
00320 
00321         private:
00322           /** \brief Border width. */
00323           static const int border_width_ = 2;
00324 
00325           // offsets defining the sample pattern
00326           int_fast16_t s_offset0_;
00327           int_fast16_t s_offset1_;
00328           int_fast16_t s_offset2_;
00329           int_fast16_t s_offset3_;
00330           int_fast16_t s_offset4_;
00331           int_fast16_t s_offset5_;
00332           int_fast16_t s_offset6_;
00333           int_fast16_t s_offset7_;
00334           int_fast16_t s_offset8_;
00335           int_fast16_t s_offset9_;
00336           int_fast16_t s_offset10_;
00337           int_fast16_t s_offset11_;
00338       };
00339 
00340       /** \brief Detector class for AGAST corner point detector (5_8). 
00341         *        
00342         * Adapted from the C++ implementation of Elmar Mair 
00343         * (http://www6.in.tum.de/Main/ResearchAgast).
00344         *
00345         * \author Stefan Holzer
00346         * \ingroup keypoints
00347         */
00348       class PCL_EXPORTS AgastDetector5_8 : public AbstractAgastDetector
00349       {
00350         public:
00351           typedef boost::shared_ptr<AgastDetector5_8> Ptr;
00352           typedef boost::shared_ptr<const AgastDetector5_8> ConstPtr;
00353 
00354           /** \brief Constructor. 
00355             * \param[in] width the width of the image to process
00356             * \param[in] height the height of the image to process
00357             * \param[in] threshold the corner detection threshold
00358             * \param[in] bmax the max image value (default: 255)
00359             */
00360           AgastDetector5_8 (const size_t width, 
00361                             const size_t height, 
00362                             const double threshold,
00363                             const double bmax = 255) 
00364             : AbstractAgastDetector (width, height, threshold, bmax)
00365           {
00366             initPattern ();
00367           }
00368 
00369           /** \brief Destructor. */
00370           ~AgastDetector5_8 () {}
00371 
00372           /** \brief Computes corner score. 
00373             * \param im 
00374             */
00375           int 
00376           computeCornerScore (const unsigned char* im) const;
00377 
00378           /** \brief Computes corner score. 
00379             * \param im 
00380             */
00381           int 
00382           computeCornerScore (const float* im) const;
00383 
00384           /** \brief Detects points of interest (i.e., keypoints) in the given image
00385             * \param[in] im the image to detect keypoints in 
00386             * \param[out] corners_all the resultant set of keypoints detected
00387             */
00388           void 
00389           detect (const unsigned char* im, std::vector<pcl::PointUV, Eigen::aligned_allocator<pcl::PointUV> > &corners_all) const;
00390 
00391           /** \brief Detects points of interest (i.e., keypoints) in the given image
00392             * \param[in] im the image to detect keypoints in 
00393             * \param[out] corners_all the resultant set of keypoints detected
00394             */
00395           void 
00396           detect (const float* im, std::vector<pcl::PointUV, Eigen::aligned_allocator<pcl::PointUV> > &corners_all) const;
00397 
00398         protected:
00399           /** \brief Initializes the sample pattern. */
00400           void 
00401           initPattern ();
00402 
00403         private:
00404           /** \brief Border width. */
00405           static const int border_width_ = 1;
00406 
00407           // offsets defining the sample pattern
00408           int_fast16_t s_offset0_;
00409           int_fast16_t s_offset1_;
00410           int_fast16_t s_offset2_;
00411           int_fast16_t s_offset3_;
00412           int_fast16_t s_offset4_;
00413           int_fast16_t s_offset5_;
00414           int_fast16_t s_offset6_;
00415           int_fast16_t s_offset7_;
00416       };
00417 
00418       /** \brief Detector class for AGAST corner point detector (OAST 9_16). 
00419         *        
00420         * Adapted from the C++ implementation of Elmar Mair 
00421         * (http://www6.in.tum.de/Main/ResearchAgast).
00422         *
00423         * \author Stefan Holzer
00424         * \ingroup keypoints
00425         */
00426       class PCL_EXPORTS OastDetector9_16 : public AbstractAgastDetector
00427       {
00428         public:
00429           typedef boost::shared_ptr<OastDetector9_16> Ptr;
00430           typedef boost::shared_ptr<const OastDetector9_16> ConstPtr;
00431 
00432           /** \brief Constructor. 
00433             * \param[in] width the width of the image to process
00434             * \param[in] height the height of the image to process
00435             * \param[in] threshold the corner detection threshold
00436             * \param[in] bmax the max image value (default: 255)
00437             */
00438           OastDetector9_16 (const size_t width, 
00439                             const size_t height, 
00440                             const double threshold,
00441                             const double bmax = 255) 
00442             : AbstractAgastDetector (width, height, threshold, bmax)
00443           {
00444             initPattern ();
00445           }
00446 
00447           /** \brief Destructor. */
00448           ~OastDetector9_16 () {}
00449 
00450           /** \brief Computes corner score. 
00451             * \param im 
00452             */
00453           int 
00454           computeCornerScore (const unsigned char* im) const;
00455 
00456           /** \brief Computes corner score. 
00457             * \param im 
00458             */
00459           int 
00460           computeCornerScore (const float* im) const;
00461 
00462           /** \brief Detects points of interest (i.e., keypoints) in the given image
00463             * \param[in] im the image to detect keypoints in 
00464             * \param[out] corners_all the resultant set of keypoints detected
00465             */
00466           void 
00467           detect (const unsigned char* im, std::vector<pcl::PointUV, Eigen::aligned_allocator<pcl::PointUV> > &corners_all) const;
00468 
00469           /** \brief Detects points of interest (i.e., keypoints) in the given image
00470             * \param[in] im the image to detect keypoints in 
00471             * \param[out] corners_all the resultant set of keypoints detected
00472             */
00473           void 
00474           detect (const float* im, std::vector<pcl::PointUV, Eigen::aligned_allocator<pcl::PointUV> > &corners_all) const;
00475 
00476         protected:
00477           /** \brief Initializes the sample pattern. */
00478           void 
00479           initPattern ();
00480 
00481         private:
00482           /** \brief Border width. */
00483           static const int border_width_ = 3;
00484 
00485           // offsets defining the sample pattern
00486           int_fast16_t s_offset0_;
00487           int_fast16_t s_offset1_;
00488           int_fast16_t s_offset2_;
00489           int_fast16_t s_offset3_;
00490           int_fast16_t s_offset4_;
00491           int_fast16_t s_offset5_;
00492           int_fast16_t s_offset6_;
00493           int_fast16_t s_offset7_;
00494           int_fast16_t s_offset8_;
00495           int_fast16_t s_offset9_;
00496           int_fast16_t s_offset10_;
00497           int_fast16_t s_offset11_;
00498           int_fast16_t s_offset12_;
00499           int_fast16_t s_offset13_;
00500           int_fast16_t s_offset14_;
00501           int_fast16_t s_offset15_;
00502       };
00503     } // namespace agast
00504   } // namespace keypoints
00505 
00506   /////////////////////////////////////////////////////////////////////////////////////////
00507   /////////////////////////////////////////////////////////////////////////////////////////
00508   /////////////////////////////////////////////////////////////////////////////////////////
00509   namespace keypoints
00510   {
00511     namespace internal
00512     {
00513       /////////////////////////////////////////////////////////////////////////////////////
00514       template <typename Out> 
00515       struct AgastApplyNonMaxSuppresion
00516       {
00517         AgastApplyNonMaxSuppresion (
00518             const std::vector<unsigned char> &image_data, 
00519             const pcl::PointCloud<pcl::PointUV> &tmp_cloud,
00520             const pcl::keypoints::agast::AbstractAgastDetector::Ptr &detector,
00521             pcl::PointCloud<Out> &output)
00522         {
00523           pcl::PointCloud<pcl::PointUV> output_temp;
00524           detector->applyNonMaxSuppression (image_data, tmp_cloud, output_temp);
00525           pcl::copyPointCloud<pcl::PointUV, Out> (output_temp, output);
00526         }
00527       };
00528 
00529       /////////////////////////////////////////////////////////////////////////////////////
00530       template <>
00531       struct AgastApplyNonMaxSuppresion<pcl::PointUV>
00532       {
00533         AgastApplyNonMaxSuppresion (
00534             const std::vector<unsigned char> &image_data, 
00535             const pcl::PointCloud<pcl::PointUV> &tmp_cloud,
00536             const pcl::keypoints::agast::AbstractAgastDetector::Ptr &detector,
00537             pcl::PointCloud<pcl::PointUV> &output)
00538         {
00539           detector->applyNonMaxSuppression (image_data, tmp_cloud, output);
00540         }
00541       };
00542       /////////////////////////////////////////////////////////////////////////////////////
00543       template <typename Out> 
00544       struct AgastDetector
00545       {
00546         AgastDetector (
00547             const std::vector<unsigned char> &image_data, 
00548             const pcl::keypoints::agast::AbstractAgastDetector::Ptr &detector,
00549             pcl::PointCloud<Out> &output)
00550         {
00551           pcl::PointCloud<pcl::PointUV> output_temp;
00552           detector->detectKeypoints (image_data, output_temp);
00553           pcl::copyPointCloud<pcl::PointUV, Out> (output_temp, output);
00554         }
00555       };
00556 
00557       /////////////////////////////////////////////////////////////////////////////////////
00558       template <>
00559       struct AgastDetector<pcl::PointUV>
00560       {
00561         AgastDetector (
00562             const std::vector<unsigned char> &image_data, 
00563             const pcl::keypoints::agast::AbstractAgastDetector::Ptr &detector,
00564             pcl::PointCloud<pcl::PointUV> &output)
00565         {
00566           detector->detectKeypoints (image_data, output);
00567         }
00568       };
00569     } // namespace agast
00570   } // namespace keypoints
00571 
00572   /////////////////////////////////////////////////////////////////////////////////////////
00573   /////////////////////////////////////////////////////////////////////////////////////////
00574   /////////////////////////////////////////////////////////////////////////////////////////
00575   /** \brief Detects 2D AGAST corner points. Based on the original work and
00576     * paper reference by
00577     *
00578     * \par
00579     * Elmar Mair, Gregory D. Hager, Darius Burschka, Michael Suppa, and Gerhard Hirzinger. 
00580     * Adaptive and generic corner detection based on the accelerated segment test. 
00581     * In Proceedings of the European Conference on Computer Vision (ECCV'10), September 2010.
00582     *
00583     * \note This is an abstract base class. All children must implement a detectKeypoints method, based on the type of AGAST keypoint to be used.
00584     *
00585     * \author Stefan Holzer, Radu B. Rusu
00586     * \ingroup keypoints
00587     */
00588   template <typename PointInT, typename PointOutT, typename IntensityT = pcl::common::IntensityFieldAccessor<PointInT> >
00589   class AgastKeypoint2DBase : public Keypoint<PointInT, PointOutT>
00590   {
00591     public:
00592       typedef typename Keypoint<PointInT, PointOutT>::PointCloudIn PointCloudIn;
00593       typedef typename Keypoint<PointInT, PointOutT>::PointCloudOut PointCloudOut;
00594       typedef typename Keypoint<PointInT, PointOutT>::KdTree KdTree;
00595       typedef typename PointCloudIn::ConstPtr PointCloudInConstPtr;
00596 
00597       typedef pcl::keypoints::agast::AbstractAgastDetector::Ptr AgastDetectorPtr;
00598      
00599       using Keypoint<PointInT, PointOutT>::name_;
00600       using Keypoint<PointInT, PointOutT>::input_;
00601       using Keypoint<PointInT, PointOutT>::indices_;
00602       using Keypoint<PointInT, PointOutT>::k_;
00603 
00604       /** \brief Constructor */
00605       AgastKeypoint2DBase ()
00606         : threshold_ (10)
00607         , apply_non_max_suppression_ (true)
00608         , bmax_ (255)
00609         , detector_ ()
00610         , nr_max_keypoints_ (std::numeric_limits<unsigned int>::max ())
00611       {
00612         k_ = 1;
00613       }
00614 
00615       /** \brief Destructor. */
00616       virtual ~AgastKeypoint2DBase ()
00617       {
00618       }
00619 
00620       /** \brief Sets the threshold for corner detection.
00621         * \param[in] threshold the threshold used for corner detection.
00622         */
00623       inline void
00624       setThreshold (const double threshold)
00625       {
00626         threshold_ = threshold;
00627       }
00628 
00629       /** \brief Get the threshold for corner detection, as set by the user. */
00630       inline double
00631       getThreshold ()
00632       {
00633         return (threshold_);
00634       }
00635 
00636       /** \brief Sets the maximum number of keypoints to return. The
00637         * estimated keypoints are sorted by their internal score.
00638         * \param[in] nr_max_keypoints set the maximum number of keypoints to return
00639         */
00640       inline void
00641       setMaxKeypoints (const unsigned int nr_max_keypoints)
00642       {
00643         nr_max_keypoints_ = nr_max_keypoints;
00644       }
00645 
00646       /** \brief Get the maximum nuber of keypoints to return, as set by the user. */
00647       inline unsigned int 
00648       getMaxKeypoints ()
00649       {
00650         return (nr_max_keypoints_);
00651       }
00652 
00653       /** \brief Sets the max image data value (affects how many iterations AGAST does)
00654         * \param[in] bmax the max image data value
00655         */
00656       inline void
00657       setMaxDataValue (const double bmax)
00658       {
00659         bmax_ = bmax;
00660       }
00661 
00662       /** \brief Get the bmax image value, as set by the user. */
00663       inline double
00664       getMaxDataValue ()
00665       {
00666         return (bmax_);
00667       }
00668 
00669       /** \brief Sets whether non-max-suppression is applied or not.
00670         * \param[in] enabled determines whether non-max-suppression is enabled.
00671         */
00672       inline void
00673       setNonMaxSuppression (const bool enabled)
00674       {
00675         apply_non_max_suppression_ = enabled;
00676       }
00677 
00678       /** \brief Returns whether non-max-suppression is applied or not. */
00679       inline bool
00680       getNonMaxSuppression ()
00681       {
00682         return (apply_non_max_suppression_);
00683       }
00684 
00685       inline void
00686       setAgastDetector (const AgastDetectorPtr &detector)
00687       {
00688         detector_ = detector;
00689       }
00690 
00691       inline AgastDetectorPtr
00692       getAgastDetector ()
00693       {
00694         return (detector_);
00695       }
00696     protected:
00697 
00698       /** \brief Initializes everything and checks whether input data is fine. */
00699       bool 
00700       initCompute ();
00701       
00702       /** \brief Detects the keypoints.
00703         * \param[out] output the resultant keypoints
00704         */
00705       virtual void 
00706       detectKeypoints (PointCloudOut &output) = 0;
00707 
00708       /** \brief Intensity field accessor. */
00709       IntensityT intensity_;
00710       
00711       /** \brief Threshold for corner detection. */
00712       double threshold_;
00713 
00714       /** \brief Determines whether non-max-suppression is activated. */
00715       bool apply_non_max_suppression_;
00716 
00717       /** \brief Max image value. */
00718       double bmax_;
00719 
00720       /** \brief The Agast detector to use. */
00721       AgastDetectorPtr detector_;
00722 
00723       /** \brief The maximum number of keypoints to return. */
00724       unsigned int nr_max_keypoints_;
00725   };
00726 
00727   /** \brief Detects 2D AGAST corner points. Based on the original work and
00728     * paper reference by
00729     *
00730     * \par
00731     * Elmar Mair, Gregory D. Hager, Darius Burschka, Michael Suppa, and Gerhard Hirzinger. 
00732     * Adaptive and generic corner detection based on the accelerated segment test. 
00733     * In Proceedings of the European Conference on Computer Vision (ECCV'10), September 2010.
00734     *
00735     * Code example:
00736     *
00737     * \code
00738     * pcl::PointCloud<pcl::PointXYZRGBA> cloud;
00739     * pcl::AgastKeypoint2D<pcl::PointXYZRGBA> agast;
00740     * agast.setThreshold (30);
00741     * agast.setInputCloud (cloud);
00742     *
00743     * PointCloud<pcl::PointUV> keypoints;
00744     * agast.compute (keypoints);
00745     * \endcode
00746     *
00747     * \note The AGAST keypoint type used is 7_12s.
00748     *
00749     * \author Stefan Holzer, Radu B. Rusu
00750     * \ingroup keypoints
00751     */
00752   template <typename PointInT, typename PointOutT = pcl::PointUV>
00753   class AgastKeypoint2D : public AgastKeypoint2DBase<PointInT, PointOutT, pcl::common::IntensityFieldAccessor<PointInT> >
00754   {
00755     public:
00756       typedef typename Keypoint<PointInT, PointOutT>::PointCloudOut PointCloudOut;
00757 
00758       using Keypoint<PointInT, PointOutT>::name_;
00759       using Keypoint<PointInT, PointOutT>::input_;
00760       using Keypoint<PointInT, PointOutT>::indices_;
00761       using Keypoint<PointInT, PointOutT>::k_;
00762       using AgastKeypoint2DBase<PointInT, PointOutT, pcl::common::IntensityFieldAccessor<PointInT> >::intensity_;
00763       using AgastKeypoint2DBase<PointInT, PointOutT, pcl::common::IntensityFieldAccessor<PointInT> >::threshold_;
00764       using AgastKeypoint2DBase<PointInT, PointOutT, pcl::common::IntensityFieldAccessor<PointInT> >::bmax_;
00765       using AgastKeypoint2DBase<PointInT, PointOutT, pcl::common::IntensityFieldAccessor<PointInT> >::apply_non_max_suppression_;
00766       using AgastKeypoint2DBase<PointInT, PointOutT, pcl::common::IntensityFieldAccessor<PointInT> >::detector_;
00767       using AgastKeypoint2DBase<PointInT, PointOutT, pcl::common::IntensityFieldAccessor<PointInT> >::nr_max_keypoints_;
00768 
00769       /** \brief Constructor */
00770       AgastKeypoint2D ()
00771       {
00772         name_ = "AgastKeypoint2D";
00773       }
00774 
00775       /** \brief Destructor. */
00776       virtual ~AgastKeypoint2D ()
00777       {
00778       }
00779 
00780     protected:
00781       /** \brief Detects the keypoints.
00782         * \param[out] output the resultant keypoints
00783         */
00784       virtual void 
00785       detectKeypoints (PointCloudOut &output);
00786   };
00787 
00788   /** \brief Detects 2D AGAST corner points. Based on the original work and
00789     * paper reference by
00790     *
00791     * \par
00792     * Elmar Mair, Gregory D. Hager, Darius Burschka, Michael Suppa, and Gerhard Hirzinger. 
00793     * Adaptive and generic corner detection based on the accelerated segment test. 
00794     * In Proceedings of the European Conference on Computer Vision (ECCV'10), September 2010.
00795     *
00796     * Code example:
00797     *
00798     * \code
00799     * pcl::PointCloud<pcl::PointXYZRGBA> cloud;
00800     * pcl::AgastKeypoint2D<pcl::PointXYZRGBA> agast;
00801     * agast.setThreshold (30);
00802     * agast.setInputCloud (cloud);
00803     *
00804     * PointCloud<pcl::PointUV> keypoints;
00805     * agast.compute (keypoints);
00806     * \endcode
00807     *
00808     * \note This is a specialized version for PointXYZ clouds, and operates on depth (z) as float. The output keypoints are of the PointXY type.
00809     * \note The AGAST keypoint type used is 7_12s.
00810     *
00811     * \author Stefan Holzer, Radu B. Rusu
00812     * \ingroup keypoints
00813     */
00814   template <>
00815   class AgastKeypoint2D<pcl::PointXYZ, pcl::PointUV>
00816     : public AgastKeypoint2DBase<pcl::PointXYZ, pcl::PointUV, pcl::common::IntensityFieldAccessor<pcl::PointXYZ> > 
00817   {
00818     public:
00819       /** \brief Constructor */
00820       AgastKeypoint2D ()
00821       {
00822         name_ = "AgastKeypoint2D";
00823         bmax_ = 4;    // max data value for an OpenNI camera
00824       }
00825 
00826       /** \brief Destructor. */
00827       virtual ~AgastKeypoint2D ()
00828       {
00829       }
00830 
00831     protected:
00832       /** \brief Detects the keypoints.
00833         * \param[out] output the resultant keypoints
00834         */
00835       virtual void 
00836       detectKeypoints (pcl::PointCloud<pcl::PointUV> &output);
00837   };
00838 
00839 }
00840 
00841 #include <pcl/keypoints/impl/agast_2d.hpp>
00842 
00843 #endif
00844