10#include "pcl/recognition/face_detection/face_common.h"
11#include <pcl/ml/feature_handler.h>
12#include <pcl/ml/stats_estimator.h>
13#include <pcl/ml/branch_estimator.h>
17 namespace face_detection
19 template<
class FT,
class DataSet,
class ExampleIndex>
27 float min_valid_small_patch_depth_;
35 min_valid_small_patch_depth_ = 0.5f;
96 srand (
static_cast<unsigned int>(time (
nullptr)));
107 f.row1_ =
rand () % (wsize_ - max_patch_size_ - 1);
108 f.col1_ =
rand () % (wsize_ / 2 - max_patch_size_ - 1);
112 f.row2_ =
rand () % (wsize_ - max_patch_size_ - 1);
113 f.col2_ = wsize_ / 2 +
rand () % (wsize_ / 2 - max_patch_size_ - 1);
118 if (num_channels_ > 1)
119 f.used_ii_ =
rand () % num_channels_;
127 for (std::size_t j = 0; j <= 10; j++)
130 features.push_back (f);
143 std::vector<unsigned char> & flags)
const override
162 int el_f1 =
te.iimages_[feature.used_ii_]->getFiniteElementsCount (
te.col_ + feature.col1_,
te.row_ + feature.row1_, feature.wsizex1_,
164 int el_f2 =
te.iimages_[feature.used_ii_]->getFiniteElementsCount (
te.col_ + feature.col2_,
te.row_ + feature.row2_, feature.wsizex2_,
167 float sum_f1 =
static_cast<float>(
te.iimages_[feature.used_ii_]->getFirstOrderSum (
te.col_ + feature.col1_,
te.row_ + feature.row1_, feature.wsizex1_, feature.wsizey1_));
168 float sum_f2 =
static_cast<float>(
te.iimages_[feature.used_ii_]->getFirstOrderSum (
te.col_ + feature.col2_,
te.row_ + feature.row2_, feature.wsizex2_, feature.wsizey2_));
170 float f = min_valid_small_patch_depth_;
171 if (
el_f1 == 0 ||
el_f2 == 0 || (
el_f1 <=
static_cast<int> (f *
static_cast<float>(feature.wsizex1_ * feature.wsizey1_)))
172 || (
el_f2 <=
static_cast<int> (f *
static_cast<float>(feature.wsizex2_ * feature.wsizey2_))))
195 template<
class LabelDataType,
class NodeType,
class DataSet,
class ExampleIndex>
232 Eigen::Vector3d & centroid)
const
234 Eigen::Matrix<double, 1, 9, Eigen::RowMajor>
accu = Eigen::Matrix<double, 1, 9, Eigen::RowMajor>::Zero ();
240 accu[0] +=
te.trans_[0] *
te.trans_[0];
241 accu[1] +=
te.trans_[0] *
te.trans_[1];
242 accu[2] +=
te.trans_[0] *
te.trans_[2];
243 accu[3] +=
te.trans_[1] *
te.trans_[1];
244 accu[4] +=
te.trans_[1] *
te.trans_[2];
245 accu[5] +=
te.trans_[2] *
te.trans_[2];
254 centroid.head<3> ().
matrix () =
accu.tail<3> ();
276 Eigen::Vector3d & centroid)
const
278 Eigen::Matrix<double, 1, 9, Eigen::RowMajor>
accu = Eigen::Matrix<double, 1, 9, Eigen::RowMajor>::Zero ();
298 centroid.head<3> ().
matrix () =
accu.tail<3> ();
322 std::vector<float> &
results, std::vector<unsigned char> & flags,
const float threshold)
const override
418 + 0.5f * std::log (std::pow (2 *
M_PI, 3)
495 node.variance = variance;
520 stream <<
"ERROR: RegressionVarianceStatsEstimator does not implement generateCodeForBranchIndex(...)";
529 stream <<
"ERROR: RegressionVarianceStatsEstimator does not implement generateCodeForBranchIndex(...)";
Interface for branch estimators.
virtual std::size_t getNumOfBranches() const =0
Returns the number of branches the corresponding tree has.
virtual void computeBranchIndex(const float result, const unsigned char flag, const float threshold, unsigned char &branch_index) const =0
Computes the branch index for the specified result.
Iterator class for point clouds with or without given indices.
std::size_t size() const
Size of the range the iterator is going through.
Utility class interface which is used for creating and evaluating features.
Class interface for gathering statistics for decision tree learning.
void setWSize(int w)
Sets the size of the window to extract features.
void setMaxPatchSize(int w)
Create a set of random tests to evaluate examples.
FeatureHandlerDepthAverage()
void createRandomFeatures(const std::size_t num_of_features, std::vector< FT > &features) override
Create a set of random tests to evaluate examples.
void generateCodeForEvaluation(const FT &, ::std::ostream &) const override
Generates evaluation code for the specified feature and writes it to the specified stream.
void evaluateFeature(const FT &feature, DataSet &data_set, const ExampleIndex &example, float &result, unsigned char &flag) const override
Evaluates a feature on the specified example.
void setNumChannels(int nf)
Sets the number of channels a feature has (i.e.
void evaluateFeature(const FT &feature, DataSet &data_set, std::vector< ExampleIndex > &examples, std::vector< float > &results, std::vector< unsigned char > &flags) const override
Evaluates a feature on the specified set of examples.
Statistics estimator for regression trees which optimizes information gain and pose parameters error.
void computeAndSetNodeStats(DataSet &data_set, std::vector< ExampleIndex > &examples, std::vector< LabelDataType > &label_data, NodeType &node) const override
Computes and sets the statistics for a node.
void computeBranchIndices(std::vector< float > &results, std::vector< unsigned char > &flags, const float threshold, std::vector< unsigned char > &branch_indices) const override
Computes the branch indices for all supplied results.
unsigned int computeMeanAndCovarianceAngles(DataSet &data_set, std::vector< ExampleIndex > &examples, Eigen::Matrix3d &covariance_matrix, Eigen::Vector3d ¢roid) const
Computes the covariance matrix for rotation values.
LabelDataType getLabelOfNode(NodeType &node) const override
Returns the label of the specified node.
PoseClassRegressionVarianceStatsEstimator(BranchEstimator *branch_estimator)
Constructor.
unsigned int computeMeanAndCovarianceOffset(DataSet &data_set, std::vector< ExampleIndex > &examples, Eigen::Matrix3d &covariance_matrix, Eigen::Vector3d ¢roid) const
Computes the covariance matrix for translation offsets.
~PoseClassRegressionVarianceStatsEstimator()
Destructor.
void generateCodeForBranchIndexComputation(NodeType &, std::ostream &stream) const override
Generates code for branch index computation.
void computeBranchIndex(const float result, const unsigned char flag, const float threshold, unsigned char &branch_index) const override
Computes the branch index for the specified result.
void generateCodeForOutput(NodeType &, std::ostream &stream) const override
Generates code for label output.
float computeInformationGain(DataSet &data_set, std::vector< ExampleIndex > &examples, std::vector< LabelDataType > &label_data, std::vector< float > &results, std::vector< unsigned char > &flags, const float threshold) const override
Computes the information gain obtained by the specified threshold.
std::size_t getNumOfBranches() const override
Returns the number of branches the corresponding tree has.
__inline double pcl_round(double number)
Win32 doesn't seem to have rounding functions.