added test for the old cvHaarDetectObjects. disabled AVX optimization in haar.cpp. it should cover tickets #2534, #2591, #2669
This commit is contained in:
@@ -52,7 +52,7 @@
|
|||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if CV_AVX
|
#if 0 /*CV_AVX*/
|
||||||
# define CV_HAAR_USE_AVX 1
|
# define CV_HAAR_USE_AVX 1
|
||||||
# if defined _MSC_VER
|
# if defined _MSC_VER
|
||||||
# pragma warning( disable : 4752 )
|
# pragma warning( disable : 4752 )
|
||||||
|
@@ -87,11 +87,15 @@ protected:
|
|||||||
vector<string> imageFilenames;
|
vector<string> imageFilenames;
|
||||||
vector<Mat> images;
|
vector<Mat> images;
|
||||||
string validationFilename;
|
string validationFilename;
|
||||||
|
string configFilename;
|
||||||
FileStorage validationFS;
|
FileStorage validationFS;
|
||||||
|
bool write_results;
|
||||||
};
|
};
|
||||||
|
|
||||||
CV_DetectorTest::CV_DetectorTest()
|
CV_DetectorTest::CV_DetectorTest()
|
||||||
{
|
{
|
||||||
|
configFilename = "dummy";
|
||||||
|
write_results = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
string& CV_DetectorTest::getValidationFilename()
|
string& CV_DetectorTest::getValidationFilename()
|
||||||
@@ -146,19 +150,31 @@ int CV_DetectorTest::prepareData( FileStorage& _fs )
|
|||||||
void CV_DetectorTest::run( int )
|
void CV_DetectorTest::run( int )
|
||||||
{
|
{
|
||||||
string dataPath = ts->get_data_path();
|
string dataPath = ts->get_data_path();
|
||||||
validationFS.open( dataPath + getValidationFilename(), FileStorage::READ );
|
string vs_filename = dataPath + getValidationFilename();
|
||||||
int code = prepareData( validationFS );
|
|
||||||
|
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 )
|
if( code < 0 )
|
||||||
{
|
{
|
||||||
ts->set_failed_test_info( code );
|
ts->set_failed_test_info( code );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef GET_STAT
|
if( write_results )
|
||||||
|
{
|
||||||
validationFS.release();
|
validationFS.release();
|
||||||
string filename = ts->get_data_path();
|
validationFS.open( vs_filename, FileStorage::WRITE );
|
||||||
filename += getValidationFilename();
|
|
||||||
validationFS.open( filename, FileStorage::WRITE );
|
|
||||||
validationFS << FileStorage::getDefaultObjectName(validationFilename) << "{";
|
validationFS << FileStorage::getDefaultObjectName(validationFilename) << "{";
|
||||||
|
|
||||||
validationFS << DIST_E << eps.dist;
|
validationFS << DIST_E << eps.dist;
|
||||||
@@ -179,7 +195,7 @@ void CV_DetectorTest::run( int )
|
|||||||
validationFS << DETECTORS << "{";
|
validationFS << DETECTORS << "{";
|
||||||
assert( detectorNames.size() == detectorFilenames.size() );
|
assert( detectorNames.size() == detectorFilenames.size() );
|
||||||
nit = detectorNames.begin();
|
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 << "{";
|
validationFS << *nit << "{";
|
||||||
writeDetector( validationFS, di );
|
writeDetector( validationFS, di );
|
||||||
@@ -200,32 +216,33 @@ void CV_DetectorTest::run( int )
|
|||||||
validationFS << "]"; // IMAGE_FILENAMES
|
validationFS << "]"; // IMAGE_FILENAMES
|
||||||
|
|
||||||
validationFS << VALIDATION << "{";
|
validationFS << VALIDATION << "{";
|
||||||
#endif
|
}
|
||||||
|
|
||||||
int progress = 0;
|
int progress = 0;
|
||||||
for( int di = 0; di < test_case_count; di++ )
|
for( int di = 0; di < test_case_count; di++ )
|
||||||
{
|
{
|
||||||
progress = update_progress( progress, di, test_case_count, 0 );
|
progress = update_progress( progress, di, test_case_count, 0 );
|
||||||
#ifdef GET_STAT
|
if( write_results )
|
||||||
validationFS << detectorNames[di] << "{";
|
validationFS << detectorNames[di] << "{";
|
||||||
#endif
|
|
||||||
vector<vector<Rect> > objects;
|
vector<vector<Rect> > objects;
|
||||||
int temp_code = runTestCase( di, 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 );
|
temp_code = validate( di, objects );
|
||||||
#endif
|
|
||||||
if (temp_code != cvtest::TS::OK)
|
if (temp_code != cvtest::TS::OK)
|
||||||
code = temp_code;
|
code = temp_code;
|
||||||
#ifdef GET_STAT
|
|
||||||
|
if( write_results )
|
||||||
validationFS << "}"; // detectorNames[di]
|
validationFS << "}"; // detectorNames[di]
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef GET_STAT
|
if( write_results )
|
||||||
|
{
|
||||||
validationFS << "}"; // VALIDATION
|
validationFS << "}"; // VALIDATION
|
||||||
validationFS << "}"; // getDefaultObjectName
|
validationFS << "}"; // getDefaultObjectName
|
||||||
#endif
|
}
|
||||||
|
|
||||||
if ( test_case_count <= 0 || imageFilenames.size() <= 0 )
|
if ( test_case_count <= 0 || imageFilenames.size() <= 0 )
|
||||||
{
|
{
|
||||||
ts->printf( cvtest::TS::LOG, "validation file is not determined or not correct" );
|
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 );
|
objects.push_back( imgObjects );
|
||||||
|
|
||||||
#ifdef GET_STAT
|
if( write_results )
|
||||||
|
{
|
||||||
char buf[10];
|
char buf[10];
|
||||||
sprintf( buf, "%s%d", "img_", ii );
|
sprintf( buf, "%s%d", "img_", ii );
|
||||||
string imageIdxStr = buf;
|
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 << it->x << it->y << it->width << it->height;
|
||||||
}
|
}
|
||||||
validationFS << "]"; // imageIdxStr
|
validationFS << "]"; // imageIdxStr
|
||||||
#endif
|
}
|
||||||
}
|
}
|
||||||
return cvtest::TS::OK;
|
return cvtest::TS::OK;
|
||||||
}
|
}
|
||||||
@@ -374,12 +392,14 @@ protected:
|
|||||||
virtual void readDetector( const FileNode& fn );
|
virtual void readDetector( const FileNode& fn );
|
||||||
virtual void writeDetector( FileStorage& fs, int di );
|
virtual void writeDetector( FileStorage& fs, int di );
|
||||||
virtual int detectMultiScale( int di, const Mat& img, vector<Rect>& objects );
|
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;
|
vector<int> flags;
|
||||||
};
|
};
|
||||||
|
|
||||||
CV_CascadeDetectorTest::CV_CascadeDetectorTest()
|
CV_CascadeDetectorTest::CV_CascadeDetectorTest()
|
||||||
{
|
{
|
||||||
validationFilename = "cascadeandhog/cascade.xml";
|
validationFilename = "cascadeandhog/cascade.xml";
|
||||||
|
configFilename = "cascadeandhog/_cascade.xml";
|
||||||
}
|
}
|
||||||
|
|
||||||
void CV_CascadeDetectorTest::readDetector( const FileNode& fn )
|
void CV_CascadeDetectorTest::readDetector( const FileNode& fn )
|
||||||
@@ -402,11 +422,48 @@ void CV_CascadeDetectorTest::writeDetector( FileStorage& fs, int di )
|
|||||||
fs << C_SCALE_CASCADE << sc;
|
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,
|
int CV_CascadeDetectorTest::detectMultiScale( int di, const Mat& img,
|
||||||
vector<Rect>& objects)
|
vector<Rect>& objects)
|
||||||
{
|
{
|
||||||
string dataPath = ts->get_data_path(), filename;
|
string dataPath = ts->get_data_path(), filename;
|
||||||
filename = dataPath + detectorFilenames[di];
|
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 );
|
CascadeClassifier cascade( filename );
|
||||||
if( cascade.empty() )
|
if( cascade.empty() )
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user