From 4d28e8243c6fe78eeeef0a4f59d72c6812578f29 Mon Sep 17 00:00:00 2001 From: Andrey Pavlenko Date: Fri, 10 Jan 2014 00:14:48 +0400 Subject: [PATCH 1/3] 'master'-like Haar perf test --- modules/ocl/perf/perf_haar.cpp | 50 ++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/modules/ocl/perf/perf_haar.cpp b/modules/ocl/perf/perf_haar.cpp index b7a1dd1a43..a6c107fe4d 100644 --- a/modules/ocl/perf/perf_haar.cpp +++ b/modules/ocl/perf/perf_haar.cpp @@ -83,3 +83,53 @@ PERF_TEST(HaarFixture, Haar) else OCL_PERF_ELSE } + +using namespace std; +using namespace cv; +using namespace perf; +using std::tr1::make_tuple; +using std::tr1::get; + +typedef std::tr1::tuple Cascade_Image_MinSize_t; +typedef perf::TestBaseWithParam Cascade_Image_MinSize; + +PERF_TEST_P( Cascade_Image_MinSize, CascadeClassifier_UMat, + testing::Combine( + testing::Values( string("cv/cascadeandhog/cascades/haarcascade_frontalface_alt.xml") ), + testing::Values( string("cv/shared/lena.png"), + string("cv/cascadeandhog/images/bttf301.png"), + string("cv/cascadeandhog/images/class57.png") ), + testing::Values(30, 64, 90) ) ) +{ + const string cascasePath = get<0>(GetParam()); + const string imagePath = get<1>(GetParam()); + const int min_size = get<2>(GetParam()); + Size minSize(min_size, min_size); + + ocl::OclCascadeClassifier cc; + if (!cc.load( getDataPath(cascasePath) )) + FAIL() << "Can't load cascade file: " << getDataPath(cascasePath); + + Mat img = imread(getDataPath(imagePath), IMREAD_GRAYSCALE); + if (img.empty()) + FAIL() << "Can't load source image: " << getDataPath(imagePath); + + vector faces; + + equalizeHist(img, img); + declare.in(img).time(60); + + ocl::oclMat uimg(img); + + while(next()) + { + faces.clear(); + + startTimer(); + cc.detectMultiScale(uimg, faces, 1.1, 3, 0, minSize); + stopTimer(); + } + + //sort(faces.begin(), faces.end(), comparators::RectLess()); + SANITY_CHECK_NOTHING();//(faces, min_size/5); +} From a7821c60e55be5968aec41f31349f58db789671e Mon Sep 17 00:00:00 2001 From: Andrey Pavlenko Date: Mon, 13 Jan 2014 11:20:17 +0400 Subject: [PATCH 2/3] refactoring the test as it should be in 2.4 --- modules/ocl/perf/perf_haar.cpp | 52 +++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/modules/ocl/perf/perf_haar.cpp b/modules/ocl/perf/perf_haar.cpp index a6c107fe4d..2fe01ee6ee 100644 --- a/modules/ocl/perf/perf_haar.cpp +++ b/modules/ocl/perf/perf_haar.cpp @@ -105,31 +105,45 @@ PERF_TEST_P( Cascade_Image_MinSize, CascadeClassifier_UMat, const string imagePath = get<1>(GetParam()); const int min_size = get<2>(GetParam()); Size minSize(min_size, min_size); - - ocl::OclCascadeClassifier cc; - if (!cc.load( getDataPath(cascasePath) )) - FAIL() << "Can't load cascade file: " << getDataPath(cascasePath); - - Mat img = imread(getDataPath(imagePath), IMREAD_GRAYSCALE); - if (img.empty()) - FAIL() << "Can't load source image: " << getDataPath(imagePath); - vector faces; + Mat img = imread(getDataPath(imagePath), IMREAD_GRAYSCALE); + ASSERT_TRUE(!img.empty()) << "Can't load source image: " << getDataPath(imagePath); equalizeHist(img, img); - declare.in(img).time(60); + declare.in(img); - ocl::oclMat uimg(img); - - while(next()) + if (RUN_PLAIN_IMPL) { - faces.clear(); + CascadeClassifier cc; + ASSERT_TRUE(cc.load(getDataPath(cascasePath))) << "Can't load cascade file: " << getDataPath(cascasePath); - startTimer(); - cc.detectMultiScale(uimg, faces, 1.1, 3, 0, minSize); - stopTimer(); + while (next()) + { + faces.clear(); + + startTimer(); + cc.detectMultiScale(img, faces, 1.1, 3, 0, minSize); + stopTimer(); + } } + else if (RUN_OCL_IMPL) + { + ocl::oclMat uimg(img); + ocl::OclCascadeClassifier cc; + ASSERT_TRUE(cc.load(getDataPath(cascasePath))) << "Can't load cascade file: " << getDataPath(cascasePath); - //sort(faces.begin(), faces.end(), comparators::RectLess()); - SANITY_CHECK_NOTHING();//(faces, min_size/5); + while (next()) + { + faces.clear(); + + startTimer(); + cc.detectMultiScale(uimg, faces, 1.1, 3, 0, minSize); + stopTimer(); + } + } + else + OCL_PERF_ELSE + + //sort(faces.begin(), faces.end(), comparators::RectLess()); + SANITY_CHECK_NOTHING();//(faces, min_size/5); } From 4c99196399288d2a97af37366c9a938d9092f0f1 Mon Sep 17 00:00:00 2001 From: Andrey Pavlenko Date: Mon, 13 Jan 2014 18:12:30 +0400 Subject: [PATCH 3/3] adding `finish()` to flush CL queue, renaming the test to match 'master' branch --- modules/ocl/perf/perf_haar.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/modules/ocl/perf/perf_haar.cpp b/modules/ocl/perf/perf_haar.cpp index 2fe01ee6ee..86890a8911 100644 --- a/modules/ocl/perf/perf_haar.cpp +++ b/modules/ocl/perf/perf_haar.cpp @@ -90,10 +90,10 @@ using namespace perf; using std::tr1::make_tuple; using std::tr1::get; -typedef std::tr1::tuple Cascade_Image_MinSize_t; -typedef perf::TestBaseWithParam Cascade_Image_MinSize; +typedef std::tr1::tuple OCL_Cascade_Image_MinSize_t; +typedef perf::TestBaseWithParam OCL_Cascade_Image_MinSize; -PERF_TEST_P( Cascade_Image_MinSize, CascadeClassifier_UMat, +PERF_TEST_P( OCL_Cascade_Image_MinSize, CascadeClassifier, testing::Combine( testing::Values( string("cv/cascadeandhog/cascades/haarcascade_frontalface_alt.xml") ), testing::Values( string("cv/shared/lena.png"), @@ -135,6 +135,7 @@ PERF_TEST_P( Cascade_Image_MinSize, CascadeClassifier_UMat, while (next()) { faces.clear(); + ocl::finish(); startTimer(); cc.detectMultiScale(uimg, faces, 1.1, 3, 0, minSize); @@ -146,4 +147,5 @@ PERF_TEST_P( Cascade_Image_MinSize, CascadeClassifier_UMat, //sort(faces.begin(), faces.end(), comparators::RectLess()); SANITY_CHECK_NOTHING();//(faces, min_size/5); + // using SANITY_CHECK_NOTHING() since OCL and PLAIN version may find different faces number }