From 87a21016d866f97228fb2310c4ac57fb221d61e2 Mon Sep 17 00:00:00 2001 From: Leonid Beynenson Date: Wed, 28 Sep 2011 21:14:20 +0000 Subject: [PATCH] Implemented the first variant of working with masks in CascadeClassifier. Probably, will be rewritten soon. --- .../objdetect/perf/perf_cascadeclassifier.cpp | 18 ++++++++++++++++-- modules/objdetect/src/cascadedetect.cpp | 18 +++++++++++++++--- modules/objdetect/src/precomp.hpp | 4 ++++ 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/modules/objdetect/perf/perf_cascadeclassifier.cpp b/modules/objdetect/perf/perf_cascadeclassifier.cpp index d8a5f4e5f6..af01dd5ce8 100644 --- a/modules/objdetect/perf/perf_cascadeclassifier.cpp +++ b/modules/objdetect/perf/perf_cascadeclassifier.cpp @@ -1,4 +1,5 @@ #include "perf_precomp.hpp" +#include using namespace std; using namespace cv; @@ -8,7 +9,18 @@ typedef std::tr1::tuple ImageName_MinSize_t; typedef perf::TestBaseWithParam ImageName_MinSize; PERF_TEST_P( ImageName_MinSize, CascadeClassifierLBPFrontalFace, - testing::Combine(testing::Values( std::string("cv/shared/lena.jpg")), testing::Values(24, 30, 40, 50, 60, 70, 80, 90) ) ) + testing::Combine(testing::Values( std::string("cv/shared/lena.jpg"), + std::string("cv/shared/1_itseez-0000247.jpg"), + std::string("cv/shared/1_itseez-0000289.jpg"), + std::string("cv/shared/1_itseez-0000492.jpg"), + std::string("cv/shared/1_itseez-0000573.jpg"), + std::string("cv/shared/1_itseez-0000803.jpg"), + std::string("cv/shared/1_itseez-0000892.jpg"), + std::string("cv/shared/1_itseez-0000984.jpg"), + std::string("cv/shared/1_itseez-0001238.jpg"), + std::string("cv/shared/1_itseez-0001438.jpg"), + std::string("cv/shared/1_itseez-0002524.jpg")), + testing::Values(24, 30, 40, 50, 60, 70, 80, 90) ) ) { const string filename = std::tr1::get<0>(GetParam()); int min_size = std::tr1::get<1>(GetParam()); @@ -18,12 +30,13 @@ PERF_TEST_P( ImageName_MinSize, CascadeClassifierLBPFrontalFace, if (cc.empty()) FAIL() << "Can't load cascade file"; - Mat img=imread(getDataPath(filename)); + Mat img=imread(getDataPath(filename), 0); if (img.empty()) FAIL() << "Can't load source image"; vector res; + declare.in(img);//.out(res) while(next()) @@ -31,6 +44,7 @@ PERF_TEST_P( ImageName_MinSize, CascadeClassifierLBPFrontalFace, res.clear(); startTimer(); + equalizeHist(img, img); cc.detectMultiScale(img, res, 1.1, 3, 0, minSize); stopTimer(); } diff --git a/modules/objdetect/src/cascadedetect.cpp b/modules/objdetect/src/cascadedetect.cpp index 48f9518ce9..f71e9bf88c 100644 --- a/modules/objdetect/src/cascadedetect.cpp +++ b/modules/objdetect/src/cascadedetect.cpp @@ -861,9 +861,10 @@ bool CascadeClassifier::setImage( Ptr& featureEvaluator, const struct CascadeClassifierInvoker { - CascadeClassifierInvoker( CascadeClassifier& _cc, Size _sz1, int _stripSize, int _yStep, double _factor, + CascadeClassifierInvoker( const Mat& _image, CascadeClassifier& _cc, Size _sz1, int _stripSize, int _yStep, double _factor, ConcurrentRectVector& _vec, vector& _levels, vector& _weights, bool outputLevels = false ) { + image=_image; classifier = &_cc; processingRectSize = _sz1; stripSize = _stripSize; @@ -877,6 +878,10 @@ struct CascadeClassifierInvoker void operator()(const BlockedRange& range) const { Ptr evaluator = classifier->featureEvaluator->clone(); + +#ifdef HAVE_TEGRA_OPTIMIZATION + Mat currentMask=tegra::getCascadeClassifierMask(image, classifier->data.origWinSize); +#endif Size winSize(cvRound(classifier->data.origWinSize.width * scalingFactor), cvRound(classifier->data.origWinSize.height * scalingFactor)); int y1 = range.begin() * stripSize; @@ -885,6 +890,12 @@ struct CascadeClassifierInvoker { for( int x = 0; x < processingRectSize.width; x += yStep ) { +#ifdef HAVE_TEGRA_OPTIMIZATION + if ( (!currentMask.empty()) && (currentMask.at(Point(x,y))==0)) { + continue; + } +#endif + double gypWeight; int result = classifier->runAt(evaluator, Point(x, y), gypWeight); if( rejectLevels ) @@ -907,6 +918,7 @@ struct CascadeClassifierInvoker } } + Mat image; CascadeClassifier* classifier; ConcurrentRectVector* rectangles; Size processingRectSize; @@ -930,14 +942,14 @@ bool CascadeClassifier::detectSingleScale( const Mat& image, int stripCount, Siz vector levelWeights; if( outputRejectLevels ) { - parallel_for(BlockedRange(0, stripCount), CascadeClassifierInvoker( *this, processingRectSize, stripSize, yStep, factor, + parallel_for(BlockedRange(0, stripCount), CascadeClassifierInvoker( image, *this, processingRectSize, stripSize, yStep, factor, concurrentCandidates, rejectLevels, levelWeights, true)); levels.insert( levels.end(), rejectLevels.begin(), rejectLevels.end() ); weights.insert( weights.end(), levelWeights.begin(), levelWeights.end() ); } else { - parallel_for(BlockedRange(0, stripCount), CascadeClassifierInvoker( *this, processingRectSize, stripSize, yStep, factor, + parallel_for(BlockedRange(0, stripCount), CascadeClassifierInvoker( image, *this, processingRectSize, stripSize, yStep, factor, concurrentCandidates, rejectLevels, levelWeights, false)); } candidates.insert( candidates.end(), concurrentCandidates.begin(), concurrentCandidates.end() ); diff --git a/modules/objdetect/src/precomp.hpp b/modules/objdetect/src/precomp.hpp index 2ab8ba35be..f763a75033 100644 --- a/modules/objdetect/src/precomp.hpp +++ b/modules/objdetect/src/precomp.hpp @@ -60,4 +60,8 @@ #include "opencv2/features2d/features2d.hpp" #include "opencv2/calib3d/calib3d.hpp" +#ifdef HAVE_TEGRA_OPTIMIZATION +#include "opencv2/objdetect/objdetect_tegra.hpp" +#endif + #endif