Path: blob/master/apps/traincascade/cascadeclassifier.h
16337 views
#ifndef _OPENCV_CASCADECLASSIFIER_H_1#define _OPENCV_CASCADECLASSIFIER_H_23#include <ctime>4#include "traincascade_features.h"5#include "haarfeatures.h"6#include "lbpfeatures.h"7#include "HOGfeatures.h" //new8#include "boost.h"910#define CC_CASCADE_FILENAME "cascade.xml"11#define CC_PARAMS_FILENAME "params.xml"1213#define CC_CASCADE_PARAMS "cascadeParams"14#define CC_STAGE_TYPE "stageType"15#define CC_FEATURE_TYPE "featureType"16#define CC_HEIGHT "height"17#define CC_WIDTH "width"1819#define CC_STAGE_NUM "stageNum"20#define CC_STAGES "stages"21#define CC_STAGE_PARAMS "stageParams"2223#define CC_BOOST "BOOST"24#define CC_BOOST_TYPE "boostType"25#define CC_DISCRETE_BOOST "DAB"26#define CC_REAL_BOOST "RAB"27#define CC_LOGIT_BOOST "LB"28#define CC_GENTLE_BOOST "GAB"29#define CC_MINHITRATE "minHitRate"30#define CC_MAXFALSEALARM "maxFalseAlarm"31#define CC_TRIM_RATE "weightTrimRate"32#define CC_MAX_DEPTH "maxDepth"33#define CC_WEAK_COUNT "maxWeakCount"34#define CC_STAGE_THRESHOLD "stageThreshold"35#define CC_WEAK_CLASSIFIERS "weakClassifiers"36#define CC_INTERNAL_NODES "internalNodes"37#define CC_LEAF_VALUES "leafValues"3839#define CC_FEATURES FEATURES40#define CC_FEATURE_PARAMS "featureParams"41#define CC_MAX_CAT_COUNT "maxCatCount"42#define CC_FEATURE_SIZE "featSize"4344#define CC_HAAR "HAAR"45#define CC_MODE "mode"46#define CC_MODE_BASIC "BASIC"47#define CC_MODE_CORE "CORE"48#define CC_MODE_ALL "ALL"49#define CC_RECTS "rects"50#define CC_TILTED "tilted"5152#define CC_LBP "LBP"53#define CC_RECT "rect"5455#define CC_HOG "HOG"5657#ifdef _WIN3258#define TIME( arg ) (((double) clock()) / CLOCKS_PER_SEC)59#else60#define TIME( arg ) (time( arg ))61#endif6263class CvCascadeParams : public CvParams64{65public:66enum { BOOST = 0 };67static const int defaultStageType = BOOST;68static const int defaultFeatureType = CvFeatureParams::HAAR;6970CvCascadeParams();71CvCascadeParams( int _stageType, int _featureType );72void write( cv::FileStorage &fs ) const;73bool read( const cv::FileNode &node );7475void printDefaults() const;76void printAttrs() const;77bool scanAttr( const std::string prmName, const std::string val );7879int stageType;80int featureType;81cv::Size winSize;82};8384class CvCascadeClassifier85{86public:87bool train( const std::string _cascadeDirName,88const std::string _posFilename,89const std::string _negFilename,90int _numPos, int _numNeg,91int _precalcValBufSize, int _precalcIdxBufSize,92int _numStages,93const CvCascadeParams& _cascadeParams,94const CvFeatureParams& _featureParams,95const CvCascadeBoostParams& _stageParams,96bool baseFormatSave = false,97double acceptanceRatioBreakValue = -1.0 );98private:99int predict( int sampleIdx );100void save( const std::string cascadeDirName, bool baseFormat = false );101bool load( const std::string cascadeDirName );102bool updateTrainingSet( double minimumAcceptanceRatio, double& acceptanceRatio );103int fillPassedSamples( int first, int count, bool isPositive, double requiredAcceptanceRatio, int64& consumed );104105void writeParams( cv::FileStorage &fs ) const;106void writeStages( cv::FileStorage &fs, const cv::Mat& featureMap ) const;107void writeFeatures( cv::FileStorage &fs, const cv::Mat& featureMap ) const;108bool readParams( const cv::FileNode &node );109bool readStages( const cv::FileNode &node );110111void getUsedFeaturesIdxMap( cv::Mat& featureMap );112113CvCascadeParams cascadeParams;114cv::Ptr<CvFeatureParams> featureParams;115cv::Ptr<CvCascadeBoostParams> stageParams;116117cv::Ptr<CvFeatureEvaluator> featureEvaluator;118std::vector< cv::Ptr<CvCascadeBoost> > stageClassifiers;119CvCascadeImageReader imgReader;120int numStages, curNumSamples;121int numPos, numNeg;122};123124#endif125126127