Point Cloud Library (PCL) 1.13.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
79 virtual ~RFFaceDetectorTrainer() = default;
80
81 /*
82 * Common parameters
83 */
84 void setForestFilename(std::string & ff)
85 {
86 forest_filename_ = ff;
87 }
88
89 void setUseNormals(bool use)
90 {
91 use_normals_ = use;
92 }
93
94 void setWSize(int s)
95 {
96 w_size_ = s;
97 }
98
99 /*
100 * Training parameters
101 */
102
103 void setDirectory(std::string & dir)
104 {
105 directory_ = dir;
106 }
108 {
109 num_images_ = num;
110 }
111
112 void setNumTrees(int num)
113 {
114 ntrees_ = num;
115 }
116
117 void setNumFeatures(int num)
118 {
119 nfeatures_ = num;
120 }
121
122 /*
123 * Detection parameters
124 */
125
126 void setModelPath(std::string & model);
127
128 void setPoseRefinement(bool do_it, int iters = 5)
129 {
130 pose_refinement_ = do_it;
131 icp_iterations_ = iters;
132 }
133
135 {
136 thres_face_ = p;
137 }
138
140 {
141 trans_max_variance_ = max;
142 }
143
144 void setWStride(int s)
145 {
146 stride_sw_ = s;
147 }
148
149 void setFaceMinVotes(int mv)
150 {
151 min_votes_size_ = mv;
152 }
153
155 {
156 used_for_pose_ = n;
157 }
158
160 {
161 forest_ = forest;
162 }
163
164 /*
165 * Get functions
166 */
167
169 {
170 heat_map = face_heat_map_;
171 }
172
173 //get votes
175 {
176 votes_cloud->points.resize (head_center_votes_.size ());
177 votes_cloud->width = head_center_votes_.size ();
178 votes_cloud->height = 1;
179
180 for (std::size_t i = 0; i < head_center_votes_.size (); i++)
181 {
182 (*votes_cloud)[i].getVector3fMap () = head_center_votes_[i];
183 }
184 }
185
187 {
188 votes_cloud->points.resize (head_center_votes_.size ());
189 votes_cloud->width = head_center_votes_.size ();
190 votes_cloud->height = 1;
191
192 int p = 0;
193 for (std::size_t i = 0; i < head_center_votes_clustered_.size (); i++)
194 {
195 for (std::size_t j = 0; j < head_center_votes_clustered_[i].size (); j++, p++)
196 {
197 (*votes_cloud)[p].getVector3fMap () = head_center_votes_clustered_[i][j];
198 (*votes_cloud)[p].intensity = 0.1f * static_cast<float> (i);
199 }
200 }
201
202 votes_cloud->points.resize (p);
203 }
204
206 {
207 votes_cloud->points.resize (head_center_votes_.size ());
208 votes_cloud->width = head_center_votes_.size ();
209 votes_cloud->height = 1;
210
211 int p = 0;
212 for (std::size_t i = 0; i < head_center_original_votes_clustered_.size (); i++)
213 {
214 for (std::size_t j = 0; j < head_center_original_votes_clustered_[i].size (); j++, p++)
215 {
216 (*votes_cloud)[p].getVector3fMap () = head_center_original_votes_clustered_[i][j];
217 (*votes_cloud)[p].intensity = 0.1f * static_cast<float> (i);
218 }
219 }
220
221 votes_cloud->points.resize (p);
222 }
223
224 //get heads
225 void getDetectedFaces(std::vector<Eigen::VectorXf> & faces)
226 {
227 for (std::size_t i = 0; i < head_clusters_centers_.size (); i++)
228 {
229 Eigen::VectorXf head (6);
230 head[0] = head_clusters_centers_[i][0];
231 head[1] = head_clusters_centers_[i][1];
232 head[2] = head_clusters_centers_[i][2];
233 head[3] = head_clusters_rotation_[i][0];
234 head[4] = head_clusters_rotation_[i][1];
235 head[5] = head_clusters_rotation_[i][2];
236 faces.push_back (head);
237 }
238 }
239 /*
240 * Other functions
241 */
243 {
244 input_ = cloud;
245 }
246
248 {
249 face_heat_map_ = heat_map;
250 }
251
255 };
256}
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)
virtual ~RFFaceDetectorTrainer()=default
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