Remove all using directives for STL namespace and members

Made all STL usages explicit to be able automatically find all usages of
particular class or function.

(cherry picked from commit 2a6fb2867e2fc639e0675eed8abb1688de4539ec)
(only cherry picked "apps/trancascade")
This commit is contained in:
Andrey Kamaev 2013-02-24 20:14:01 +04:00 committed by Leszek Swirski
parent d45ce086c1
commit bef34093aa
14 changed files with 56 additions and 53 deletions

View File

@ -4,6 +4,7 @@
#include "HOGfeatures.h" #include "HOGfeatures.h"
#include "cascadeclassifier.h" #include "cascadeclassifier.h"
using namespace std;
CvHOGFeatureParams::CvHOGFeatureParams() CvHOGFeatureParams::CvHOGFeatureParams()
{ {

View File

@ -26,13 +26,13 @@ public:
virtual void writeFeatures( FileStorage &fs, const Mat& featureMap ) const; virtual void writeFeatures( FileStorage &fs, const Mat& featureMap ) const;
protected: protected:
virtual void generateFeatures(); virtual void generateFeatures();
virtual void integralHistogram(const Mat &img, vector<Mat> &histogram, Mat &norm, int nbins) const; virtual void integralHistogram(const Mat &img, std::vector<Mat> &histogram, Mat &norm, int nbins) const;
class Feature class Feature
{ {
public: public:
Feature(); Feature();
Feature( int offset, int x, int y, int cellW, int cellH ); Feature( int offset, int x, int y, int cellW, int cellH );
float calc( const vector<Mat> &_hists, const Mat &_normSum, size_t y, int featComponent ) const; float calc( const std::vector<Mat> &_hists, const Mat &_normSum, size_t y, int featComponent ) const;
void write( FileStorage &fs ) const; void write( FileStorage &fs ) const;
void write( FileStorage &fs, int varIdx ) const; void write( FileStorage &fs, int varIdx ) const;
@ -43,10 +43,10 @@ protected:
int p0, p1, p2, p3; int p0, p1, p2, p3;
} fastRect[N_CELLS]; } fastRect[N_CELLS];
}; };
vector<Feature> features; std::vector<Feature> features;
Mat normSum; //for nomalization calculation (L1 or L2) Mat normSum; //for nomalization calculation (L1 or L2)
vector<Mat> hist; std::vector<Mat> hist;
}; };
inline float CvHOGEvaluator::operator()(int varIdx, int sampleIdx) const 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); return features[featureIdx].calc( hist, normSum, sampleIdx, componentIdx);
} }
inline float CvHOGEvaluator::Feature::calc( const vector<Mat>& _hists, const Mat& _normSum, size_t y, int featComponent ) const inline float CvHOGEvaluator::Feature::calc( const std::vector<Mat>& _hists, const Mat& _normSum, size_t y, int featComponent ) const
{ {
float normFactor; float normFactor;
float res; float res;

View File

@ -160,10 +160,10 @@ CvCascadeBoostParams::CvCascadeBoostParams( int _boostType,
void CvCascadeBoostParams::write( FileStorage &fs ) const 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::REAL ? CC_REAL_BOOST :
boost_type == CvBoost::LOGIT ? CC_LOGIT_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() ); CV_Assert( !boostTypeStr.empty() );
fs << CC_BOOST_TYPE << boostTypeStr; fs << CC_BOOST_TYPE << boostTypeStr;
fs << CC_MINHITRATE << minHitRate; fs << CC_MINHITRATE << minHitRate;
@ -175,7 +175,7 @@ void CvCascadeBoostParams::write( FileStorage &fs ) const
bool CvCascadeBoostParams::read( const FileNode &node ) bool CvCascadeBoostParams::read( const FileNode &node )
{ {
String boostTypeStr; string boostTypeStr;
FileNode rnode = node[CC_BOOST_TYPE]; FileNode rnode = node[CC_BOOST_TYPE];
rnode >> boostTypeStr; rnode >> boostTypeStr;
boost_type = !boostTypeStr.compare( CC_DISCRETE_BOOST ) ? CvBoost::DISCRETE : boost_type = !boostTypeStr.compare( CC_DISCRETE_BOOST ) ? CvBoost::DISCRETE :
@ -213,10 +213,10 @@ void CvCascadeBoostParams::printDefaults() const
void CvCascadeBoostParams::printAttrs() 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::REAL ? CC_REAL_BOOST :
boost_type == CvBoost::LOGIT ? CC_LOGIT_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() ); CV_Assert( !boostTypeStr.empty() );
cout << "boostType: " << boostTypeStr << endl; cout << "boostType: " << boostTypeStr << endl;
cout << "minHitRate: " << minHitRate << endl; cout << "minHitRate: " << minHitRate << endl;
@ -226,7 +226,7 @@ void CvCascadeBoostParams::printAttrs() const
cout << "maxWeakCount: " << weak_count << endl; 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; bool res = true;

View File

@ -17,7 +17,7 @@ struct CvCascadeBoostParams : CvBoostParams
bool read( const FileNode &node ); bool read( const FileNode &node );
virtual void printDefaults() const; virtual void printDefaults() const;
virtual void printAttrs() 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 struct CvCascadeBoostTrainData : CvDTreeTrainData

View File

@ -24,10 +24,10 @@ CvCascadeParams::CvCascadeParams( int _stageType, int _featureType ) : stageType
void CvCascadeParams::write( FileStorage &fs ) const void CvCascadeParams::write( FileStorage &fs ) const
{ {
String stageTypeStr = stageType == BOOST ? CC_BOOST : String(); string stageTypeStr = stageType == BOOST ? CC_BOOST : string();
CV_Assert( !stageTypeStr.empty() ); CV_Assert( !stageTypeStr.empty() );
fs << CC_STAGE_TYPE << stageTypeStr; 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::LBP ? CC_LBP :
featureType == CvFeatureParams::HOG ? CC_HOG : featureType == CvFeatureParams::HOG ? CC_HOG :
0; 0;
@ -41,7 +41,7 @@ bool CvCascadeParams::read( const FileNode &node )
{ {
if ( node.empty() ) if ( node.empty() )
return false; return false;
String stageTypeStr, featureTypeStr; string stageTypeStr, featureTypeStr;
FileNode rnode = node[CC_STAGE_TYPE]; FileNode rnode = node[CC_STAGE_TYPE];
if ( !rnode.isString() ) if ( !rnode.isString() )
return false; return false;
@ -96,7 +96,7 @@ void CvCascadeParams::printAttrs() const
cout << "sampleHeight: " << winSize.height << endl; 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; bool res = true;
if( !prmName.compare( "-stageType" ) ) if( !prmName.compare( "-stageType" ) )
@ -126,9 +126,9 @@ bool CvCascadeParams::scanAttr( const String prmName, const String val )
//---------------------------- CascadeClassifier -------------------------------------- //---------------------------- CascadeClassifier --------------------------------------
bool CvCascadeClassifier::train( const String _cascadeDirName, bool CvCascadeClassifier::train( const string _cascadeDirName,
const String _posFilename, const string _posFilename,
const String _negFilename, const string _negFilename,
int _numPos, int _numNeg, int _numPos, int _numNeg,
int _precalcValBufSize, int _precalcIdxBufSize, int _precalcValBufSize, int _precalcIdxBufSize,
int _numStages, int _numStages,
@ -399,7 +399,7 @@ bool CvCascadeClassifier::readStages( const FileNode &node)
#define ICV_HAAR_PARENT_NAME "parent" #define ICV_HAAR_PARENT_NAME "parent"
#define ICV_HAAR_NEXT_NAME "next" #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 ); FileStorage fs( filename, FileStorage::WRITE );
@ -491,7 +491,7 @@ void CvCascadeClassifier::save( const String filename, bool baseFormat )
fs << "}"; fs << "}";
} }
bool CvCascadeClassifier::load( const String cascadeDirName ) bool CvCascadeClassifier::load( const string cascadeDirName )
{ {
FileStorage fs( cascadeDirName + CC_PARAMS_FILENAME, FileStorage::READ ); FileStorage fs( cascadeDirName + CC_PARAMS_FILENAME, FileStorage::READ );
if ( !fs.isOpened() ) if ( !fs.isOpened() )

View File

@ -77,7 +77,7 @@ public:
void printDefaults() const; void printDefaults() const;
void printAttrs() 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 stageType;
int featureType; int featureType;
@ -87,9 +87,9 @@ public:
class CvCascadeClassifier class CvCascadeClassifier
{ {
public: public:
bool train( const String _cascadeDirName, bool train( const std::string _cascadeDirName,
const String _posFilename, const std::string _posFilename,
const String _negFilename, const std::string _negFilename,
int _numPos, int _numNeg, int _numPos, int _numNeg,
int _precalcValBufSize, int _precalcIdxBufSize, int _precalcValBufSize, int _precalcIdxBufSize,
int _numStages, int _numStages,
@ -99,8 +99,8 @@ public:
bool baseFormatSave = false ); bool baseFormatSave = false );
private: private:
int predict( int sampleIdx ); int predict( int sampleIdx );
void save( const String cascadeDirName, bool baseFormat = false ); void save( const std::string cascadeDirName, bool baseFormat = false );
bool load( const String cascadeDirName ); bool load( const std::string cascadeDirName );
bool updateTrainingSet( double& acceptanceRatio ); bool updateTrainingSet( double& acceptanceRatio );
int fillPassedSamples( int first, int count, bool isPositive, int64& consumed ); int fillPassedSamples( int first, int count, bool isPositive, int64& consumed );
@ -117,7 +117,7 @@ private:
Ptr<CvCascadeBoostParams> stageParams; Ptr<CvCascadeBoostParams> stageParams;
Ptr<CvFeatureEvaluator> featureEvaluator; Ptr<CvFeatureEvaluator> featureEvaluator;
vector< Ptr<CvCascadeBoost> > stageClassifiers; std::vector< Ptr<CvCascadeBoost> > stageClassifiers;
CvCascadeImageReader imgReader; CvCascadeImageReader imgReader;
int numStages, curNumSamples; int numStages, curNumSamples;
int numPos, numNeg; int numPos, numNeg;

View File

@ -24,7 +24,7 @@ CvParams::CvParams() : name( "params" ) {}
void CvParams::printDefaults() const void CvParams::printDefaults() const
{ cout << "--" << name << "--" << endl; } { cout << "--" << name << "--" << endl; }
void CvParams::printAttrs() const {} void CvParams::printAttrs() const {}
bool CvParams::scanAttr( const String, const String ) { return false; } bool CvParams::scanAttr( const string, const string ) { return false; }
//---------------------------- FeatureParams -------------------------------------- //---------------------------- FeatureParams --------------------------------------

View File

@ -25,9 +25,9 @@ void CvHaarFeatureParams::init( const CvFeatureParams& fp )
void CvHaarFeatureParams::write( FileStorage &fs ) const void CvHaarFeatureParams::write( FileStorage &fs ) const
{ {
CvFeatureParams::write( fs ); CvFeatureParams::write( fs );
String modeStr = mode == BASIC ? CC_MODE_BASIC : string modeStr = mode == BASIC ? CC_MODE_BASIC :
mode == CORE ? CC_MODE_CORE : mode == CORE ? CC_MODE_CORE :
mode == ALL ? CC_MODE_ALL : String(); mode == ALL ? CC_MODE_ALL : string();
CV_Assert( !modeStr.empty() ); CV_Assert( !modeStr.empty() );
fs << CC_MODE << modeStr; fs << CC_MODE << modeStr;
} }
@ -40,7 +40,7 @@ bool CvHaarFeatureParams::read( const FileNode &node )
FileNode rnode = node[CC_MODE]; FileNode rnode = node[CC_MODE];
if( !rnode.isString() ) if( !rnode.isString() )
return false; return false;
String modeStr; string modeStr;
rnode >> modeStr; rnode >> modeStr;
mode = !modeStr.compare( CC_MODE_BASIC ) ? BASIC : mode = !modeStr.compare( CC_MODE_BASIC ) ? BASIC :
!modeStr.compare( CC_MODE_CORE ) ? CORE : !modeStr.compare( CC_MODE_CORE ) ? CORE :
@ -58,13 +58,13 @@ void CvHaarFeatureParams::printDefaults() const
void CvHaarFeatureParams::printAttrs() const void CvHaarFeatureParams::printAttrs() const
{ {
CvFeatureParams::printAttrs(); CvFeatureParams::printAttrs();
String mode_str = mode == BASIC ? CC_MODE_BASIC : string mode_str = mode == BASIC ? CC_MODE_BASIC :
mode == CORE ? CC_MODE_CORE : mode == CORE ? CC_MODE_CORE :
mode == ALL ? CC_MODE_ALL : 0; mode == ALL ? CC_MODE_ALL : 0;
cout << "mode: " << mode_str << endl; 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 ) ) if ( !CvFeatureParams::scanAttr( prmName, val ) )
{ {

View File

@ -23,7 +23,7 @@ public:
virtual void printDefaults() const; virtual void printDefaults() const;
virtual void printAttrs() 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; int mode;
}; };
@ -64,7 +64,7 @@ protected:
} fastRect[CV_HAAR_FEATURE_MAX]; } fastRect[CV_HAAR_FEATURE_MAX];
}; };
vector<Feature> features; std::vector<Feature> features;
Mat sum; /* sum images (each row represents image) */ Mat sum; /* sum images (each row represents image) */
Mat tilted; /* tilted sum images (each row represents image) */ Mat tilted; /* tilted sum images (each row represents image) */
Mat normfactor; /* normalization factor */ Mat normfactor; /* normalization factor */

View File

@ -7,7 +7,9 @@
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
bool CvCascadeImageReader::create( const String _posFilename, const String _negFilename, Size _winSize ) using namespace std;
bool CvCascadeImageReader::create( const string _posFilename, const string _negFilename, Size _winSize )
{ {
return posReader.create(_posFilename) && negReader.create(_negFilename, _winSize); return posReader.create(_posFilename) && negReader.create(_negFilename, _winSize);
} }
@ -22,21 +24,21 @@ CvCascadeImageReader::NegReader::NegReader()
stepFactor = 0.5F; 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()); std::ifstream file(_filename.c_str());
if ( !file.is_open() ) if ( !file.is_open() )
return false; return false;
size_t pos = _filename.rfind('\\'); size_t pos = _filename.rfind('\\');
char dlmrt = '\\'; char dlmrt = '\\';
if (pos == String::npos) if (pos == string::npos)
{ {
pos = _filename.rfind('/'); pos = _filename.rfind('/');
dlmrt = '/'; dlmrt = '/';
} }
dirname = pos == String::npos ? "" : _filename.substr(0, pos) + dlmrt; dirname = pos == string::npos ? "" : _filename.substr(0, pos) + dlmrt;
while( !file.eof() ) while( !file.eof() )
{ {
std::getline(file, str); std::getline(file, str);
@ -64,8 +66,8 @@ bool CvCascadeImageReader::NegReader::nextImg()
round = round % (winSize.width * winSize.height); round = round % (winSize.width * winSize.height);
last %= count; last %= count;
_offset.x = min( (int)round % winSize.width, src.cols - winSize.width ); _offset.x = std::min( (int)round % winSize.width, src.cols - winSize.width );
_offset.y = min( (int)round / winSize.width, src.rows - winSize.height ); _offset.y = std::min( (int)round / winSize.width, src.rows - winSize.height );
if( !src.empty() && src.type() == CV_8UC1 if( !src.empty() && src.type() == CV_8UC1
&& offset.x >= 0 && offset.y >= 0 ) && offset.x >= 0 && offset.y >= 0 )
break; break;
@ -126,7 +128,7 @@ CvCascadeImageReader::PosReader::PosReader()
vec = 0; vec = 0;
} }
bool CvCascadeImageReader::PosReader::create( const String _filename ) bool CvCascadeImageReader::PosReader::create( const string _filename )
{ {
if ( file ) if ( file )
fclose( file ); fclose( file );

View File

@ -8,7 +8,7 @@ using namespace cv;
class CvCascadeImageReader class CvCascadeImageReader
{ {
public: public:
bool create( const String _posFilename, const String _negFilename, Size _winSize ); bool create( const std::string _posFilename, const std::string _negFilename, Size _winSize );
void restart() { posReader.restart(); } void restart() { posReader.restart(); }
bool getNeg(Mat &_img) { return negReader.get( _img ); } bool getNeg(Mat &_img) { return negReader.get( _img ); }
bool getPos(Mat &_img) { return posReader.get( _img ); } bool getPos(Mat &_img) { return posReader.get( _img ); }
@ -19,7 +19,7 @@ private:
public: public:
PosReader(); PosReader();
virtual ~PosReader(); virtual ~PosReader();
bool create( const String _filename ); bool create( const std::string _filename );
bool get( Mat &_img ); bool get( Mat &_img );
void restart(); void restart();
@ -35,12 +35,12 @@ private:
{ {
public: public:
NegReader(); NegReader();
bool create( const String _filename, Size _winSize ); bool create( const std::string _filename, Size _winSize );
bool get( Mat& _img ); bool get( Mat& _img );
bool nextImg(); bool nextImg();
Mat src, img; Mat src, img;
vector<String> imgFilenames; std::vector<std::string> imgFilenames;
Point offset, point; Point offset, point;
float scale; float scale;
float scaleFactor; float scaleFactor;

View File

@ -34,7 +34,7 @@ protected:
Rect rect; Rect rect;
int p[16]; int p[16];
}; };
vector<Feature> features; std::vector<Feature> features;
Mat sum; Mat sum;
}; };

View File

@ -9,7 +9,7 @@ using namespace std;
int main( int argc, char* argv[] ) int main( int argc, char* argv[] )
{ {
CvCascadeClassifier classifier; CvCascadeClassifier classifier;
String cascadeDirName, vecName, bgName; string cascadeDirName, vecName, bgName;
int numPos = 2000; int numPos = 2000;
int numNeg = 1000; int numNeg = 1000;
int numStages = 20; int numStages = 20;

View File

@ -33,7 +33,7 @@
float calcNormFactor( const Mat& sum, const Mat& sqSum ); float calcNormFactor( const Mat& sum, const Mat& sqSum );
template<class Feature> template<class Feature>
void _writeFeatures( const vector<Feature> features, FileStorage &fs, const Mat& featureMap ) void _writeFeatures( const std::vector<Feature> features, FileStorage &fs, const Mat& featureMap )
{ {
fs << FEATURES << "["; fs << FEATURES << "[";
const Mat_<int>& featureMap_ = (const Mat_<int>&)featureMap; const Mat_<int>& featureMap_ = (const Mat_<int>&)featureMap;
@ -58,8 +58,8 @@ public:
// from|to screen // from|to screen
virtual void printDefaults() const; virtual void printDefaults() const;
virtual void printAttrs() 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 );
String name; std::string name;
}; };
class CvFeatureParams : public CvParams class CvFeatureParams : public CvParams