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