11 #include <pcl/ml/dt/decision_tree_data_provider.h>
12 #include <pcl/recognition/face_detection/face_common.h>
14 #include <boost/algorithm/string.hpp>
15 #include <boost/filesystem/operations.hpp>
21 namespace bf = boost::filesystem;
25 namespace face_detection
27 template<
class FeatureType,
class DataSet,
class LabelType,
class ExampleIndex,
class NodeType>
32 std::vector<std::string> image_files_;
35 int patches_per_image_;
36 int min_images_per_bin_;
38 void getFilesInDirectory(bf::path & dir, std::string & rel_path_so_far, std::vector<std::string> & relative_paths, std::string & ext)
40 for (
const auto& dir_entry : bf::directory_iterator(dir))
43 if (bf::is_directory (dir_entry))
45 std::string so_far = rel_path_so_far + (dir_entry.path ().filename ()).
string () +
"/";
46 bf::path curr_path = dir_entry.path ();
47 getFilesInDirectory (curr_path, so_far, relative_paths, ext);
51 std::vector < std::string > strs;
52 std::string file = (dir_entry.path ().filename ()).
string ();
53 boost::split (strs, file, boost::is_any_of (
"."));
54 std::string extension = strs[strs.size () - 1];
58 std::string path = rel_path_so_far + (dir_entry.path ().filename ()).
string ();
59 relative_paths.push_back (path);
65 inline bool readMatrixFromFile(
const std::string& file, Eigen::Matrix4f & matrix)
69 in.open (file.c_str (), std::ifstream::in);
76 in.getline (linebuf, 1024);
77 std::string line (linebuf);
78 std::vector < std::string > strs_2;
79 boost::split (strs_2, line, boost::is_any_of (
" "));
81 for (
int i = 0; i < 16; i++)
83 matrix (i / 4, i % 4) =
static_cast<float> (atof (strs_2[i].c_str ()));
89 bool check_inside(
int col,
int row,
int min_col,
int max_col,
int min_row,
int max_row)
91 return col >= min_col && col <= max_col && row >= min_row && row <= max_row;
94 template<
class Po
intInT>
97 cloud_out.
width = max_col - min_col + 1;
98 cloud_out.
height = max_row - min_row + 1;
100 for (
unsigned int u = 0; u < cloud_out.
width; u++)
102 for (
unsigned int v = 0; v < cloud_out.
height; v++)
104 cloud_out.
at (u, v) = cloud_in.
at (min_col + u, min_row + v);
113 using Ptr = shared_ptr<FaceDetectorDataProvider<FeatureType, DataSet, LabelType, ExampleIndex, NodeType>>;
114 using ConstPtr = shared_ptr<const FaceDetectorDataProvider<FeatureType, DataSet, LabelType, ExampleIndex, NodeType>>;
119 USE_NORMALS_ =
false;
121 patches_per_image_ = 20;
122 min_images_per_bin_ = -1;
127 patches_per_image_ = n;
132 min_images_per_bin_ = n;
155 void getDatasetAndLabels(DataSet & data_set, std::vector<LabelType> & label_data, std::vector<ExampleIndex> & examples)
override;
shared_ptr< const DecisionTreeTrainerDataProvider< FeatureType, DataSet, LabelType, ExampleIndex, NodeType > > ConstPtr
shared_ptr< DecisionTreeTrainerDataProvider< FeatureType, DataSet, LabelType, ExampleIndex, NodeType > > Ptr
const PointT & at(int column, int row) const
Obtain the point given by the (column, row) coordinates.
bool is_dense
True if no points are invalid (e.g., have NaN or Inf values in any of their floating point fields).
void resize(std::size_t count)
Resizes the container to contain count elements.
std::uint32_t width
The point cloud width (if organized as an image-structure).
std::uint32_t height
The point cloud height (if organized as an image-structure).
FaceDetectorDataProvider()
void initialize(std::string &data_dir)
void setMinImagesPerBin(int n)
void setUseNormals(bool use)
void setPatchesPerImage(int n)
void getDatasetAndLabels(DataSet &data_set, std::vector< LabelType > &label_data, std::vector< ExampleIndex > &examples) override
Virtual function called to obtain training examples and labels before training a specific tree.
Defines functions, macros and traits for allocating and using memory.