Commit 18039d78 authored by Vadim Pisarevsky's avatar Vadim Pisarevsky

added test for the old cvHaarDetectObjects. disabled AVX optimization in…

added test for the old cvHaarDetectObjects. disabled AVX optimization in haar.cpp. it should cover tickets #2534, #2591, #2669
parent a8c014de
......@@ -52,7 +52,7 @@
# endif
#endif
#if CV_AVX
#if 0 /*CV_AVX*/
# define CV_HAAR_USE_AVX 1
# if defined _MSC_VER
# pragma warning( disable : 4752 )
......
......@@ -87,11 +87,15 @@ protected:
vector<string> imageFilenames;
vector<Mat> images;
string validationFilename;
string configFilename;
FileStorage validationFS;
bool write_results;
};
CV_DetectorTest::CV_DetectorTest()
{
configFilename = "dummy";
write_results = false;
}
string& CV_DetectorTest::getValidationFilename()
......@@ -146,25 +150,37 @@ int CV_DetectorTest::prepareData( FileStorage& _fs )
void CV_DetectorTest::run( int )
{
string dataPath = ts->get_data_path();
validationFS.open( dataPath + getValidationFilename(), FileStorage::READ );
int code = prepareData( validationFS );
string vs_filename = dataPath + getValidationFilename();
write_results = !validationFS.open( vs_filename, FileStorage::READ );
int code;
if( !write_results )
{
code = prepareData( validationFS );
}
else
{
FileStorage fs0(dataPath + configFilename, FileStorage::READ );
code = prepareData(fs0);
}
if( code < 0 )
{
ts->set_failed_test_info( code );
return;
}
#ifdef GET_STAT
if( write_results )
{
validationFS.release();
string filename = ts->get_data_path();
filename += getValidationFilename();
validationFS.open( filename, FileStorage::WRITE );
validationFS.open( vs_filename, FileStorage::WRITE );
validationFS << FileStorage::getDefaultObjectName(validationFilename) << "{";
validationFS << DIST_E << eps.dist;
validationFS << S_E << eps.s;
validationFS << NO_PAIR_E << eps.noPair;
// validationFS << TOTAL_NO_PAIR_E << eps.totalNoPair;
// validationFS << TOTAL_NO_PAIR_E << eps.totalNoPair;
// write detector names
validationFS << DETECTOR_NAMES << "[";
......@@ -179,7 +195,7 @@ void CV_DetectorTest::run( int )
validationFS << DETECTORS << "{";
assert( detectorNames.size() == detectorFilenames.size() );
nit = detectorNames.begin();
for( int di = 0; di < detectorNames.size(), nit != detectorNames.end(); ++nit, di++ )
for( int di = 0; di < detectorNames.size(); ++nit, di++ )
{
validationFS << *nit << "{";
writeDetector( validationFS, di );
......@@ -200,32 +216,33 @@ void CV_DetectorTest::run( int )
validationFS << "]"; // IMAGE_FILENAMES
validationFS << VALIDATION << "{";
#endif
}
int progress = 0;
for( int di = 0; di < test_case_count; di++ )
{
progress = update_progress( progress, di, test_case_count, 0 );
#ifdef GET_STAT
if( write_results )
validationFS << detectorNames[di] << "{";
#endif
vector<vector<Rect> > objects;
int temp_code = runTestCase( di, objects );
#ifndef GET_STAT
if (temp_code == cvtest::TS::OK)
if (!write_results && temp_code == cvtest::TS::OK)
temp_code = validate( di, objects );
#endif
if (temp_code != cvtest::TS::OK)
code = temp_code;
#ifdef GET_STAT
if( write_results )
validationFS << "}"; // detectorNames[di]
#endif
}
#ifdef GET_STAT
if( write_results )
{
validationFS << "}"; // VALIDATION
validationFS << "}"; // getDefaultObjectName
#endif
}
if ( test_case_count <= 0 || imageFilenames.size() <= 0 )
{
ts->printf( cvtest::TS::LOG, "validation file is not determined or not correct" );
......@@ -257,7 +274,8 @@ int CV_DetectorTest::runTestCase( int detectorIdx, vector<vector<Rect> >& object
objects.push_back( imgObjects );
#ifdef GET_STAT
if( write_results )
{
char buf[10];
sprintf( buf, "%s%d", "img_", ii );
string imageIdxStr = buf;
......@@ -268,7 +286,7 @@ int CV_DetectorTest::runTestCase( int detectorIdx, vector<vector<Rect> >& object
validationFS << it->x << it->y << it->width << it->height;
}
validationFS << "]"; // imageIdxStr
#endif
}
}
return cvtest::TS::OK;
}
......@@ -374,12 +392,14 @@ protected:
virtual void readDetector( const FileNode& fn );
virtual void writeDetector( FileStorage& fs, int di );
virtual int detectMultiScale( int di, const Mat& img, vector<Rect>& objects );
virtual int detectMultiScale_C( const string& filename, int di, const Mat& img, vector<Rect>& objects );
vector<int> flags;
};
CV_CascadeDetectorTest::CV_CascadeDetectorTest()
{
validationFilename = "cascadeandhog/cascade.xml";
configFilename = "cascadeandhog/_cascade.xml";
}
void CV_CascadeDetectorTest::readDetector( const FileNode& fn )
......@@ -402,11 +422,48 @@ void CV_CascadeDetectorTest::writeDetector( FileStorage& fs, int di )
fs << C_SCALE_CASCADE << sc;
}
int CV_CascadeDetectorTest::detectMultiScale_C( const string& filename,
int di, const Mat& img,
vector<Rect>& objects )
{
Ptr<CvHaarClassifierCascade> c_cascade = cvLoadHaarClassifierCascade(filename.c_str(), cvSize(0,0));
Ptr<CvMemStorage> storage = cvCreateMemStorage();
if( c_cascade.empty() )
{
ts->printf( cvtest::TS::LOG, "cascade %s can not be opened");
return cvtest::TS::FAIL_INVALID_TEST_DATA;
}
Mat grayImg;
cvtColor( img, grayImg, CV_BGR2GRAY );
equalizeHist( grayImg, grayImg );
CvMat c_gray = grayImg;
CvSeq* rs = cvHaarDetectObjects(&c_gray, c_cascade, storage, 1.1, 3, flags[di] );
objects.clear();
for( int i = 0; i < rs->total; i++ )
{
Rect r = *(Rect*)cvGetSeqElem(rs, i);
objects.push_back(r);
}
return cvtest::TS::OK;
}
int CV_CascadeDetectorTest::detectMultiScale( int di, const Mat& img,
vector<Rect>& objects)
{
string dataPath = ts->get_data_path(), filename;
filename = dataPath + detectorFilenames[di];
const string pattern = "haarcascade_frontalface_default.xml";
if( filename.size() >= pattern.size() &&
strcmp(filename.c_str() + (filename.size() - pattern.size()),
pattern.c_str()) == 0 )
return detectMultiScale_C(filename, di, img, objects);
CascadeClassifier cascade( filename );
if( cascade.empty() )
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment