Point Cloud Library (PCL)  1.8.1
person_classifier.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  * person_classifier.h
37  * Created on: Nov 30, 2012
38  * Author: Matteo Munaro
39  */
40 
41 #ifndef PCL_PEOPLE_PERSON_CLASSIFIER_H_
42 #define PCL_PEOPLE_PERSON_CLASSIFIER_H_
43 
44 #include <pcl/people/person_cluster.h>
45 #include <pcl/people/hog.h>
46 
47 namespace pcl
48 {
49  namespace people
50  {
51  template <typename PointT> class PersonClassifier;
52 
53  template <typename PointT>
54  class PersonClassifier
55  {
56  protected:
57 
58  /** \brief Height of the image patch to classify. */
60 
61  /** \brief Width of the image patch to classify. */
63 
64  /** \brief SVM offset. */
65  float SVM_offset_;
66 
67  /** \brief SVM weights vector. */
68  std::vector<float> SVM_weights_;
69 
70  public:
71 
73  typedef boost::shared_ptr<PointCloud> PointCloudPtr;
74 
75  /** \brief Constructor. */
77 
78  /** \brief Destructor. */
79  virtual ~PersonClassifier ();
80 
81  /** \brief Load SVM parameters from a text file.
82  *
83  * \param[in] svm_filename Filename containing SVM parameters.
84  *
85  * \return true if SVM has been correctly set, false otherwise.
86  */
87  bool
88  loadSVMFromFile (std::string svm_filename);
89 
90  /**
91  * \brief Set trained SVM for person confidence estimation.
92  *
93  * \param[in] window_height Detection window height.
94  * \param[in] window_width Detection window width.
95  * \param[in] SVM_weights SVM weights vector.
96  * \param[in] SVM_offset SVM offset.
97  */
98  void
99  setSVM (int window_height, int window_width, std::vector<float> SVM_weights, float SVM_offset);
100 
101  /**
102  * \brief Get trained SVM for person confidence estimation.
103  *
104  * \param[out] window_height Detection window height.
105  * \param[out] window_width Detection window width.
106  * \param[out] SVM_weights SVM weights vector.
107  * \param[out] SVM_offset SVM offset.
108  */
109  void
110  getSVM (int& window_height, int& window_width, std::vector<float>& SVM_weights, float& SVM_offset);
111 
112  /**
113  * \brief Resize an image represented by a pointcloud containing RGB information.
114  *
115  * \param[in] input_image A pointer to a pointcloud containing RGB information.
116  * \param[out] output_image A pointer to the output pointcloud.
117  * \param[in] width Output width.
118  * \param[in] height Output height.
119  */
120  void
121  resize (PointCloudPtr& input_image, PointCloudPtr& output_image,
122  int width, int height);
123 
124  /**
125  * \brief Copies an image and makes a black border around it, where the source image is not present.
126  *
127  * \param[in] input_image A pointer to a pointcloud containing RGB information.
128  * \param[out] output_image A pointer to the output pointcloud.
129  * \param[in] xmin x coordinate of the top-left point of the bbox to copy from the input image.
130  * \param[in] ymin y coordinate of the top-left point of the bbox to copy from the input image.
131  * \param[in] width Output width.
132  * \param[in] height Output height.
133  */
134  void
135  copyMakeBorder (PointCloudPtr& input_image, PointCloudPtr& output_image,
136  int xmin, int ymin, int width, int height);
137 
138  /**
139  * \brief Classify the given portion of image.
140  *
141  * \param[in] height The height of the image patch to classify, in pixels.
142  * \param[in] xc The x-coordinate of the center of the image patch to classify, in pixels.
143  * \param[in] yc The y-coordinate of the center of the image patch to classify, in pixels.
144  * \param[in] image The whole image (pointer to a point cloud containing RGB information) containing the object to classify.
145  * \return The classification score given by the SVM.
146  */
147  double
148  evaluate (float height, float xc, float yc, PointCloudPtr& image);
149 
150  /**
151  * \brief Compute person confidence for a given PersonCluster.
152  *
153  * \param[in] image The input image (pointer to a point cloud containing RGB information).
154  * \param[in] bottom Theoretical bottom point of the cluster projected to the image.
155  * \param[in] top Theoretical top point of the cluster projected to the image.
156  * \param[in] centroid Theoretical centroid point of the cluster projected to the image.
157  * \param[in] vertical If true, the sensor is considered to be vertically placed (portrait mode).
158  * \return The person confidence.
159  */
160  double
161  evaluate (PointCloudPtr& image, Eigen::Vector3f& bottom, Eigen::Vector3f& top, Eigen::Vector3f& centroid,
162  bool vertical);
163  };
164  } /* namespace people */
165 } /* namespace pcl */
166 #include <pcl/people/impl/person_classifier.hpp>
167 #endif /* PCL_PEOPLE_PERSON_CLASSIFIER_H_ */
boost::shared_ptr< PointCloud > PointCloudPtr
int window_width_
Width of the image patch to classify.
virtual ~PersonClassifier()
Destructor.
double evaluate(float height, float xc, float yc, PointCloudPtr &image)
Classify the given portion of image.
pcl::PointCloud< PointT > PointCloud
std::vector< float > SVM_weights_
SVM weights vector.
void setSVM(int window_height, int window_width, std::vector< float > SVM_weights, float SVM_offset)
Set trained SVM for person confidence estimation.
void getSVM(int &window_height, int &window_width, std::vector< float > &SVM_weights, float &SVM_offset)
Get trained SVM for person confidence estimation.
void copyMakeBorder(PointCloudPtr &input_image, PointCloudPtr &output_image, int xmin, int ymin, int width, int height)
Copies an image and makes a black border around it, where the source image is not present.
PointCloud represents the base class in PCL for storing collections of 3D points.
void resize(PointCloudPtr &input_image, PointCloudPtr &output_image, int width, int height)
Resize an image represented by a pointcloud containing RGB information.
bool loadSVMFromFile(std::string svm_filename)
Load SVM parameters from a text file.
int window_height_
Height of the image patch to classify.