add method to fill soft cascade

This commit is contained in:
marina.kolpakova 2012-09-04 13:52:07 +04:00
parent 7290d8576d
commit fe2c38be80
2 changed files with 75 additions and 12 deletions

View File

@ -494,9 +494,9 @@ class CV_EXPORTS SoftCascade
{
public:
SoftCascade();
SoftCascade( const string& filename );
SoftCascade( const string& filename, const float minScale = 0.4f, const float maxScale = 5.f);
virtual ~SoftCascade();
bool load( const string& filename );
bool load( const string& filename, const float minScale = 0.4f, const float maxScale = 5.f);
virtual void detectMultiScale(const Mat& image, const std::vector<cv::Rect>& rois, std::vector<cv::Rect>& objects, double factor = 1.05, int step = 4, int rejectfactor = 1);
@ -506,7 +506,15 @@ protected:
// int stripSize, int yStep, double factor, vector<Rect>& candidates,
// vector<int>& rejectLevels, vector<double>& levelWeights, bool outputRejectLevels=false);
enum { BOOST = 0 };
enum { FRAME_WIDTH = 640, FRAME_HEIGHT = 480, TOTAL_SCALES = 55, CLASSIFIERS = 5};
enum
{
FRAME_WIDTH = 640,
FRAME_HEIGHT = 480,
TOTAL_SCALES = 55,
CLASSIFIERS = 5,
ORIG_OBJECT_WIDTH = 64,
ORIG_OBJECT_HEIGHT = 128
};
private:
struct Feature

View File

@ -41,9 +41,10 @@
#include <precomp.hpp>
#include <opencv2/objdetect/objdetect.hpp>
#include <opencv2/core/core.hpp>
#include <vector>
#include <string>
struct cv::SoftCascade::Filds
{
@ -53,6 +54,50 @@ struct cv::SoftCascade::Filds
// cv::Mat magnitude;
// double scaleFactor;
// int windowStep;
float minScale;
float maxScale;
int noctaves;
bool fill(const FileNode &root, const float mins, const float maxs)
{
minScale = mins;
maxScale = maxs;
const char *SC_STAGE_TYPE = "stageType";
const char *SC_FEATURE_TYPE = "featureType";
const char *SC_BOOST = "BOOST";
const char *SC_ICF = "ICF";
const char *SC_NUM_OCTAVES = "octavesNum";
const char* SC_CASCADES = "cascades";
const char *SC_HEIGHT = "height";
const char *SC_WIDTH = "width";
const char *SC_MAX_DEPTH = "maxDepth";
const char *SC_STAGES = "stages";
const char *SC_STAGE_THRESHOLD = "stageThreshold";
// only boost supported
std::string stageTypeStr = (string)root[SC_STAGE_TYPE];
CV_Assert(stageTypeStr == SC_BOOST);
// only HOG-like integral channel features cupported
string featureTypeStr = (string)root[SC_FEATURE_TYPE];
CV_Assert(featureTypeStr == SC_ICF);
noctaves = (int)root[SC_NUM_OCTAVES];
CV_Assert(noctaves > 0);
// const char *SC_WEAK_CLASSIFIERS = "weakClassifiers";
// const char *SC_INTERNAL_NODES = "internalNodes";
// const char *SC_LEAF_VALUES = "leafValues";
// const char *SC_FEATURES = "features";
// const char *SC_RECT = "rect";
// const char *SC_STAGE_PARAMS = "stageParams";
// const char *SC_FEATURE_PARAMS = "featureParams";
// const char *SC_MAX_CAT_COUNT = "maxCatCount";
return true;
}
};
namespace {
@ -161,18 +206,28 @@ struct Level {
cv::SoftCascade::SoftCascade() : filds(0) {}
cv::SoftCascade::SoftCascade( const string& filename )
cv::SoftCascade::SoftCascade( const string& filename, const float minScale, const float maxScale)
{
filds = new Filds;
load(filename);
load(filename, minScale, maxScale);
}
cv::SoftCascade::~SoftCascade()
{
delete filds;
}
bool cv::SoftCascade::load( const string& filename )
bool cv::SoftCascade::load( const string& filename, const float minScale, const float maxScale)
{
delete filds;
filds = 0;
cv::FileStorage fs(filename, FileStorage::READ);
if (!fs.isOpened()) return false;
filds = new Filds;
if (!(*filds).fill(fs.getFirstTopLevelNode(), minScale, maxScale)) return false;
////////////////
// temp fixture
Filds& flds = *filds;
flds.octaves.push_back(0.5f);
@ -182,12 +237,9 @@ bool cv::SoftCascade::load( const string& filename )
flds.octaves.push_back(8.0f);
// scales calculations
int origObjectW = 64;
int origObjectH = 128;
float maxScale = 5.f, minScale = 0.4f;
std::vector<Level> levels;
pyrLevels(FRAME_WIDTH, FRAME_HEIGHT, origObjectW, origObjectH, TOTAL_SCALES, minScale, maxScale,levels);
pyrLevels(FRAME_WIDTH, FRAME_HEIGHT, ORIG_OBJECT_WIDTH, ORIG_OBJECT_HEIGHT, TOTAL_SCALES, minScale, maxScale, levels);
for (std::vector<Level>::iterator level = levels.begin(); level < levels.end(); ++level)
{
@ -198,11 +250,14 @@ bool cv::SoftCascade::load( const string& filename )
float logAbsScale = fabs((*level).logFactor - logOctave);
if(logAbsScale < minAbsLog)
(*level).assign(*oct, origObjectW, origObjectH);
(*level).assign(*oct, ORIG_OBJECT_WIDTH, ORIG_OBJECT_HEIGHT);
}
}
// load cascade from xml
// read(const FileNode &root)
return true;
}