diff --git a/apps/traincascade/HOGfeatures.cpp b/apps/traincascade/HOGfeatures.cpp index 9a562fcad0..49af05cf01 100644 --- a/apps/traincascade/HOGfeatures.cpp +++ b/apps/traincascade/HOGfeatures.cpp @@ -4,6 +4,8 @@ #include "HOGfeatures.h" #include "cascadeclassifier.h" +using namespace std; +using namespace cv; CvHOGFeatureParams::CvHOGFeatureParams() { diff --git a/apps/traincascade/HOGfeatures.h b/apps/traincascade/HOGfeatures.h index a7f33f6086..cdf758777d 100644 --- a/apps/traincascade/HOGfeatures.h +++ b/apps/traincascade/HOGfeatures.h @@ -20,33 +20,33 @@ class CvHOGEvaluator : public CvFeatureEvaluator public: virtual ~CvHOGEvaluator() {} virtual void init(const CvFeatureParams *_featureParams, - int _maxSampleCount, Size _winSize ); - virtual void setImage(const Mat& img, uchar clsLabel, int idx); + int _maxSampleCount, cv::Size _winSize ); + virtual void setImage(const cv::Mat& img, uchar clsLabel, int idx); virtual float operator()(int varIdx, int sampleIdx) const; - virtual void writeFeatures( FileStorage &fs, const Mat& featureMap ) const; + virtual void writeFeatures( cv::FileStorage &fs, const cv::Mat& featureMap ) const; protected: virtual void generateFeatures(); - virtual void integralHistogram(const Mat &img, vector &histogram, Mat &norm, int nbins) const; + virtual void integralHistogram(const cv::Mat &img, std::vector &histogram, cv::Mat &norm, int nbins) const; class Feature { public: Feature(); Feature( int offset, int x, int y, int cellW, int cellH ); - float calc( const vector &_hists, const Mat &_normSum, size_t y, int featComponent ) const; - void write( FileStorage &fs ) const; - void write( FileStorage &fs, int varIdx ) const; + float calc( const std::vector &_hists, const cv::Mat &_normSum, size_t y, int featComponent ) const; + void write( cv::FileStorage &fs ) const; + void write( cv::FileStorage &fs, int varIdx ) const; - Rect rect[N_CELLS]; //cells + cv::Rect rect[N_CELLS]; //cells struct { int p0, p1, p2, p3; } fastRect[N_CELLS]; }; - vector features; + std::vector features; - Mat normSum; //for nomalization calculation (L1 or L2) - vector hist; + cv::Mat normSum; //for nomalization calculation (L1 or L2) + std::vector hist; }; inline float CvHOGEvaluator::operator()(int varIdx, int sampleIdx) const @@ -57,7 +57,7 @@ inline float CvHOGEvaluator::operator()(int varIdx, int sampleIdx) const return features[featureIdx].calc( hist, normSum, sampleIdx, componentIdx); } -inline float CvHOGEvaluator::Feature::calc( const vector& _hists, const Mat& _normSum, size_t y, int featComponent ) const +inline float CvHOGEvaluator::Feature::calc( const std::vector& _hists, const cv::Mat& _normSum, size_t y, int featComponent ) const { float normFactor; float res; diff --git a/apps/traincascade/boost.cpp b/apps/traincascade/boost.cpp index 4f91d5a29d..d1a2b3e0f7 100644 --- a/apps/traincascade/boost.cpp +++ b/apps/traincascade/boost.cpp @@ -1,6 +1,19 @@ #include "opencv2/core/core.hpp" #include "opencv2/core/internal.hpp" +using cv::Size; +using cv::Mat; +using cv::Point; +using cv::FileStorage; +using cv::Rect; +using cv::Ptr; +using cv::FileNode; +using cv::Mat_; +using cv::Range; +using cv::FileNodeIterator; +using cv::ParallelLoopBody; + + #include "boost.h" #include "cascadeclassifier.h" #include @@ -160,10 +173,10 @@ CvCascadeBoostParams::CvCascadeBoostParams( int _boostType, void CvCascadeBoostParams::write( FileStorage &fs ) const { - String boostTypeStr = boost_type == CvBoost::DISCRETE ? CC_DISCRETE_BOOST : + string boostTypeStr = boost_type == CvBoost::DISCRETE ? CC_DISCRETE_BOOST : boost_type == CvBoost::REAL ? CC_REAL_BOOST : boost_type == CvBoost::LOGIT ? CC_LOGIT_BOOST : - boost_type == CvBoost::GENTLE ? CC_GENTLE_BOOST : String(); + boost_type == CvBoost::GENTLE ? CC_GENTLE_BOOST : string(); CV_Assert( !boostTypeStr.empty() ); fs << CC_BOOST_TYPE << boostTypeStr; fs << CC_MINHITRATE << minHitRate; @@ -175,7 +188,7 @@ void CvCascadeBoostParams::write( FileStorage &fs ) const bool CvCascadeBoostParams::read( const FileNode &node ) { - String boostTypeStr; + string boostTypeStr; FileNode rnode = node[CC_BOOST_TYPE]; rnode >> boostTypeStr; boost_type = !boostTypeStr.compare( CC_DISCRETE_BOOST ) ? CvBoost::DISCRETE : @@ -213,10 +226,10 @@ void CvCascadeBoostParams::printDefaults() const void CvCascadeBoostParams::printAttrs() const { - String boostTypeStr = boost_type == CvBoost::DISCRETE ? CC_DISCRETE_BOOST : + string boostTypeStr = boost_type == CvBoost::DISCRETE ? CC_DISCRETE_BOOST : boost_type == CvBoost::REAL ? CC_REAL_BOOST : boost_type == CvBoost::LOGIT ? CC_LOGIT_BOOST : - boost_type == CvBoost::GENTLE ? CC_GENTLE_BOOST : String(); + boost_type == CvBoost::GENTLE ? CC_GENTLE_BOOST : string(); CV_Assert( !boostTypeStr.empty() ); cout << "boostType: " << boostTypeStr << endl; cout << "minHitRate: " << minHitRate << endl; @@ -226,7 +239,7 @@ void CvCascadeBoostParams::printAttrs() const cout << "maxWeakCount: " << weak_count << endl; } -bool CvCascadeBoostParams::scanAttr( const String prmName, const String val) +bool CvCascadeBoostParams::scanAttr( const string prmName, const string val) { bool res = true; diff --git a/apps/traincascade/boost.h b/apps/traincascade/boost.h index 16f7c2ce1d..0edf776a5b 100644 --- a/apps/traincascade/boost.h +++ b/apps/traincascade/boost.h @@ -13,11 +13,11 @@ struct CvCascadeBoostParams : CvBoostParams CvCascadeBoostParams( int _boostType, float _minHitRate, float _maxFalseAlarm, double _weightTrimRate, int _maxDepth, int _maxWeakCount ); virtual ~CvCascadeBoostParams() {} - void write( FileStorage &fs ) const; - bool read( const FileNode &node ); + void write( cv::FileStorage &fs ) const; + bool read( const cv::FileNode &node ); virtual void printDefaults() const; virtual void printAttrs() const; - virtual bool scanAttr( const String prmName, const String val); + virtual bool scanAttr( const std::string prmName, const std::string val); }; struct CvCascadeBoostTrainData : CvDTreeTrainData @@ -45,7 +45,7 @@ struct CvCascadeBoostTrainData : CvDTreeTrainData virtual void free_train_data(); const CvFeatureEvaluator* featureEvaluator; - Mat valCache; // precalculated feature values (CV_32FC1) + cv::Mat valCache; // precalculated feature values (CV_32FC1) CvMat _resp; // for casting int numPrecalcVal, numPrecalcIdx; }; @@ -54,9 +54,9 @@ class CvCascadeBoostTree : public CvBoostTree { public: virtual CvDTreeNode* predict( int sampleIdx ) const; - void write( FileStorage &fs, const Mat& featureMap ); - void read( const FileNode &node, CvBoost* _ensemble, CvDTreeTrainData* _data ); - void markFeaturesInMap( Mat& featureMap ); + void write( cv::FileStorage &fs, const cv::Mat& featureMap ); + void read( const cv::FileNode &node, CvBoost* _ensemble, CvDTreeTrainData* _data ); + void markFeaturesInMap( cv::Mat& featureMap ); protected: virtual void split_node_data( CvDTreeNode* n ); }; @@ -70,10 +70,10 @@ public: virtual float predict( int sampleIdx, bool returnSum = false ) const; float getThreshold() const { return threshold; } - void write( FileStorage &fs, const Mat& featureMap ) const; - bool read( const FileNode &node, const CvFeatureEvaluator* _featureEvaluator, + void write( cv::FileStorage &fs, const cv::Mat& featureMap ) const; + bool read( const cv::FileNode &node, const CvFeatureEvaluator* _featureEvaluator, const CvCascadeBoostParams& _params ); - void markUsedFeaturesInMap( Mat& featureMap ); + void markUsedFeaturesInMap( cv::Mat& featureMap ); protected: virtual bool set_params( const CvBoostParams& _params ); virtual void update_weights( CvBoostTree* tree ); diff --git a/apps/traincascade/cascadeclassifier.cpp b/apps/traincascade/cascadeclassifier.cpp index 33f29aa7be..7c18348ae5 100644 --- a/apps/traincascade/cascadeclassifier.cpp +++ b/apps/traincascade/cascadeclassifier.cpp @@ -5,6 +5,7 @@ #include using namespace std; +using namespace cv; static const char* stageTypes[] = { CC_BOOST }; static const char* featureTypes[] = { CC_HAAR, CC_LBP, CC_HOG }; @@ -24,10 +25,10 @@ CvCascadeParams::CvCascadeParams( int _stageType, int _featureType ) : stageType void CvCascadeParams::write( FileStorage &fs ) const { - String stageTypeStr = stageType == BOOST ? CC_BOOST : String(); + string stageTypeStr = stageType == BOOST ? CC_BOOST : string(); CV_Assert( !stageTypeStr.empty() ); fs << CC_STAGE_TYPE << stageTypeStr; - String featureTypeStr = featureType == CvFeatureParams::HAAR ? CC_HAAR : + string featureTypeStr = featureType == CvFeatureParams::HAAR ? CC_HAAR : featureType == CvFeatureParams::LBP ? CC_LBP : featureType == CvFeatureParams::HOG ? CC_HOG : 0; @@ -41,7 +42,7 @@ bool CvCascadeParams::read( const FileNode &node ) { if ( node.empty() ) return false; - String stageTypeStr, featureTypeStr; + string stageTypeStr, featureTypeStr; FileNode rnode = node[CC_STAGE_TYPE]; if ( !rnode.isString() ) return false; @@ -96,7 +97,7 @@ void CvCascadeParams::printAttrs() const cout << "sampleHeight: " << winSize.height << endl; } -bool CvCascadeParams::scanAttr( const String prmName, const String val ) +bool CvCascadeParams::scanAttr( const string prmName, const string val ) { bool res = true; if( !prmName.compare( "-stageType" ) ) @@ -126,9 +127,9 @@ bool CvCascadeParams::scanAttr( const String prmName, const String val ) //---------------------------- CascadeClassifier -------------------------------------- -bool CvCascadeClassifier::train( const String _cascadeDirName, - const String _posFilename, - const String _negFilename, +bool CvCascadeClassifier::train( const string _cascadeDirName, + const string _posFilename, + const string _negFilename, int _numPos, int _numNeg, int _precalcValBufSize, int _precalcIdxBufSize, int _numStages, @@ -411,7 +412,7 @@ bool CvCascadeClassifier::readStages( const FileNode &node) #define ICV_HAAR_PARENT_NAME "parent" #define ICV_HAAR_NEXT_NAME "next" -void CvCascadeClassifier::save( const String filename, bool baseFormat ) +void CvCascadeClassifier::save( const string filename, bool baseFormat ) { FileStorage fs( filename, FileStorage::WRITE ); @@ -503,7 +504,7 @@ void CvCascadeClassifier::save( const String filename, bool baseFormat ) fs << "}"; } -bool CvCascadeClassifier::load( const String cascadeDirName ) +bool CvCascadeClassifier::load( const string cascadeDirName ) { FileStorage fs( cascadeDirName + CC_PARAMS_FILENAME, FileStorage::READ ); if ( !fs.isOpened() ) diff --git a/apps/traincascade/cascadeclassifier.h b/apps/traincascade/cascadeclassifier.h index 6890068c21..93be478b4e 100644 --- a/apps/traincascade/cascadeclassifier.h +++ b/apps/traincascade/cascadeclassifier.h @@ -72,24 +72,24 @@ public: CvCascadeParams(); CvCascadeParams( int _stageType, int _featureType ); - void write( FileStorage &fs ) const; - bool read( const FileNode &node ); + void write( cv::FileStorage &fs ) const; + bool read( const cv::FileNode &node ); void printDefaults() const; void printAttrs() const; - bool scanAttr( const String prmName, const String val ); + bool scanAttr( const std::string prmName, const std::string val ); int stageType; int featureType; - Size winSize; + cv::Size winSize; }; class CvCascadeClassifier { public: - bool train( const String _cascadeDirName, - const String _posFilename, - const String _negFilename, + bool train( const std::string _cascadeDirName, + const std::string _posFilename, + const std::string _negFilename, int _numPos, int _numNeg, int _precalcValBufSize, int _precalcIdxBufSize, int _numStages, @@ -99,25 +99,25 @@ public: bool baseFormatSave = false ); private: int predict( int sampleIdx ); - void save( const String cascadeDirName, bool baseFormat = false ); - bool load( const String cascadeDirName ); + void save( const std::string cascadeDirName, bool baseFormat = false ); + bool load( const std::string cascadeDirName ); bool updateTrainingSet( double& acceptanceRatio ); int fillPassedSamples( int first, int count, bool isPositive, int64& consumed ); - void writeParams( FileStorage &fs ) const; - void writeStages( FileStorage &fs, const Mat& featureMap ) const; - void writeFeatures( FileStorage &fs, const Mat& featureMap ) const; - bool readParams( const FileNode &node ); - bool readStages( const FileNode &node ); + void writeParams( cv::FileStorage &fs ) const; + void writeStages( cv::FileStorage &fs, const cv::Mat& featureMap ) const; + void writeFeatures( cv::FileStorage &fs, const cv::Mat& featureMap ) const; + bool readParams( const cv::FileNode &node ); + bool readStages( const cv::FileNode &node ); - void getUsedFeaturesIdxMap( Mat& featureMap ); + void getUsedFeaturesIdxMap( cv::Mat& featureMap ); CvCascadeParams cascadeParams; - Ptr featureParams; - Ptr stageParams; + cv::Ptr featureParams; + cv::Ptr stageParams; - Ptr featureEvaluator; - vector< Ptr > stageClassifiers; + cv::Ptr featureEvaluator; + std::vector< cv::Ptr > stageClassifiers; CvCascadeImageReader imgReader; int numStages, curNumSamples; int numPos, numNeg; diff --git a/apps/traincascade/features.cpp b/apps/traincascade/features.cpp index effa4dcc56..a772aa39ff 100644 --- a/apps/traincascade/features.cpp +++ b/apps/traincascade/features.cpp @@ -5,6 +5,7 @@ #include "cascadeclassifier.h" using namespace std; +using namespace cv; float calcNormFactor( const Mat& sum, const Mat& sqSum ) { @@ -24,7 +25,7 @@ CvParams::CvParams() : name( "params" ) {} void CvParams::printDefaults() const { cout << "--" << name << "--" << endl; } void CvParams::printAttrs() const {} -bool CvParams::scanAttr( const String, const String ) { return false; } +bool CvParams::scanAttr( const string, const string ) { return false; } //---------------------------- FeatureParams -------------------------------------- diff --git a/apps/traincascade/haarfeatures.cpp b/apps/traincascade/haarfeatures.cpp index 0298b42a78..d31db4fcda 100644 --- a/apps/traincascade/haarfeatures.cpp +++ b/apps/traincascade/haarfeatures.cpp @@ -5,6 +5,7 @@ #include "cascadeclassifier.h" using namespace std; +using namespace cv; CvHaarFeatureParams::CvHaarFeatureParams() : mode(BASIC) { @@ -25,9 +26,9 @@ void CvHaarFeatureParams::init( const CvFeatureParams& fp ) void CvHaarFeatureParams::write( FileStorage &fs ) const { CvFeatureParams::write( fs ); - String modeStr = mode == BASIC ? CC_MODE_BASIC : + string modeStr = mode == BASIC ? CC_MODE_BASIC : mode == CORE ? CC_MODE_CORE : - mode == ALL ? CC_MODE_ALL : String(); + mode == ALL ? CC_MODE_ALL : string(); CV_Assert( !modeStr.empty() ); fs << CC_MODE << modeStr; } @@ -40,7 +41,7 @@ bool CvHaarFeatureParams::read( const FileNode &node ) FileNode rnode = node[CC_MODE]; if( !rnode.isString() ) return false; - String modeStr; + string modeStr; rnode >> modeStr; mode = !modeStr.compare( CC_MODE_BASIC ) ? BASIC : !modeStr.compare( CC_MODE_CORE ) ? CORE : @@ -58,13 +59,13 @@ void CvHaarFeatureParams::printDefaults() const void CvHaarFeatureParams::printAttrs() const { CvFeatureParams::printAttrs(); - String mode_str = mode == BASIC ? CC_MODE_BASIC : + string mode_str = mode == BASIC ? CC_MODE_BASIC : mode == CORE ? CC_MODE_CORE : mode == ALL ? CC_MODE_ALL : 0; cout << "mode: " << mode_str << endl; } -bool CvHaarFeatureParams::scanAttr( const String prmName, const String val) +bool CvHaarFeatureParams::scanAttr( const string prmName, const string val) { if ( !CvFeatureParams::scanAttr( prmName, val ) ) { diff --git a/apps/traincascade/haarfeatures.h b/apps/traincascade/haarfeatures.h index 64739027a9..0894d098c3 100644 --- a/apps/traincascade/haarfeatures.h +++ b/apps/traincascade/haarfeatures.h @@ -18,12 +18,12 @@ public: CvHaarFeatureParams( int _mode ); virtual void init( const CvFeatureParams& fp ); - virtual void write( FileStorage &fs ) const; - virtual bool read( const FileNode &node ); + virtual void write( cv::FileStorage &fs ) const; + virtual bool read( const cv::FileNode &node ); virtual void printDefaults() const; virtual void printAttrs() const; - virtual bool scanAttr( const String prm, const String val); + virtual bool scanAttr( const std::string prm, const std::string val); int mode; }; @@ -32,11 +32,11 @@ class CvHaarEvaluator : public CvFeatureEvaluator { public: virtual void init(const CvFeatureParams *_featureParams, - int _maxSampleCount, Size _winSize ); - virtual void setImage(const Mat& img, uchar clsLabel, int idx); + int _maxSampleCount, cv::Size _winSize ); + virtual void setImage(const cv::Mat& img, uchar clsLabel, int idx); virtual float operator()(int featureIdx, int sampleIdx) const; - virtual void writeFeatures( FileStorage &fs, const Mat& featureMap ) const; - void writeFeature( FileStorage &fs, int fi ) const; // for old file fornat + virtual void writeFeatures( cv::FileStorage &fs, const cv::Mat& featureMap ) const; + void writeFeature( cv::FileStorage &fs, int fi ) const; // for old file fornat protected: virtual void generateFeatures(); @@ -48,13 +48,13 @@ protected: int x0, int y0, int w0, int h0, float wt0, int x1, int y1, int w1, int h1, float wt1, int x2 = 0, int y2 = 0, int w2 = 0, int h2 = 0, float wt2 = 0.0F ); - float calc( const Mat &sum, const Mat &tilted, size_t y) const; - void write( FileStorage &fs ) const; + float calc( const cv::Mat &sum, const cv::Mat &tilted, size_t y) const; + void write( cv::FileStorage &fs ) const; bool tilted; struct { - Rect r; + cv::Rect r; float weight; } rect[CV_HAAR_FEATURE_MAX]; @@ -64,10 +64,10 @@ protected: } fastRect[CV_HAAR_FEATURE_MAX]; }; - vector features; - Mat sum; /* sum images (each row represents image) */ - Mat tilted; /* tilted sum images (each row represents image) */ - Mat normfactor; /* normalization factor */ + std::vector features; + cv::Mat sum; /* sum images (each row represents image) */ + cv::Mat tilted; /* tilted sum images (each row represents image) */ + cv::Mat normfactor; /* normalization factor */ }; inline float CvHaarEvaluator::operator()(int featureIdx, int sampleIdx) const @@ -76,7 +76,7 @@ inline float CvHaarEvaluator::operator()(int featureIdx, int sampleIdx) const return !nf ? 0.0f : (features[featureIdx].calc( sum, tilted, sampleIdx)/nf); } -inline float CvHaarEvaluator::Feature::calc( const Mat &_sum, const Mat &_tilted, size_t y) const +inline float CvHaarEvaluator::Feature::calc( const cv::Mat &_sum, const cv::Mat &_tilted, size_t y) const { const int* img = tilted ? _tilted.ptr((int)y) : _sum.ptr((int)y); float ret = rect[0].weight * (img[fastRect[0].p0] - img[fastRect[0].p1] - img[fastRect[0].p2] + img[fastRect[0].p3] ) + diff --git a/apps/traincascade/imagestorage.cpp b/apps/traincascade/imagestorage.cpp index 0f749f9b01..394481b737 100644 --- a/apps/traincascade/imagestorage.cpp +++ b/apps/traincascade/imagestorage.cpp @@ -7,7 +7,10 @@ #include #include -bool CvCascadeImageReader::create( const String _posFilename, const String _negFilename, Size _winSize ) +using namespace std; +using namespace cv; + +bool CvCascadeImageReader::create( const string _posFilename, const string _negFilename, Size _winSize ) { return posReader.create(_posFilename) && negReader.create(_negFilename, _winSize); } @@ -22,21 +25,21 @@ CvCascadeImageReader::NegReader::NegReader() stepFactor = 0.5F; } -bool CvCascadeImageReader::NegReader::create( const String _filename, Size _winSize ) +bool CvCascadeImageReader::NegReader::create( const string _filename, Size _winSize ) { - String dirname, str; + string dirname, str; std::ifstream file(_filename.c_str()); if ( !file.is_open() ) return false; size_t pos = _filename.rfind('\\'); char dlmrt = '\\'; - if (pos == String::npos) + if (pos == string::npos) { pos = _filename.rfind('/'); dlmrt = '/'; } - dirname = pos == String::npos ? "" : _filename.substr(0, pos) + dlmrt; + dirname = pos == string::npos ? "" : _filename.substr(0, pos) + dlmrt; while( !file.eof() ) { std::getline(file, str); @@ -64,8 +67,8 @@ bool CvCascadeImageReader::NegReader::nextImg() round = round % (winSize.width * winSize.height); last %= count; - _offset.x = min( (int)round % winSize.width, src.cols - winSize.width ); - _offset.y = min( (int)round / winSize.width, src.rows - winSize.height ); + _offset.x = std::min( (int)round % winSize.width, src.cols - winSize.width ); + _offset.y = std::min( (int)round / winSize.width, src.rows - winSize.height ); if( !src.empty() && src.type() == CV_8UC1 && offset.x >= 0 && offset.y >= 0 ) break; @@ -126,7 +129,7 @@ CvCascadeImageReader::PosReader::PosReader() vec = 0; } -bool CvCascadeImageReader::PosReader::create( const String _filename ) +bool CvCascadeImageReader::PosReader::create( const string _filename ) { if ( file ) fclose( file ); diff --git a/apps/traincascade/imagestorage.h b/apps/traincascade/imagestorage.h index 91a4e5e87f..fb68e25cb2 100644 --- a/apps/traincascade/imagestorage.h +++ b/apps/traincascade/imagestorage.h @@ -3,15 +3,15 @@ #include "highgui.h" -using namespace cv; + class CvCascadeImageReader { public: - bool create( const String _posFilename, const String _negFilename, Size _winSize ); + bool create( const std::string _posFilename, const std::string _negFilename, cv::Size _winSize ); void restart() { posReader.restart(); } - bool getNeg(Mat &_img) { return negReader.get( _img ); } - bool getPos(Mat &_img) { return posReader.get( _img ); } + bool getNeg(cv::Mat &_img) { return negReader.get( _img ); } + bool getPos(cv::Mat &_img) { return posReader.get( _img ); } private: class PosReader @@ -19,8 +19,8 @@ private: public: PosReader(); virtual ~PosReader(); - bool create( const String _filename ); - bool get( Mat &_img ); + bool create( const std::string _filename ); + bool get( cv::Mat &_img ); void restart(); short* vec; @@ -35,18 +35,18 @@ private: { public: NegReader(); - bool create( const String _filename, Size _winSize ); - bool get( Mat& _img ); + bool create( const std::string _filename, cv::Size _winSize ); + bool get( cv::Mat& _img ); bool nextImg(); - Mat src, img; - vector imgFilenames; - Point offset, point; + cv::Mat src, img; + std::vector imgFilenames; + cv::Point offset, point; float scale; float scaleFactor; float stepFactor; size_t last, round; - Size winSize; + cv::Size winSize; } negReader; }; diff --git a/apps/traincascade/lbpfeatures.cpp b/apps/traincascade/lbpfeatures.cpp index cf9bb7b245..522d90a3c1 100644 --- a/apps/traincascade/lbpfeatures.cpp +++ b/apps/traincascade/lbpfeatures.cpp @@ -4,6 +4,8 @@ #include "lbpfeatures.h" #include "cascadeclassifier.h" +using namespace cv; + CvLBPFeatureParams::CvLBPFeatureParams() { maxCatCount = 256; diff --git a/apps/traincascade/lbpfeatures.h b/apps/traincascade/lbpfeatures.h index 30c35374d3..3e36a5887a 100644 --- a/apps/traincascade/lbpfeatures.h +++ b/apps/traincascade/lbpfeatures.h @@ -15,11 +15,11 @@ class CvLBPEvaluator : public CvFeatureEvaluator public: virtual ~CvLBPEvaluator() {} virtual void init(const CvFeatureParams *_featureParams, - int _maxSampleCount, Size _winSize ); - virtual void setImage(const Mat& img, uchar clsLabel, int idx); + int _maxSampleCount, cv::Size _winSize ); + virtual void setImage(const cv::Mat& img, uchar clsLabel, int idx); virtual float operator()(int featureIdx, int sampleIdx) const { return (float)features[featureIdx].calc( sum, sampleIdx); } - virtual void writeFeatures( FileStorage &fs, const Mat& featureMap ) const; + virtual void writeFeatures( cv::FileStorage &fs, const cv::Mat& featureMap ) const; protected: virtual void generateFeatures(); @@ -28,18 +28,18 @@ protected: public: Feature(); Feature( int offset, int x, int y, int _block_w, int _block_h ); - uchar calc( const Mat& _sum, size_t y ) const; - void write( FileStorage &fs ) const; + uchar calc( const cv::Mat& _sum, size_t y ) const; + void write( cv::FileStorage &fs ) const; - Rect rect; + cv::Rect rect; int p[16]; }; - vector features; + std::vector features; - Mat sum; + cv::Mat sum; }; -inline uchar CvLBPEvaluator::Feature::calc(const Mat &_sum, size_t y) const +inline uchar CvLBPEvaluator::Feature::calc(const cv::Mat &_sum, size_t y) const { const int* psum = _sum.ptr((int)y); int cval = psum[p[5]] - psum[p[6]] - psum[p[9]] + psum[p[10]]; diff --git a/apps/traincascade/traincascade.cpp b/apps/traincascade/traincascade.cpp index 5a969f434a..c051d3f650 100644 --- a/apps/traincascade/traincascade.cpp +++ b/apps/traincascade/traincascade.cpp @@ -5,11 +5,12 @@ #include "cascadeclassifier.h" using namespace std; +using namespace cv; int main( int argc, char* argv[] ) { CvCascadeClassifier classifier; - String cascadeDirName, vecName, bgName; + string cascadeDirName, vecName, bgName; int numPos = 2000; int numNeg = 1000; int numStages = 20; diff --git a/apps/traincascade/traincascade_features.h b/apps/traincascade/traincascade_features.h index 019a4b9b37..dfba7a3d43 100644 --- a/apps/traincascade/traincascade_features.h +++ b/apps/traincascade/traincascade_features.h @@ -30,13 +30,13 @@ (p3) = (rect).x + (rect).width - (rect).height \ + (step) * ((rect).y + (rect).width + (rect).height); -float calcNormFactor( const Mat& sum, const Mat& sqSum ); +float calcNormFactor( const cv::Mat& sum, const cv::Mat& sqSum ); template -void _writeFeatures( const vector features, FileStorage &fs, const Mat& featureMap ) +void _writeFeatures( const std::vector features, cv::FileStorage &fs, const cv::Mat& featureMap ) { fs << FEATURES << "["; - const Mat_& featureMap_ = (const Mat_&)featureMap; + const cv::Mat_& featureMap_ = (const cv::Mat_&)featureMap; for ( int fi = 0; fi < featureMap.cols; fi++ ) if ( featureMap_(0, fi) >= 0 ) { @@ -53,13 +53,13 @@ public: CvParams(); virtual ~CvParams() {} // from|to file - virtual void write( FileStorage &fs ) const = 0; - virtual bool read( const FileNode &node ) = 0; + virtual void write( cv::FileStorage &fs ) const = 0; + virtual bool read( const cv::FileNode &node ) = 0; // from|to screen virtual void printDefaults() const; virtual void printAttrs() const; - virtual bool scanAttr( const String prmName, const String val ); - String name; + virtual bool scanAttr( const std::string prmName, const std::string val ); + std::string name; }; class CvFeatureParams : public CvParams @@ -68,9 +68,9 @@ public: enum { HAAR = 0, LBP = 1, HOG = 2 }; CvFeatureParams(); virtual void init( const CvFeatureParams& fp ); - virtual void write( FileStorage &fs ) const; - virtual bool read( const FileNode &node ); - static Ptr create( int featureType ); + virtual void write( cv::FileStorage &fs ) const; + virtual bool read( const cv::FileNode &node ); + static cv::Ptr create( int featureType ); int maxCatCount; // 0 in case of numerical features int featSize; // 1 in case of simple features (HAAR, LBP) and N_BINS(9)*N_CELLS(4) in case of Dalal's HOG features }; @@ -80,25 +80,25 @@ class CvFeatureEvaluator public: virtual ~CvFeatureEvaluator() {} virtual void init(const CvFeatureParams *_featureParams, - int _maxSampleCount, Size _winSize ); - virtual void setImage(const Mat& img, uchar clsLabel, int idx); - virtual void writeFeatures( FileStorage &fs, const Mat& featureMap ) const = 0; + int _maxSampleCount, cv::Size _winSize ); + virtual void setImage(const cv::Mat& img, uchar clsLabel, int idx); + virtual void writeFeatures( cv::FileStorage &fs, const cv::Mat& featureMap ) const = 0; virtual float operator()(int featureIdx, int sampleIdx) const = 0; - static Ptr create(int type); + static cv::Ptr create(int type); int getNumFeatures() const { return numFeatures; } int getMaxCatCount() const { return featureParams->maxCatCount; } int getFeatureSize() const { return featureParams->featSize; } - const Mat& getCls() const { return cls; } + const cv::Mat& getCls() const { return cls; } float getCls(int si) const { return cls.at(si, 0); } protected: virtual void generateFeatures() = 0; int npos, nneg; int numFeatures; - Size winSize; + cv::Size winSize; CvFeatureParams *featureParams; - Mat cls; + cv::Mat cls; }; #endif