Point Cloud Library (PCL)  1.8.0
rf_face_detector_trainer.h
1 /*
2  * rf_face_detector_trainer.h
3  *
4  * Created on: 22 Sep 2012
5  * Author: Aitor Aldoma
6  */
7 
8 #ifndef PCL_RF_FACE_DETECTOR_TRAINER_H_
9 #define PCL_RF_FACE_DETECTOR_TRAINER_H_
10 
11 #include "pcl/recognition/face_detection/face_detector_data_provider.h"
12 #include "pcl/recognition/face_detection/rf_face_utils.h"
13 #include "pcl/ml/dt/decision_forest.h"
14 #include <pcl/features/integral_image2D.h>
15 
16 namespace pcl
17 {
18  class PCL_EXPORTS RFFaceDetectorTrainer
19  {
20  private:
21  int w_size_;
22  int max_patch_size_;
23  int stride_sw_;
24  int ntrees_;
25  std::string forest_filename_;
26  int nfeatures_;
27  float thres_face_;
28  int num_images_;
29  float trans_max_variance_;
30  size_t min_votes_size_;
31  int used_for_pose_;
32  bool use_normals_;
33  std::string directory_;
34  float HEAD_ST_DIAMETER_;
35  float larger_radius_ratio_;
36  std::vector<Eigen::Vector3f, Eigen::aligned_allocator<Eigen::Vector3f> > head_center_votes_;
37  std::vector<std::vector<Eigen::Vector3f, Eigen::aligned_allocator<Eigen::Vector3f> > > head_center_votes_clustered_;
38  std::vector<std::vector<Eigen::Vector3f, Eigen::aligned_allocator<Eigen::Vector3f> > > head_center_original_votes_clustered_;
39  std::vector<Eigen::Vector3f, Eigen::aligned_allocator<Eigen::Vector3f> > angle_votes_;
40  std::vector<float> uncertainties_;
41  std::vector<Eigen::Vector3f, Eigen::aligned_allocator<Eigen::Vector3f> > head_clusters_centers_;
42  std::vector<Eigen::Vector3f, Eigen::aligned_allocator<Eigen::Vector3f> > head_clusters_rotation_;
43 
46 
49 
50  std::string model_path_;
51  bool pose_refinement_;
52  int icp_iterations_;
53 
55  float res_;
56 
57  public:
58 
60  {
61  w_size_ = 80;
62  max_patch_size_ = 40;
63  stride_sw_ = 4;
64  ntrees_ = 10;
65  forest_filename_ = std::string ("forest.txt");
66  nfeatures_ = 10000;
67  thres_face_ = 1.f;
68  num_images_ = 1000;
69  trans_max_variance_ = 1600.f;
70  used_for_pose_ = std::numeric_limits<int>::max ();
71  use_normals_ = false;
72  directory_ = std::string ("");
73  HEAD_ST_DIAMETER_ = 0.2364f;
74  larger_radius_ratio_ = 1.5f;
75  face_heat_map_.reset ();
76  model_path_ = std::string ("face_mesh.ply");
77  pose_refinement_ = false;
78  res_ = 0.005f;
79  }
80 
82  {
83 
84  }
85 
86  /*
87  * Common parameters
88  */
89  void setForestFilename(std::string & ff)
90  {
91  forest_filename_ = ff;
92  }
93 
94  void setUseNormals(bool use)
95  {
96  use_normals_ = use;
97  }
98 
99  void setWSize(int s)
100  {
101  w_size_ = s;
102  }
103 
104  /*
105  * Training parameters
106  */
107 
108  void setDirectory(std::string & dir)
109  {
110  directory_ = dir;
111  }
112  void setNumTrainingImages(int num)
113  {
114  num_images_ = num;
115  }
116 
117  void setNumTrees(int num)
118  {
119  ntrees_ = num;
120  }
121 
122  void setNumFeatures(int num)
123  {
124  nfeatures_ = num;
125  }
126 
127  /*
128  * Detection parameters
129  */
130 
131  void setModelPath(std::string & model);
132 
133  void setPoseRefinement(bool do_it, int iters = 5)
134  {
135  pose_refinement_ = do_it;
136  icp_iterations_ = iters;
137  }
138 
140  {
141  thres_face_ = p;
142  }
143 
144  void setLeavesFaceMaxVariance(float max)
145  {
146  trans_max_variance_ = max;
147  }
148 
149  void setWStride(int s)
150  {
151  stride_sw_ = s;
152  }
153 
154  void setFaceMinVotes(int mv)
155  {
156  min_votes_size_ = mv;
157  }
158 
160  {
161  used_for_pose_ = n;
162  }
163 
165  {
166  forest_ = forest;
167  }
168 
169  /*
170  * Get functions
171  */
172 
174  {
175  heat_map = face_heat_map_;
176  }
177 
178  //get votes
180  {
181  votes_cloud->points.resize (head_center_votes_.size ());
182  votes_cloud->width = static_cast<int>(head_center_votes_.size ());
183  votes_cloud->height = 1;
184 
185  for (size_t i = 0; i < head_center_votes_.size (); i++)
186  {
187  votes_cloud->points[i].getVector3fMap () = head_center_votes_[i];
188  }
189  }
190 
192  {
193  votes_cloud->points.resize (head_center_votes_.size ());
194  votes_cloud->width = static_cast<int>(head_center_votes_.size ());
195  votes_cloud->height = 1;
196 
197  int p = 0;
198  for (size_t i = 0; i < head_center_votes_clustered_.size (); i++)
199  {
200  for (size_t j = 0; j < head_center_votes_clustered_[i].size (); j++, p++)
201  {
202  votes_cloud->points[p].getVector3fMap () = head_center_votes_clustered_[i][j];
203  votes_cloud->points[p].intensity = 0.1f * static_cast<float> (i);
204  }
205  }
206 
207  votes_cloud->points.resize (p);
208  }
209 
211  {
212  votes_cloud->points.resize (head_center_votes_.size ());
213  votes_cloud->width = static_cast<int>(head_center_votes_.size ());
214  votes_cloud->height = 1;
215 
216  int p = 0;
217  for (size_t i = 0; i < head_center_original_votes_clustered_.size (); i++)
218  {
219  for (size_t j = 0; j < head_center_original_votes_clustered_[i].size (); j++, p++)
220  {
221  votes_cloud->points[p].getVector3fMap () = head_center_original_votes_clustered_[i][j];
222  votes_cloud->points[p].intensity = 0.1f * static_cast<float> (i);
223  }
224  }
225 
226  votes_cloud->points.resize (p);
227  }
228 
229  //get heads
230  void getDetectedFaces(std::vector<Eigen::VectorXf> & faces)
231  {
232  for (size_t i = 0; i < head_clusters_centers_.size (); i++)
233  {
234  Eigen::VectorXf head (6);
235  head[0] = head_clusters_centers_[i][0];
236  head[1] = head_clusters_centers_[i][1];
237  head[2] = head_clusters_centers_[i][2];
238  head[3] = head_clusters_rotation_[i][0];
239  head[4] = head_clusters_rotation_[i][1];
240  head[5] = head_clusters_rotation_[i][2];
241  faces.push_back (head);
242  }
243  }
244  /*
245  * Other functions
246  */
248  {
249  input_ = cloud;
250  }
251 
253  {
254  face_heat_map_ = heat_map;
255  }
256 
257  void trainWithDataProvider();
258  void faceVotesClustering();
259  void detectFaces();
260  };
261 }
262 
263 #endif /* PCL_RF_FACE_DETECTOR_TRAINER_H_ */
Class representing a decision forest.
void setInputCloud(pcl::PointCloud< pcl::PointXYZ >::Ptr &cloud)
void setForestFilename(std::string &ff)
std::vector< PointT, Eigen::aligned_allocator< PointT > > points
The point data.
Definition: point_cloud.h:410
void getDetectedFaces(std::vector< Eigen::VectorXf > &faces)
void setForest(pcl::DecisionForest< NodeType > &forest)
uint32_t height
The point cloud height (if organized as an image-structure).
Definition: point_cloud.h:415
void getVotes(pcl::PointCloud< pcl::PointXYZ >::Ptr &votes_cloud)
boost::shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:428
uint32_t width
The point cloud width (if organized as an image-structure).
Definition: point_cloud.h:413
void setDirectory(std::string &dir)
void getFaceHeatMap(pcl::PointCloud< pcl::PointXYZI >::Ptr &heat_map)
void setFaceHeatMapCloud(pcl::PointCloud< pcl::PointXYZI >::Ptr &heat_map)
void getVotes2(pcl::PointCloud< pcl::PointXYZI >::Ptr &votes_cloud)
void getVotes(pcl::PointCloud< pcl::PointXYZI >::Ptr &votes_cloud)
void setPoseRefinement(bool do_it, int iters=5)