8 #ifndef FACE_DETECTOR_DATA_PROVIDER_H_ 9 #define FACE_DETECTOR_DATA_PROVIDER_H_ 12 #include "pcl/recognition/face_detection/face_common.h" 13 #include <pcl/ml/dt/decision_tree_data_provider.h> 14 #include <boost/filesystem/operations.hpp> 18 #include <boost/algorithm/string.hpp> 20 namespace bf = boost::filesystem;
24 namespace face_detection
26 template<
class FeatureType,
class DataSet,
class LabelType,
class ExampleIndex,
class NodeType>
31 std::vector<std::string> image_files_;
34 int patches_per_image_;
35 int min_images_per_bin_;
37 void getFilesInDirectory(bf::path & dir, std::string & rel_path_so_far, std::vector<std::string> & relative_paths, std::string & ext)
39 bf::directory_iterator end_itr;
40 for (bf::directory_iterator itr (dir); itr != end_itr; ++itr)
43 if (bf::is_directory (*itr))
45 #if BOOST_FILESYSTEM_VERSION == 3 46 std::string so_far = rel_path_so_far + (itr->path ().filename ()).
string () +
"/";
48 std::string so_far = rel_path_so_far + (itr->path ()).filename () +
"/";
51 bf::path curr_path = itr->path ();
52 getFilesInDirectory (curr_path, so_far, relative_paths, ext);
56 std::vector < std::string > strs;
57 #if BOOST_FILESYSTEM_VERSION == 3 58 std::string file = (itr->path ().filename ()).
string ();
60 std::string file = (itr->path ()).filename ();
63 boost::split (strs, file, boost::is_any_of (
"."));
64 std::string extension = strs[strs.size () - 1];
66 if (extension.compare (ext) == 0)
68 #if BOOST_FILESYSTEM_VERSION == 3 69 std::string path = rel_path_so_far + (itr->path ().filename ()).
string ();
71 std::string path = rel_path_so_far + (itr->path ()).filename ();
74 relative_paths.push_back (path);
80 inline bool readMatrixFromFile(std::string file, Eigen::Matrix4f & matrix)
84 in.open (file.c_str (), std::ifstream::in);
91 in.getline (linebuf, 1024);
92 std::string line (linebuf);
93 std::vector < std::string > strs_2;
94 boost::split (strs_2, line, boost::is_any_of (
" "));
96 for (
int i = 0; i < 16; i++)
98 matrix (i / 4, i % 4) = static_cast<float> (atof (strs_2[i].c_str ()));
104 bool check_inside(
int col,
int row,
int min_col,
int max_col,
int min_row,
int max_row)
106 if (col >= min_col && col <= max_col && row >= min_row && row <= max_row)
112 template<
class Po
intInT>
115 cloud_out.
width = max_col - min_col + 1;
116 cloud_out.
height = max_row - min_row + 1;
118 for (
unsigned int u = 0; u < cloud_out.
width; u++)
120 for (
unsigned int v = 0; v < cloud_out.
height; v++)
122 cloud_out.
at (u, v) = cloud_in.
at (min_col + u, min_row + v);
134 USE_NORMALS_ =
false;
136 patches_per_image_ = 20;
137 min_images_per_bin_ = -1;
147 patches_per_image_ = n;
152 min_images_per_bin_ = n;
175 void getDatasetAndLabels(DataSet & data_set, std::vector<LabelType> & label_data, std::vector<ExampleIndex> & examples);
std::vector< PointT, Eigen::aligned_allocator< PointT > > points
The point data.
This file defines compatibility wrappers for low level I/O functions.
const PointT & at(int column, int row) const
Obtain the point given by the (column, row) coordinates.
void getDatasetAndLabels(DataSet &data_set, std::vector< LabelType > &label_data, std::vector< ExampleIndex > &examples)
Virtual function called to obtain training examples and labels before training a specific tree.
uint32_t height
The point cloud height (if organized as an image-structure).
void setUseNormals(bool use)
Define standard C methods and C++ classes that are common to all methods.
uint32_t width
The point cloud width (if organized as an image-structure).
void initialize(std::string &data_dir)
void setMinImagesPerBin(int n)
void setPatchesPerImage(int n)
bool is_dense
True if no points are invalid (e.g., have NaN or Inf values in any of their floating point fields).
virtual ~FaceDetectorDataProvider()
FaceDetectorDataProvider()