Point Cloud Library (PCL)  1.7.0
/tmp/buildd/pcl-1.7-1.7.0/people/include/pcl/people/ground_based_people_detection_app.h
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  * Point Cloud Library (PCL) - www.pointclouds.org
00005  * Copyright (c) 2013-, Open Perception, 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 the copyright holder(s) 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  * ground_based_people_detection_app.h
00037  * Created on: Nov 30, 2012
00038  * Author: Matteo Munaro
00039  */
00040 
00041 #ifndef PCL_PEOPLE_GROUND_BASED_PEOPLE_DETECTION_APP_H_
00042 #define PCL_PEOPLE_GROUND_BASED_PEOPLE_DETECTION_APP_H_
00043 
00044 #include <pcl/point_types.h>
00045 #include <pcl/sample_consensus/sac_model_plane.h>
00046 #include <pcl/sample_consensus/ransac.h>
00047 #include <pcl/filters/extract_indices.h>
00048 #include <pcl/segmentation/extract_clusters.h>
00049 #include <pcl/kdtree/kdtree.h>
00050 #include <pcl/filters/voxel_grid.h>
00051 #include <pcl/people/person_cluster.h>
00052 #include <pcl/people/head_based_subcluster.h>
00053 #include <pcl/people/person_classifier.h>
00054 
00055 namespace pcl
00056 {
00057   namespace people
00058   {
00059     /** \brief GroundBasedPeopleDetectionApp performs people detection on RGB-D data having as input the ground plane coefficients.
00060      * It implements the people detection algorithm described here:
00061      * M. Munaro, F. Basso and E. Menegatti,
00062      * Tracking people within groups with RGB-D data,
00063      * In Proceedings of the International Conference on Intelligent Robots and Systems (IROS) 2012, Vilamoura (Portugal), 2012.
00064      *
00065      * \author Matteo Munaro
00066      * \ingroup people
00067      */
00068     template <typename PointT> class GroundBasedPeopleDetectionApp;
00069 
00070     template <typename PointT>
00071     class GroundBasedPeopleDetectionApp
00072     {
00073     public:
00074 
00075       typedef pcl::PointCloud<PointT> PointCloud;
00076       typedef boost::shared_ptr<PointCloud> PointCloudPtr;
00077       typedef boost::shared_ptr<const PointCloud> PointCloudConstPtr;
00078 
00079       /** \brief Constructor. */
00080       GroundBasedPeopleDetectionApp ();
00081 
00082       /** \brief Destructor. */
00083       virtual ~GroundBasedPeopleDetectionApp ();
00084 
00085       /**
00086        * \brief Set the pointer to the input cloud.
00087        *
00088        * \param[in] cloud A pointer to the input cloud.
00089        */
00090       void
00091       setInputCloud (PointCloudPtr& cloud);
00092 
00093       /**
00094        * \brief Set the ground coefficients.
00095        *
00096        * \param[in] ground_coeffs Vector containing the four plane coefficients.
00097        */
00098       void
00099       setGround (Eigen::VectorXf& ground_coeffs);
00100 
00101       /**
00102        * \brief Set sampling factor. 
00103        *
00104        * \param[in] sampling_factor Value of the downsampling factor (in each dimension) which is applied to the raw point cloud (default = 1.).
00105        */
00106       void
00107       setSamplingFactor (int sampling_factor);
00108       
00109       /**
00110        * \brief Set voxel size. 
00111        *
00112        * \param[in] voxel_size Value of the voxel dimension (default = 0.06m.).
00113        */
00114       void
00115       setVoxelSize (float voxel_size);
00116 
00117       /**
00118        * \brief Set intrinsic parameters of the RGB camera.
00119        *
00120        * \param[in] intrinsics_matrix RGB camera intrinsic parameters matrix.
00121        */
00122       void
00123       setIntrinsics (Eigen::Matrix3f intrinsics_matrix);
00124 
00125       /**
00126        * \brief Set SVM-based person classifier.
00127        *
00128        * \param[in] person_classifier Needed for people detection on RGB data.
00129        */
00130       void
00131       setClassifier (pcl::people::PersonClassifier<pcl::RGB> person_classifier);
00132 
00133       /**
00134        * \brief Set sensor orientation (vertical = true means portrait mode, vertical = false means landscape mode).
00135        *
00136        * \param[in] vertical Set landscape/portait camera orientation (default = false).
00137        */
00138       void
00139       setSensorPortraitOrientation (bool vertical);
00140 
00141       /**
00142        * \brief Set head_centroid_ to true (person centroid is in the head) or false (person centroid is the whole body centroid).
00143        *
00144        * \param[in] head_centroid Set the location of the person centroid (head or body center) (default = true).
00145        */
00146       void
00147       setHeadCentroid (bool head_centroid);
00148 
00149       /**
00150        * \brief Set minimum and maximum allowed height for a person cluster.
00151        *
00152        * \param[in] min_height Minimum allowed height for a person cluster (default = 1.3).
00153        * \param[in] max_height Maximum allowed height for a person cluster (default = 2.3).
00154        */
00155       void
00156       setHeightLimits (float min_height, float max_height);
00157 
00158       /**
00159        * \brief Set minimum and maximum allowed number of points for a person cluster.
00160        *
00161        * \param[in] min_points Minimum allowed number of points for a person cluster.
00162        * \param[in] max_points Maximum allowed number of points for a person cluster.
00163        */
00164       void
00165       setDimensionLimits (int min_points, int max_points);
00166 
00167       /**
00168        * \brief Set minimum distance between persons' heads.
00169        *
00170        * \param[in] heads_minimum_distance Minimum allowed distance between persons' heads (default = 0.3).
00171        */
00172       void
00173       setMinimumDistanceBetweenHeads (float heads_minimum_distance);
00174 
00175       /**
00176        * \brief Get minimum and maximum allowed height for a person cluster.
00177        *
00178        * \param[out] min_height Minimum allowed height for a person cluster.
00179        * \param[out] max_height Maximum allowed height for a person cluster.
00180        */
00181       void
00182       getHeightLimits (float& min_height, float& max_height);
00183 
00184       /**
00185        * \brief Get minimum and maximum allowed number of points for a person cluster.
00186        *
00187        * \param[out] min_points Minimum allowed number of points for a person cluster.
00188        * \param[out] max_points Maximum allowed number of points for a person cluster.
00189        */
00190       void
00191       getDimensionLimits (int& min_points, int& max_points);
00192 
00193       /**
00194        * \brief Get minimum distance between persons' heads.
00195        */
00196       float
00197       getMinimumDistanceBetweenHeads ();
00198 
00199       /**
00200        * \brief Get floor coefficients.
00201        */
00202       Eigen::VectorXf
00203       getGround ();
00204 
00205       /**
00206        * \brief Get pointcloud after voxel grid filtering and ground removal.
00207        */
00208       PointCloudPtr
00209       getNoGroundCloud ();
00210 
00211       /**
00212        * \brief Extract RGB information from a point cloud and output the corresponding RGB point cloud.
00213        *
00214        * \param[in] input_cloud A pointer to a point cloud containing also RGB information.
00215        * \param[out] output_cloud A pointer to a RGB point cloud.
00216        */
00217       void
00218       extractRGBFromPointCloud (PointCloudPtr input_cloud, pcl::PointCloud<pcl::RGB>::Ptr& output_cloud);
00219 
00220       /**
00221        * \brief Swap rows/cols dimensions of a RGB point cloud (90 degrees counterclockwise rotation).
00222        *
00223        * \param[in,out] cloud A pointer to a RGB point cloud.
00224        */
00225       void
00226       swapDimensions (pcl::PointCloud<pcl::RGB>::Ptr& cloud);
00227 
00228       /**
00229        * \brief Perform people detection on the input data and return people clusters information.
00230        * 
00231        * \param[out] clusters Vector of PersonCluster.
00232        * 
00233        * \return true if the compute operation is succesful, false otherwise.
00234        */
00235       bool
00236       compute (std::vector<pcl::people::PersonCluster<PointT> >& clusters);
00237 
00238     protected:
00239       /** \brief sampling factor used to downsample the point cloud */
00240       int sampling_factor_; 
00241       
00242       /** \brief voxel size */
00243       float voxel_size_;                  
00244       
00245       /** \brief ground plane coefficients */
00246       Eigen::VectorXf ground_coeffs_;            
00247       
00248       /** \brief ground plane normalization factor */
00249       float sqrt_ground_coeffs_;              
00250       
00251       /** \brief pointer to the input cloud */
00252       PointCloudPtr cloud_;   
00253 
00254       /** \brief pointer to the cloud after voxel grid filtering and ground removal */
00255       PointCloudPtr no_ground_cloud_;              
00256       
00257       /** \brief pointer to a RGB cloud corresponding to cloud_ */
00258       pcl::PointCloud<pcl::RGB>::Ptr rgb_image_;      
00259       
00260       /** \brief person clusters maximum height from the ground plane */
00261       float max_height_;                  
00262       
00263       /** \brief person clusters minimum height from the ground plane */
00264       float min_height_;                  
00265       
00266       /** \brief if true, the sensor is considered to be vertically placed (portrait mode) */
00267       bool vertical_;                    
00268       
00269       /** \brief if true, the person centroid is computed as the centroid of the cluster points belonging to the head;  
00270        * if false, the person centroid is computed as the centroid of the whole cluster points (default = true) */
00271       bool head_centroid_;    // if true, the person centroid is computed as the centroid of the cluster points belonging to the head (default = true)
00272                               // if false, the person centroid is computed as the centroid of the whole cluster points 
00273       /** \brief maximum number of points for a person cluster */
00274       int max_points_;                  
00275       
00276       /** \brief minimum number of points for a person cluster */
00277       int min_points_;                  
00278       
00279       /** \brief true if min_points and max_points have been set by the user, false otherwise */
00280       bool dimension_limits_set_;              
00281       
00282       /** \brief minimum distance between persons' heads */
00283       float heads_minimum_distance_;            
00284       
00285       /** \brief intrinsic parameters matrix of the RGB camera */
00286       Eigen::Matrix3f intrinsics_matrix_;          
00287       
00288       /** \brief SVM-based person classifier */
00289       pcl::people::PersonClassifier<pcl::RGB> person_classifier_;  
00290       
00291       /** \brief flag stating if the classifier has been set or not */
00292       bool person_classifier_set_flag_;        
00293     };
00294   } /* namespace people */
00295 } /* namespace pcl */
00296 #include <pcl/people/impl/ground_based_people_detection_app.hpp>
00297 #endif /* PCL_PEOPLE_GROUND_BASED_PEOPLE_DETECTION_APP_H_ */