Point Cloud Library (PCL)  1.7.1
ground_based_people_detection_app.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 the copyright holder(s) 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  * ground_based_people_detection_app.h
37  * Created on: Nov 30, 2012
38  * Author: Matteo Munaro
39  */
40 
41 #ifndef PCL_PEOPLE_GROUND_BASED_PEOPLE_DETECTION_APP_H_
42 #define PCL_PEOPLE_GROUND_BASED_PEOPLE_DETECTION_APP_H_
43 
44 #include <pcl/point_types.h>
45 #include <pcl/sample_consensus/sac_model_plane.h>
46 #include <pcl/sample_consensus/ransac.h>
47 #include <pcl/filters/extract_indices.h>
48 #include <pcl/segmentation/extract_clusters.h>
49 #include <pcl/kdtree/kdtree.h>
50 #include <pcl/filters/voxel_grid.h>
51 #include <pcl/people/person_cluster.h>
52 #include <pcl/people/head_based_subcluster.h>
53 #include <pcl/people/person_classifier.h>
54 
55 namespace pcl
56 {
57  namespace people
58  {
59  /** \brief GroundBasedPeopleDetectionApp performs people detection on RGB-D data having as input the ground plane coefficients.
60  * It implements the people detection algorithm described here:
61  * M. Munaro, F. Basso and E. Menegatti,
62  * Tracking people within groups with RGB-D data,
63  * In Proceedings of the International Conference on Intelligent Robots and Systems (IROS) 2012, Vilamoura (Portugal), 2012.
64  *
65  * \author Matteo Munaro
66  * \ingroup people
67  */
68  template <typename PointT> class GroundBasedPeopleDetectionApp;
69 
70  template <typename PointT>
72  {
73  public:
74 
76  typedef boost::shared_ptr<PointCloud> PointCloudPtr;
77  typedef boost::shared_ptr<const PointCloud> PointCloudConstPtr;
78 
79  /** \brief Constructor. */
81 
82  /** \brief Destructor. */
84 
85  /**
86  * \brief Set the pointer to the input cloud.
87  *
88  * \param[in] cloud A pointer to the input cloud.
89  */
90  void
91  setInputCloud (PointCloudPtr& cloud);
92 
93  /**
94  * \brief Set the ground coefficients.
95  *
96  * \param[in] ground_coeffs Vector containing the four plane coefficients.
97  */
98  void
99  setGround (Eigen::VectorXf& ground_coeffs);
100 
101  /**
102  * \brief Set sampling factor.
103  *
104  * \param[in] sampling_factor Value of the downsampling factor (in each dimension) which is applied to the raw point cloud (default = 1.).
105  */
106  void
107  setSamplingFactor (int sampling_factor);
108 
109  /**
110  * \brief Set voxel size.
111  *
112  * \param[in] voxel_size Value of the voxel dimension (default = 0.06m.).
113  */
114  void
115  setVoxelSize (float voxel_size);
116 
117  /**
118  * \brief Set intrinsic parameters of the RGB camera.
119  *
120  * \param[in] intrinsics_matrix RGB camera intrinsic parameters matrix.
121  */
122  void
123  setIntrinsics (Eigen::Matrix3f intrinsics_matrix);
124 
125  /**
126  * \brief Set SVM-based person classifier.
127  *
128  * \param[in] person_classifier Needed for people detection on RGB data.
129  */
130  void
132 
133  /**
134  * \brief Set sensor orientation (vertical = true means portrait mode, vertical = false means landscape mode).
135  *
136  * \param[in] vertical Set landscape/portait camera orientation (default = false).
137  */
138  void
139  setSensorPortraitOrientation (bool vertical);
140 
141  /**
142  * \brief Set head_centroid_ to true (person centroid is in the head) or false (person centroid is the whole body centroid).
143  *
144  * \param[in] head_centroid Set the location of the person centroid (head or body center) (default = true).
145  */
146  void
147  setHeadCentroid (bool head_centroid);
148 
149  /**
150  * \brief Set minimum and maximum allowed height for a person cluster.
151  *
152  * \param[in] min_height Minimum allowed height for a person cluster (default = 1.3).
153  * \param[in] max_height Maximum allowed height for a person cluster (default = 2.3).
154  */
155  void
156  setHeightLimits (float min_height, float max_height);
157 
158  /**
159  * \brief Set minimum and maximum allowed number of points for a person cluster.
160  *
161  * \param[in] min_points Minimum allowed number of points for a person cluster.
162  * \param[in] max_points Maximum allowed number of points for a person cluster.
163  */
164  void
165  setDimensionLimits (int min_points, int max_points);
166 
167  /**
168  * \brief Set minimum distance between persons' heads.
169  *
170  * \param[in] heads_minimum_distance Minimum allowed distance between persons' heads (default = 0.3).
171  */
172  void
173  setMinimumDistanceBetweenHeads (float heads_minimum_distance);
174 
175  /**
176  * \brief Get minimum and maximum allowed height for a person cluster.
177  *
178  * \param[out] min_height Minimum allowed height for a person cluster.
179  * \param[out] max_height Maximum allowed height for a person cluster.
180  */
181  void
182  getHeightLimits (float& min_height, float& max_height);
183 
184  /**
185  * \brief Get minimum and maximum allowed number of points for a person cluster.
186  *
187  * \param[out] min_points Minimum allowed number of points for a person cluster.
188  * \param[out] max_points Maximum allowed number of points for a person cluster.
189  */
190  void
191  getDimensionLimits (int& min_points, int& max_points);
192 
193  /**
194  * \brief Get minimum distance between persons' heads.
195  */
196  float
198 
199  /**
200  * \brief Get floor coefficients.
201  */
202  Eigen::VectorXf
203  getGround ();
204 
205  /**
206  * \brief Get pointcloud after voxel grid filtering and ground removal.
207  */
208  PointCloudPtr
209  getNoGroundCloud ();
210 
211  /**
212  * \brief Extract RGB information from a point cloud and output the corresponding RGB point cloud.
213  *
214  * \param[in] input_cloud A pointer to a point cloud containing also RGB information.
215  * \param[out] output_cloud A pointer to a RGB point cloud.
216  */
217  void
218  extractRGBFromPointCloud (PointCloudPtr input_cloud, pcl::PointCloud<pcl::RGB>::Ptr& output_cloud);
219 
220  /**
221  * \brief Swap rows/cols dimensions of a RGB point cloud (90 degrees counterclockwise rotation).
222  *
223  * \param[in,out] cloud A pointer to a RGB point cloud.
224  */
225  void
227 
228  /**
229  * \brief Perform people detection on the input data and return people clusters information.
230  *
231  * \param[out] clusters Vector of PersonCluster.
232  *
233  * \return true if the compute operation is successful, false otherwise.
234  */
235  bool
236  compute (std::vector<pcl::people::PersonCluster<PointT> >& clusters);
237 
238  protected:
239  /** \brief sampling factor used to downsample the point cloud */
241 
242  /** \brief voxel size */
243  float voxel_size_;
244 
245  /** \brief ground plane coefficients */
246  Eigen::VectorXf ground_coeffs_;
247 
248  /** \brief ground plane normalization factor */
250 
251  /** \brief pointer to the input cloud */
252  PointCloudPtr cloud_;
253 
254  /** \brief pointer to the cloud after voxel grid filtering and ground removal */
255  PointCloudPtr no_ground_cloud_;
256 
257  /** \brief pointer to a RGB cloud corresponding to cloud_ */
259 
260  /** \brief person clusters maximum height from the ground plane */
261  float max_height_;
262 
263  /** \brief person clusters minimum height from the ground plane */
264  float min_height_;
265 
266  /** \brief if true, the sensor is considered to be vertically placed (portrait mode) */
267  bool vertical_;
268 
269  /** \brief if true, the person centroid is computed as the centroid of the cluster points belonging to the head;
270  * if false, the person centroid is computed as the centroid of the whole cluster points (default = true) */
271  bool head_centroid_; // if true, the person centroid is computed as the centroid of the cluster points belonging to the head (default = true)
272  // if false, the person centroid is computed as the centroid of the whole cluster points
273  /** \brief maximum number of points for a person cluster */
275 
276  /** \brief minimum number of points for a person cluster */
278 
279  /** \brief true if min_points and max_points have been set by the user, false otherwise */
281 
282  /** \brief minimum distance between persons' heads */
284 
285  /** \brief intrinsic parameters matrix of the RGB camera */
286  Eigen::Matrix3f intrinsics_matrix_;
287 
288  /** \brief SVM-based person classifier */
290 
291  /** \brief flag stating if the classifier has been set or not */
293  };
294  } /* namespace people */
295 } /* namespace pcl */
296 #include <pcl/people/impl/ground_based_people_detection_app.hpp>
297 #endif /* PCL_PEOPLE_GROUND_BASED_PEOPLE_DETECTION_APP_H_ */
void setIntrinsics(Eigen::Matrix3f intrinsics_matrix)
Set intrinsic parameters of the RGB camera.
pcl::PointCloud< pcl::RGB >::Ptr rgb_image_
pointer to a RGB cloud corresponding to cloud_
Eigen::VectorXf ground_coeffs_
ground plane coefficients
float max_height_
person clusters maximum height from the ground plane
void setClassifier(pcl::people::PersonClassifier< pcl::RGB > person_classifier)
Set SVM-based person classifier.
pcl::people::PersonClassifier< pcl::RGB > person_classifier_
SVM-based person classifier.
void extractRGBFromPointCloud(PointCloudPtr input_cloud, pcl::PointCloud< pcl::RGB >::Ptr &output_cloud)
Extract RGB information from a point cloud and output the corresponding RGB point cloud...
float getMinimumDistanceBetweenHeads()
Get minimum distance between persons' heads.
bool head_centroid_
if true, the person centroid is computed as the centroid of the cluster points belonging to the head;...
void setDimensionLimits(int min_points, int max_points)
Set minimum and maximum allowed number of points for a person cluster.
void setMinimumDistanceBetweenHeads(float heads_minimum_distance)
Set minimum distance between persons' heads.
void setInputCloud(PointCloudPtr &cloud)
Set the pointer to the input cloud.
int max_points_
maximum number of points for a person cluster
void getHeightLimits(float &min_height, float &max_height)
Get minimum and maximum allowed height for a person cluster.
bool dimension_limits_set_
true if min_points and max_points have been set by the user, false otherwise
int sampling_factor_
sampling factor used to downsample the point cloud
Eigen::Matrix3f intrinsics_matrix_
intrinsic parameters matrix of the RGB camera
PointCloudPtr getNoGroundCloud()
Get pointcloud after voxel grid filtering and ground removal.
PersonCluster represents a class for representing information about a cluster containing a person...
boost::shared_ptr< const PointCloud > PointCloudConstPtr
bool person_classifier_set_flag_
flag stating if the classifier has been set or not
GroundBasedPeopleDetectionApp performs people detection on RGB-D data having as input the ground plan...
void setHeadCentroid(bool head_centroid)
Set head_centroid_ to true (person centroid is in the head) or false (person centroid is the whole bo...
void getDimensionLimits(int &min_points, int &max_points)
Get minimum and maximum allowed number of points for a person cluster.
void swapDimensions(pcl::PointCloud< pcl::RGB >::Ptr &cloud)
Swap rows/cols dimensions of a RGB point cloud (90 degrees counterclockwise rotation).
void setHeightLimits(float min_height, float max_height)
Set minimum and maximum allowed height for a person cluster.
PointCloudPtr no_ground_cloud_
pointer to the cloud after voxel grid filtering and ground removal
Eigen::VectorXf getGround()
Get floor coefficients.
bool compute(std::vector< pcl::people::PersonCluster< PointT > > &clusters)
Perform people detection on the input data and return people clusters information.
int min_points_
minimum number of points for a person cluster
boost::shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:428
void setSamplingFactor(int sampling_factor)
Set sampling factor.
bool vertical_
if true, the sensor is considered to be vertically placed (portrait mode)
void setGround(Eigen::VectorXf &ground_coeffs)
Set the ground coefficients.
void setSensorPortraitOrientation(bool vertical)
Set sensor orientation (vertical = true means portrait mode, vertical = false means landscape mode)...
PointCloud represents the base class in PCL for storing collections of 3D points. ...
float min_height_
person clusters minimum height from the ground plane
float heads_minimum_distance_
minimum distance between persons' heads
float sqrt_ground_coeffs_
ground plane normalization factor