#include "HOGfeatures.h"
#include "cascadeclassifier.h"
+using namespace std;
CvHOGFeatureParams::CvHOGFeatureParams()
{
virtual void writeFeatures( FileStorage &fs, const Mat& featureMap ) const;
protected:
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
{
public:
Feature();
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, int varIdx ) const;
int p0, p1, p2, p3;
} fastRect[N_CELLS];
};
- vector<Feature> features;
+ std::vector<Feature> features;
Mat normSum; //for nomalization calculation (L1 or L2)
- vector<Mat> hist;
+ std::vector<Mat> hist;
};
inline float CvHOGEvaluator::operator()(int varIdx, int sampleIdx) const
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 res;
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;
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 :
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;
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 read( const 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
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;
{
if ( node.empty() )
return false;
- String stageTypeStr, featureTypeStr;
+ string stageTypeStr, featureTypeStr;
FileNode rnode = node[CC_STAGE_TYPE];
if ( !rnode.isString() )
return false;
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" ) )
//---------------------------- 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,
#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 );
fs << "}";
}
-bool CvCascadeClassifier::load( const String cascadeDirName )
+bool CvCascadeClassifier::load( const string cascadeDirName )
{
FileStorage fs( cascadeDirName + CC_PARAMS_FILENAME, FileStorage::READ );
if ( !fs.isOpened() )
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;
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,
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 );
Ptr<CvCascadeBoostParams> stageParams;
Ptr<CvFeatureEvaluator> featureEvaluator;
- vector< Ptr<CvCascadeBoost> > stageClassifiers;
+ std::vector< Ptr<CvCascadeBoost> > stageClassifiers;
CvCascadeImageReader imgReader;
int numStages, curNumSamples;
int numPos, numNeg;
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 --------------------------------------
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;
}
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 :
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 ) )
{
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;
};
} fastRect[CV_HAAR_FEATURE_MAX];
};
- vector<Feature> features;
+ std::vector<Feature> features;
Mat sum; /* sum images (each row represents image) */
Mat tilted; /* tilted sum images (each row represents image) */
Mat normfactor; /* normalization factor */
#include <iostream>
#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);
}
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);
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;
vec = 0;
}
-bool CvCascadeImageReader::PosReader::create( const String _filename )
+bool CvCascadeImageReader::PosReader::create( const string _filename )
{
if ( file )
fclose( file );
class CvCascadeImageReader
{
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(); }
bool getNeg(Mat &_img) { return negReader.get( _img ); }
bool getPos(Mat &_img) { return posReader.get( _img ); }
public:
PosReader();
virtual ~PosReader();
- bool create( const String _filename );
+ bool create( const std::string _filename );
bool get( Mat &_img );
void restart();
{
public:
NegReader();
- bool create( const String _filename, Size _winSize );
+ bool create( const std::string _filename, Size _winSize );
bool get( Mat& _img );
bool nextImg();
Mat src, img;
- vector<String> imgFilenames;
+ std::vector<std::string> imgFilenames;
Point offset, point;
float scale;
float scaleFactor;
Rect rect;
int p[16];
};
- vector<Feature> features;
+ std::vector<Feature> features;
Mat sum;
};
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;
float calcNormFactor( const Mat& sum, const Mat& sqSum );
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 << "[";
const Mat_<int>& featureMap_ = (const Mat_<int>&)featureMap;
// 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