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