Commit 85aaf88a authored by Vlad Shakhuro's avatar Vlad Shakhuro

Derive ACFFeatureEvaluator from Algorithm

parent c994b489
......@@ -60,37 +60,31 @@ namespace xobjdetect
*/
void computeChannels(InputArray image, OutputArrayOfArrays channels);
class CV_EXPORTS ACFFeatureEvaluator
class CV_EXPORTS ACFFeatureEvaluator : public Algorithm
{
public:
/* Construct evaluator, set features to evaluate */
ACFFeatureEvaluator(const std::vector<Point3i>& features);
/* Set channels for feature evaluation */
void setChannels(InputArrayOfArrays channels);
virtual void setChannels(InputArrayOfArrays channels) = 0;
/* Set window position */
void setPosition(Size position);
virtual void setPosition(Size position) = 0;
/* Evaluate feature with given index for current channels
and window position */
int evaluate(size_t feature_ind) const;
virtual int evaluate(size_t feature_ind) const = 0;
/* Evaluate all features for current channels and window position
Returns matrix-column of features
*/
void evaluateAll(OutputArray feature_values) const;
virtual void evaluateAll(OutputArray feature_values) const = 0;
private:
/* Features to evaluate */
std::vector<Point3i> features_;
/* Channels for feature evaluation */
std::vector<Mat> channels_;
/* Channels window position */
Size position_;
};
/* Construct evaluator, set features to evaluate */
CV_EXPORTS Ptr<ACFFeatureEvaluator>
createACFFeatureEvaluator(const std::vector<Point3i>& features);
/* Generate acf features
window_size — size of window in which features should be evaluated
......@@ -158,7 +152,7 @@ private:
float pos_value_, neg_value_;
};
class CV_EXPORTS WaldBoost
class CV_EXPORTS WaldBoost : public Algorithm
{
public:
/* Initialize WaldBoost cascade with default of specified parameters */
......
......@@ -45,33 +45,44 @@ using std::vector;
using std::min;
#include <iostream>
using std::cout;
using std::endl;
namespace cv
{
namespace xobjdetect
{
ACFFeatureEvaluator::ACFFeatureEvaluator(const vector<Point3i>& features):
features_(features), channels_(), position_()
{
}
int ACFFeatureEvaluator::evaluate(size_t feature_ind) const
class ACFFeatureEvaluatorImpl : public ACFFeatureEvaluator
{
/* Assume there are 10 channels */
CV_Assert(channels_.size() == 10);
CV_Assert(feature_ind < features_.size());
Point3i feature = features_.at(feature_ind);
int x = feature.x;
int y = feature.y;
int n = feature.z;
return channels_[n].at<int>(y, x);
}
public:
ACFFeatureEvaluatorImpl(const vector<Point3i>& features):
features_(features), channels_(), position_()
{
CV_Assert(features.size() > 0);
}
void ACFFeatureEvaluator::setChannels(cv::InputArrayOfArrays channels)
virtual void setChannels(InputArrayOfArrays channels);
virtual void setPosition(Size position);
virtual int evaluate(size_t feature_ind) const;
virtual void evaluateAll(OutputArray feature_values) const;
private:
/* Features to evaluate */
std::vector<Point3i> features_;
/* Channels for feature evaluation */
std::vector<Mat> channels_;
/* Channels window position */
Size position_;
};
void ACFFeatureEvaluatorImpl::setChannels(cv::InputArrayOfArrays channels)
{
channels_.clear();
vector<Mat> ch;
channels.getMatVector(ch);
CV_Assert(ch.size() == 10);
for( size_t i = 0; i < ch.size(); ++i )
{
const Mat &channel = ch[i];
......@@ -92,12 +103,24 @@ void ACFFeatureEvaluator::setChannels(cv::InputArrayOfArrays channels)
}
}
void ACFFeatureEvaluator::setPosition(Size position)
void ACFFeatureEvaluatorImpl::setPosition(Size position)
{
position_ = position;
}
void ACFFeatureEvaluator::evaluateAll(OutputArray feature_values) const
int ACFFeatureEvaluatorImpl::evaluate(size_t feature_ind) const
{
CV_Assert(channels_.size() == 10);
CV_Assert(feature_ind < features_.size());
Point3i feature = features_.at(feature_ind);
int x = feature.x;
int y = feature.y;
int n = feature.z;
return channels_[n].at<int>(y, x);
}
void ACFFeatureEvaluatorImpl::evaluateAll(OutputArray feature_values) const
{
Mat_<int> feature_vals(1, (int)features_.size());
for( int i = 0; i < (int)features_.size(); ++i )
......@@ -107,6 +130,12 @@ void ACFFeatureEvaluator::evaluateAll(OutputArray feature_values) const
feature_values.setTo(feature_vals);
}
Ptr<ACFFeatureEvaluator>
createACFFeatureEvaluator(const vector<Point3i>& features)
{
return Ptr<ACFFeatureEvaluator>(new ACFFeatureEvaluatorImpl(features));
}
vector<Point3i> generateFeatures(Size window_size, int count)
{
CV_Assert(count > 0);
......
......@@ -118,7 +118,7 @@ void ICFDetector::train(const vector<string>& image_filenames,
labels(0, i) = -1;
vector<Point3i> features = generateFeatures(model_size);
ACFFeatureEvaluator feature_evaluator(features);
Ptr<ACFFeatureEvaluator> feature_evaluator = createACFFeatureEvaluator(features);
Mat_<int> data((int)features.size(), (int)samples.size());
Mat_<int> feature_col;
......@@ -127,8 +127,8 @@ void ICFDetector::train(const vector<string>& image_filenames,
for( int i = 0; i < (int)samples.size(); ++i )
{
computeChannels(samples[i], channels);
feature_evaluator.setChannels(channels);
feature_evaluator.evaluateAll(feature_col);
feature_evaluator->setChannels(channels);
feature_evaluator->evaluateAll(feature_col);
for( int j = 0; j < feature_col.rows; ++j )
data(i, j) = feature_col(0, j);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment