12 #include <pcl/ml/dt/decision_tree_data_provider.h>
13 #include <pcl/recognition/face_detection/face_common.h>
15 #include <boost/algorithm/string.hpp>
16 #include <boost/filesystem/operations.hpp>
23 namespace bf = boost::filesystem;
27 namespace face_detection
29 template<
class FeatureType,
class DataSet,
class LabelType,
class ExampleIndex,
class NodeType>
34 std::vector<std::string> image_files_;
37 int patches_per_image_;
38 int min_images_per_bin_;
40 void getFilesInDirectory(bf::path & dir, std::string & rel_path_so_far, std::vector<std::string> & relative_paths, std::string & ext)
42 for (
const auto& dir_entry : bf::directory_iterator(dir))
45 if (bf::is_directory (dir_entry))
47 std::string so_far = rel_path_so_far + (dir_entry.path ().filename ()).
string () +
"/";
48 bf::path curr_path = dir_entry.path ();
49 getFilesInDirectory (curr_path, so_far, relative_paths, ext);
53 std::vector < std::string > strs;
54 std::string file = (dir_entry.path ().filename ()).
string ();
55 boost::split (strs, file, boost::is_any_of (
"."));
56 std::string extension = strs[strs.size () - 1];
60 std::string path = rel_path_so_far + (dir_entry.path ().filename ()).
string ();
61 relative_paths.push_back (path);
67 inline bool readMatrixFromFile(std::string file, Eigen::Matrix4f & matrix)
71 in.open (file.c_str (), std::ifstream::in);
78 in.getline (linebuf, 1024);
79 std::string line (linebuf);
80 std::vector < std::string > strs_2;
81 boost::split (strs_2, line, boost::is_any_of (
" "));
83 for (
int i = 0; i < 16; i++)
85 matrix (i / 4, i % 4) =
static_cast<float> (atof (strs_2[i].c_str ()));
91 bool check_inside(
int col,
int row,
int min_col,
int max_col,
int min_row,
int max_row)
93 return col >= min_col && col <= max_col && row >= min_row && row <= max_row;
96 template<
class Po
intInT>
99 cloud_out.
width = max_col - min_col + 1;
100 cloud_out.
height = max_row - min_row + 1;
102 for (
unsigned int u = 0; u < cloud_out.
width; u++)
104 for (
unsigned int v = 0; v < cloud_out.
height; v++)
106 cloud_out.
at (u, v) = cloud_in.
at (min_col + u, min_row + v);
115 using Ptr = shared_ptr<FaceDetectorDataProvider<FeatureType, DataSet, LabelType, ExampleIndex, NodeType>>;
116 using ConstPtr = shared_ptr<const FaceDetectorDataProvider<FeatureType, DataSet, LabelType, ExampleIndex, NodeType>>;
121 USE_NORMALS_ =
false;
123 patches_per_image_ = 20;
124 min_images_per_bin_ = -1;
134 patches_per_image_ = n;
139 min_images_per_bin_ = n;
162 void getDatasetAndLabels(DataSet & data_set, std::vector<LabelType> & label_data, std::vector<ExampleIndex> & examples)
override;