//#define GET_STAT
-#define DIST_E "distE"\r
-#define S_E "sE"\r
-#define NO_PAIR_E "noPairE"\r
+#define DIST_E "distE"
+#define S_E "sE"
+#define NO_PAIR_E "noPairE"
//#define TOTAL_NO_PAIR_E "totalNoPairE"
#define DETECTOR_NAMES "detector_names"
class CV_DetectorTest : public CvTest
{
-public:\r
+public:
CV_DetectorTest( const char* test_name );
- virtual int init( CvTS* system );\r
-protected:\r
- virtual int prepareData( FileStorage& fs );\r
- virtual void run( int startFrom );\r
- virtual string& getValidationFilename();\r
- \r
- virtual void readDetector( const FileNode& fn ) = 0;\r
- virtual void writeDetector( FileStorage& fs, int di ) = 0;\r
- int runTestCase( int detectorIdx, vector<vector<Rect> >& objects );\r
- virtual int detectMultiScale( int di, const Mat& img, vector<Rect>& objects ) = 0;\r
- int validate( int detectorIdx, vector<vector<Rect> >& objects );\r
-\r
- struct\r
- {\r
- float dist;\r
- float s;\r
- float noPair;\r
- //float totalNoPair;\r
- } eps;\r
- vector<string> detectorNames;\r
- vector<string> detectorFilenames;\r
- vector<string> imageFilenames;\r
- vector<Mat> images;\r
- string validationFilename;\r
- FileStorage validationFS;\r
+ virtual int init( CvTS* system );
+protected:
+ virtual int prepareData( FileStorage& fs );
+ virtual void run( int startFrom );
+ virtual string& getValidationFilename();
+
+ virtual void readDetector( const FileNode& fn ) = 0;
+ virtual void writeDetector( FileStorage& fs, int di ) = 0;
+ int runTestCase( int detectorIdx, vector<vector<Rect> >& objects );
+ virtual int detectMultiScale( int di, const Mat& img, vector<Rect>& objects ) = 0;
+ int validate( int detectorIdx, vector<vector<Rect> >& objects );
+
+ struct
+ {
+ float dist;
+ float s;
+ float noPair;
+ //float totalNoPair;
+ } eps;
+ vector<string> detectorNames;
+ vector<string> detectorFilenames;
+ vector<string> imageFilenames;
+ vector<Mat> images;
+ string validationFilename;
+ FileStorage validationFS;
};
CV_DetectorTest::CV_DetectorTest( const char* test_name ) : CvTest( test_name, "detectMultiScale" )
int CV_DetectorTest::prepareData( FileStorage& _fs )
{
- if( !_fs.isOpened() )\r
- test_case_count = -1;\r
- else\r
- {\r
- FileNode fn = _fs.getFirstTopLevelNode();\r
-\r
- fn[DIST_E] >> eps.dist;\r
- fn[S_E] >> eps.s;\r
- fn[NO_PAIR_E] >> eps.noPair;\r
-// fn[TOTAL_NO_PAIR_E] >> eps.totalNoPair;\r
-\r
- // read detectors\r
- if( fn[DETECTOR_NAMES].node->data.seq != 0 )\r
- {\r
- FileNodeIterator it = fn[DETECTOR_NAMES].begin();\r
- for( ; it != fn[DETECTOR_NAMES].end(); )\r
- {\r
- string name;\r
- it >> name; \r
- detectorNames.push_back(name);\r
- readDetector(fn[DETECTORS][name]);\r
- }\r
- }\r
- test_case_count = (int)detectorNames.size();\r
-\r
- // read images filenames and images\r
- string dataPath = ts->get_data_path();\r
- if( fn[IMAGE_FILENAMES].node->data.seq != 0 )\r
- {\r
+ if( !_fs.isOpened() )
+ test_case_count = -1;
+ else
+ {
+ FileNode fn = _fs.getFirstTopLevelNode();
+
+ fn[DIST_E] >> eps.dist;
+ fn[S_E] >> eps.s;
+ fn[NO_PAIR_E] >> eps.noPair;
+// fn[TOTAL_NO_PAIR_E] >> eps.totalNoPair;
+
+ // read detectors
+ if( fn[DETECTOR_NAMES].node->data.seq != 0 )
+ {
+ FileNodeIterator it = fn[DETECTOR_NAMES].begin();
+ for( ; it != fn[DETECTOR_NAMES].end(); )
+ {
+ string name;
+ it >> name;
+ detectorNames.push_back(name);
+ readDetector(fn[DETECTORS][name]);
+ }
+ }
+ test_case_count = (int)detectorNames.size();
+
+ // read images filenames and images
+ string dataPath = ts->get_data_path();
+ if( fn[IMAGE_FILENAMES].node->data.seq != 0 )
+ {
for( FileNodeIterator it = fn[IMAGE_FILENAMES].begin(); it != fn[IMAGE_FILENAMES].end(); )
{
string filename;
imageFilenames.push_back(filename);
Mat img = imread( dataPath+filename, 1 );
images.push_back( img );
- }\r
- }\r
- }\r
+ }
+ }
+ }
return CvTS::OK;
}
validationFS.open( filename, FileStorage::WRITE );
validationFS << FileStorage::getDefaultObjectName(validationFilename) << "{";
- validationFS << DIST_E << eps.dist;\r
- validationFS << S_E << eps.s;\r
- validationFS << NO_PAIR_E << eps.noPair;\r
+ validationFS << DIST_E << eps.dist;
+ validationFS << S_E << eps.s;
+ validationFS << NO_PAIR_E << eps.noPair;
// validationFS << TOTAL_NO_PAIR_E << eps.totalNoPair;
// write detector names
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
validationFS << detectorNames[di] << "{";
#endif
validationFS << "}"; // getDefaultObjectName
#endif
if ( test_case_count <= 0 || imageFilenames.size() <= 0 )
- {\r
+ {
ts->printf( CvTS::LOG, "validation file is not determined or not correct" );
- code = CvTS::FAIL_INVALID_TEST_DATA;\r
+ code = CvTS::FAIL_INVALID_TEST_DATA;
}
ts->set_failed_test_info( code );
}
-int CV_DetectorTest::runTestCase( int detectorIdx, vector<vector<Rect> >& objects )\r
-{\r
- string dataPath = ts->get_data_path(), detectorFilename;\r
- if( !detectorFilenames[detectorIdx].empty() )\r
- detectorFilename = dataPath + detectorFilenames[detectorIdx];\r
-\r
+int CV_DetectorTest::runTestCase( int detectorIdx, vector<vector<Rect> >& objects )
+{
+ string dataPath = ts->get_data_path(), detectorFilename;
+ if( !detectorFilenames[detectorIdx].empty() )
+ detectorFilename = dataPath + detectorFilenames[detectorIdx];
+
for( int ii = 0; ii < (int)imageFilenames.size(); ++ii )
{
vector<Rect> imgObjects;
- Mat image = images[ii];\r
+ Mat image = images[ii];
if( image.empty() )
{
char msg[30];
sprintf( msg, "%s %d %s", "image ", ii, " can not be read" );
ts->printf( CvTS::LOG, msg );
return CvTS::FAIL_INVALID_TEST_DATA;
- }\r
- int code = detectMultiScale( detectorIdx, image, imgObjects );\r
- if( code != CvTS::OK )\r
- return code;\r
-\r
- objects.push_back( imgObjects );\r
+ }
+ int code = detectMultiScale( detectorIdx, image, imgObjects );
+ if( code != CvTS::OK )
+ return code;
+
+ objects.push_back( imgObjects );
#ifdef GET_STAT
char buf[10];
validationFS << it->x << it->y << it->width << it->height;
}
validationFS << "]"; // imageIdxStr
-#endif\r
- }\r
- return CvTS::OK;\r
-}\r
-\r
-\r
-bool isZero( uchar i ) {return i == 0;}\r
-\r
+#endif
+ }
+ return CvTS::OK;
+}
+
+
+bool isZero( uchar i ) {return i == 0;}
+
int CV_DetectorTest::validate( int detectorIdx, vector<vector<Rect> >& objects )
{
assert( imageFilenames.size() == objects.size() );
int noPair = 0;
- // read validation rectangles\r
+ // read validation rectangles
char buf[10];
sprintf( buf, "%s%d", "img_", imageIdx );
- string imageIdxStr = buf;\r
+ string imageIdxStr = buf;
FileNode node = validationFS.getFirstTopLevelNode()[VALIDATION][detectorNames[detectorIdx]][imageIdxStr];
- vector<Rect> valRects;\r
- if( node.node->data.seq != 0 )\r
- {\r
+ vector<Rect> valRects;
+ if( node.node->data.seq != 0 )
+ {
for( FileNodeIterator it = node.begin(); it != node.end(); )
{
Rect r;
it >> r.x >> r.y >> r.width >> r.height;
valRects.push_back(r);
- }\r
+ }
}
totalValRectCount += (int)valRects.size();
detectorNames[detectorIdx].c_str(), imageFilenames[imageIdx].c_str() );
ts->printf( CvTS::LOG, msg );
return CvTS::FAIL_BAD_ACCURACY;
- }\r
- if ( totalNoPair > totalValRectCount*eps./*total*/noPair+1 )\r
- {\r
+ }
+ if ( totalNoPair > totalValRectCount*eps./*total*/noPair+1 )
+ {
ts->printf( CvTS::LOG, "overrated count of rectangles without pair on all images set" );
- return CvTS::FAIL_BAD_ACCURACY;\r
- }\r
-
- return CvTS::OK;\r
-}\r
-\r
-//----------------------------------------------- CascadeDetectorTest -----------------------------------\r
-class CV_CascadeDetectorTest : public CV_DetectorTest\r
-{\r
-public:\r
+ return CvTS::FAIL_BAD_ACCURACY;
+ }
+
+ return CvTS::OK;
+}
+
+//----------------------------------------------- CascadeDetectorTest -----------------------------------
+class CV_CascadeDetectorTest : public CV_DetectorTest
+{
+public:
CV_CascadeDetectorTest( const char* test_name );
-protected:\r
- virtual void readDetector( const FileNode& fn );\r
- virtual void writeDetector( FileStorage& fs, int di );\r
- virtual int detectMultiScale( int di, const Mat& img, vector<Rect>& objects );\r
- vector<int> flags;\r
-};\r
-\r
-CV_CascadeDetectorTest::CV_CascadeDetectorTest(const char *test_name)\r
- : CV_DetectorTest( test_name )\r
-{\r
- validationFilename = "cascadeandhog/cascade.xml";\r
-}\r
-\r
-void CV_CascadeDetectorTest::readDetector( const FileNode& fn )\r
-{\r
- string filename;\r
- int flag;\r
- fn[FILENAME] >> filename;\r
- detectorFilenames.push_back(filename);\r
- fn[C_SCALE_CASCADE] >> flag;\r
+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 );
+ vector<int> flags;
+};
+
+CV_CascadeDetectorTest::CV_CascadeDetectorTest(const char *test_name)
+ : CV_DetectorTest( test_name )
+{
+ validationFilename = "cascadeandhog/cascade.xml";
+}
+
+void CV_CascadeDetectorTest::readDetector( const FileNode& fn )
+{
+ string filename;
+ int flag;
+ fn[FILENAME] >> filename;
+ detectorFilenames.push_back(filename);
+ fn[C_SCALE_CASCADE] >> flag;
if( flag )
- flags.push_back( 0 );\r
- else\r
- flags.push_back( CV_HAAR_SCALE_IMAGE );\r
-}\r
-\r
-void CV_CascadeDetectorTest::writeDetector( FileStorage& fs, int di )\r
-{\r
+ flags.push_back( 0 );
+ else
+ flags.push_back( CV_HAAR_SCALE_IMAGE );
+}
+
+void CV_CascadeDetectorTest::writeDetector( FileStorage& fs, int di )
+{
int sc = flags[di] & CV_HAAR_SCALE_IMAGE ? 0 : 1;
fs << FILENAME << detectorFilenames[di];
fs << C_SCALE_CASCADE << sc;
-}\r
-\r
-int CV_CascadeDetectorTest::detectMultiScale( int di, const Mat& img,\r
- vector<Rect>& objects)\r
-{\r
- string dataPath = ts->get_data_path(), filename;\r
- filename = dataPath + detectorFilenames[di];\r
- CascadeClassifier cascade( filename );\r
- if( cascade.empty() )\r
- {\r
- ts->printf( CvTS::LOG, "cascade %s can not be opened");\r
- return CvTS::FAIL_INVALID_TEST_DATA;\r
- }\r
- Mat grayImg;\r
+}
+
+int CV_CascadeDetectorTest::detectMultiScale( int di, const Mat& img,
+ vector<Rect>& objects)
+{
+ string dataPath = ts->get_data_path(), filename;
+ filename = dataPath + detectorFilenames[di];
+ CascadeClassifier cascade( filename );
+ if( cascade.empty() )
+ {
+ ts->printf( CvTS::LOG, "cascade %s can not be opened");
+ return CvTS::FAIL_INVALID_TEST_DATA;
+ }
+ Mat grayImg;
cvtColor( img, grayImg, CV_BGR2GRAY );
- equalizeHist( grayImg, grayImg );\r
- cascade.detectMultiScale( grayImg, objects, 1.1, 3, flags[di] );\r
- return CvTS::OK;\r
-}\r
-\r
-//----------------------------------------------- HOGDetectorTest -----------------------------------\r
-class CV_HOGDetectorTest : public CV_DetectorTest\r
-{\r
-public:\r
+ equalizeHist( grayImg, grayImg );
+ cascade.detectMultiScale( grayImg, objects, 1.1, 3, flags[di] );
+ return CvTS::OK;
+}
+
+//----------------------------------------------- HOGDetectorTest -----------------------------------
+class CV_HOGDetectorTest : public CV_DetectorTest
+{
+public:
CV_HOGDetectorTest( const char* test_name );
-protected:\r
- virtual void readDetector( const FileNode& fn );\r
- virtual void writeDetector( FileStorage& fs, int di );\r
- virtual int detectMultiScale( int di, const Mat& img, vector<Rect>& objects );\r
-};\r
-\r
-CV_HOGDetectorTest::CV_HOGDetectorTest(const char *test_name)\r
-: CV_DetectorTest( test_name )\r
-{\r
- validationFilename = "cascadeandhog/hog.xml";\r
-}\r
-\r
-void CV_HOGDetectorTest::readDetector( const FileNode& fn )\r
-{\r
- string filename;\r
- if( fn[FILENAME].node->data.seq != 0 )\r
- fn[FILENAME] >> filename;\r
- detectorFilenames.push_back( filename);\r
-}\r
-\r
-void CV_HOGDetectorTest::writeDetector( FileStorage& fs, int di )\r
-{\r
+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 );
+};
+
+CV_HOGDetectorTest::CV_HOGDetectorTest(const char *test_name)
+: CV_DetectorTest( test_name )
+{
+ validationFilename = "cascadeandhog/hog.xml";
+}
+
+void CV_HOGDetectorTest::readDetector( const FileNode& fn )
+{
+ string filename;
+ if( fn[FILENAME].node->data.seq != 0 )
+ fn[FILENAME] >> filename;
+ detectorFilenames.push_back( filename);
+}
+
+void CV_HOGDetectorTest::writeDetector( FileStorage& fs, int di )
+{
fs << FILENAME << detectorFilenames[di];
-}\r
-\r
-int CV_HOGDetectorTest::detectMultiScale( int di, const Mat& img,\r
- vector<Rect>& objects)\r
-{\r
- HOGDescriptor hog;\r
+}
+
+int CV_HOGDetectorTest::detectMultiScale( int di, const Mat& img,
+ vector<Rect>& objects)
+{
+ HOGDescriptor hog;
if( detectorFilenames[di].empty() )
hog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector());
else
assert(0);
- hog.detectMultiScale(img, objects);\r
- return CvTS::OK;\r
-}\r
-\r
-CV_CascadeDetectorTest cascadeTest("cascade-detector");\r
-CV_HOGDetectorTest hogTest("hog-detector");\r
+ hog.detectMultiScale(img, objects);
+ return CvTS::OK;
+}
+
+CV_CascadeDetectorTest cascadeTest("cascade-detector");
+CV_HOGDetectorTest hogTest("hog-detector");