1 #ifndef _OPENCV_CASCADECLASSIFIER_H_
2 #define _OPENCV_CASCADECLASSIFIER_H_
5 #include "traincascade_features.h"
6 #include "haarfeatures.h"
7 #include "lbpfeatures.h"
8 #include "HOGfeatures.h" //new
13 #define CC_CASCADE_FILENAME "cascade.xml"
14 #define CC_PARAMS_FILENAME "params.xml"
16 #define CC_CASCADE_PARAMS "cascadeParams"
17 #define CC_STAGE_TYPE "stageType"
18 #define CC_FEATURE_TYPE "featureType"
19 #define CC_HEIGHT "height"
20 #define CC_WIDTH "width"
22 #define CC_STAGE_NUM "stageNum"
23 #define CC_STAGES "stages"
24 #define CC_STAGE_PARAMS "stageParams"
26 #define CC_BOOST "BOOST"
27 #define CC_BOOST_TYPE "boostType"
28 #define CC_DISCRETE_BOOST "DAB"
29 #define CC_REAL_BOOST "RAB"
30 #define CC_LOGIT_BOOST "LB"
31 #define CC_GENTLE_BOOST "GAB"
32 #define CC_MINHITRATE "minHitRate"
33 #define CC_MAXFALSEALARM "maxFalseAlarm"
34 #define CC_TRIM_RATE "weightTrimRate"
35 #define CC_MAX_DEPTH "maxDepth"
36 #define CC_WEAK_COUNT "maxWeakCount"
37 #define CC_STAGE_THRESHOLD "stageThreshold"
38 #define CC_WEAK_CLASSIFIERS "weakClassifiers"
39 #define CC_INTERNAL_NODES "internalNodes"
40 #define CC_LEAF_VALUES "leafValues"
42 #define CC_FEATURES FEATURES
43 #define CC_FEATURE_PARAMS "featureParams"
44 #define CC_MAX_CAT_COUNT "maxCatCount"
45 #define CC_FEATURE_SIZE "featSize"
47 #define CC_HAAR "HAAR"
48 #define CC_MODE "mode"
49 #define CC_MODE_BASIC "BASIC"
50 #define CC_MODE_CORE "CORE"
51 #define CC_MODE_ALL "ALL"
52 #define CC_RECTS "rects"
53 #define CC_TILTED "tilted"
56 #define CC_RECT "rect"
61 #define TIME( arg ) (((double) clock()) / CLOCKS_PER_SEC)
63 #define TIME( arg ) (time( arg ))
66 class CvCascadeParams : public CvParams
70 static const int defaultStageType = BOOST;
71 static const int defaultFeatureType = CvFeatureParams::HAAR;
74 CvCascadeParams( int _stageType, int _featureType );
75 void write( cv::FileStorage &fs ) const;
76 bool read( const cv::FileNode &node );
78 void printDefaults() const;
79 void printAttrs() const;
80 bool scanAttr( const std::string prmName, const std::string val );
87 class CvCascadeClassifier
90 bool train( const std::string _cascadeDirName,
91 const std::string _posFilename,
92 const std::string _negFilename,
93 int _numPos, int _numNeg,
94 int _precalcValBufSize, int _precalcIdxBufSize,
96 const CvCascadeParams& _cascadeParams,
97 const CvFeatureParams& _featureParams,
98 const CvCascadeBoostParams& _stageParams,
99 bool baseFormatSave = false );
101 int predict( int sampleIdx );
102 void save( const std::string cascadeDirName, bool baseFormat = false );
103 bool load( const std::string cascadeDirName );
104 bool updateTrainingSet( double& acceptanceRatio );
105 int fillPassedSamples( int first, int count, bool isPositive, int64& consumed );
107 void writeParams( cv::FileStorage &fs ) const;
108 void writeStages( cv::FileStorage &fs, const cv::Mat& featureMap ) const;
109 void writeFeatures( cv::FileStorage &fs, const cv::Mat& featureMap ) const;
110 bool readParams( const cv::FileNode &node );
111 bool readStages( const cv::FileNode &node );
113 void getUsedFeaturesIdxMap( cv::Mat& featureMap );
115 CvCascadeParams cascadeParams;
116 cv::Ptr<CvFeatureParams> featureParams;
117 cv::Ptr<CvCascadeBoostParams> stageParams;
119 cv::Ptr<CvFeatureEvaluator> featureEvaluator;
120 std::vector< cv::Ptr<CvCascadeBoost> > stageClassifiers;
121 CvCascadeImageReader imgReader;
122 int numStages, curNumSamples;