From b0b85f36f61b4b5a79ff7cbe035d3829556f0401 Mon Sep 17 00:00:00 2001 From: "marina.kolpakova" Date: Wed, 5 Sep 2012 12:36:37 +0400 Subject: [PATCH] add test for soft cascade detect method --- .../objdetect/include/opencv2/objdetect/objdetect.hpp | 10 ++++++++-- modules/objdetect/src/softcascade.cpp | 12 +++++++++--- modules/objdetect/test/test_softcascade.cpp | 19 +++++++++++++++++++ 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/modules/objdetect/include/opencv2/objdetect/objdetect.hpp b/modules/objdetect/include/opencv2/objdetect/objdetect.hpp index 9bdc914..9fab741 100644 --- a/modules/objdetect/include/opencv2/objdetect/objdetect.hpp +++ b/modules/objdetect/include/opencv2/objdetect/objdetect.hpp @@ -493,12 +493,18 @@ protected: class CV_EXPORTS SoftCascade { public: + //! empty cascade will be created. SoftCascade(); + + //! cascade will be loaded from file "filename" SoftCascade( const string& filename, const float minScale = 0.4f, const float maxScale = 5.f); - virtual ~SoftCascade(); bool load( const string& filename, const float minScale = 0.4f, const float maxScale = 5.f); - virtual void detectMultiScale(const Mat& image, const std::vector& rois, std::vector& objects, double factor = 1.05, int step = 4, int rejectfactor = 1); + virtual ~SoftCascade(); + + //! return vector of bounding boxes. Each box contains detected object + virtual void detectMultiScale(const Mat& image, const std::vector& rois, std::vector& objects, + int step = 4, int rejectfactor = 1); protected: virtual void detectForOctave(int octave); diff --git a/modules/objdetect/src/softcascade.cpp b/modules/objdetect/src/softcascade.cpp index 065fb0d..62d58f2 100644 --- a/modules/objdetect/src/softcascade.cpp +++ b/modules/objdetect/src/softcascade.cpp @@ -319,14 +319,20 @@ bool cv::SoftCascade::load( const string& filename, const float minScale, const filds = new Filds; Filds& flds = *filds; if (!flds.fill(fs.getFirstTopLevelNode(), minScale, maxScale)) return false; - // flds.calcLevels(FRAME_WIDTH, FRAME_HEIGHT, TOTAL_SCALES); + flds.calcLevels(FRAME_WIDTH, FRAME_HEIGHT, TOTAL_SCALES); return true; } void cv::SoftCascade::detectMultiScale(const Mat& image, const std::vector& rois, std::vector& objects, - const double factor, const int step, const int rejectfactor) -{} + const int step, const int rejectfactor) +{ + // only color images are supperted + CV_Assert(image.type() == CV_8UC3); + + // only this window size allowed + CV_Assert(image.cols == 640 && image.rows == 480); +} void cv::SoftCascade::detectForOctave(const int octave) {} \ No newline at end of file diff --git a/modules/objdetect/test/test_softcascade.cpp b/modules/objdetect/test/test_softcascade.cpp index a7b8548..d283d06 100644 --- a/modules/objdetect/test/test_softcascade.cpp +++ b/modules/objdetect/test/test_softcascade.cpp @@ -47,4 +47,23 @@ TEST(SoftCascade, readCascade) cv::SoftCascade cascade; ASSERT_TRUE(cascade.load(xml)); +} + +TEST(SoftCascade, Detect) +{ + std::string xml = cvtest::TS::ptr()->get_data_path() + "cascadeandhog/softcascade.xml"; + std::cout << "PATH: "<< xml << std::endl; + cv::SoftCascade cascade; + ASSERT_TRUE(cascade.load(xml)); + + cv::Mat colored = cv::imread(cvtest::TS::ptr()->get_data_path() + "cascadeandhog/bahnhof/image_00000006_0.png"); + ASSERT_FALSE(colored.empty()); + + std::vector objectBoxes; + std::vector rois; + rois.push_back(cv::Rect(0, 0, 640, 480)); + ASSERT_NO_THROW( + { + cascade.detectMultiScale(colored, rois, objectBoxes); + }); } \ No newline at end of file -- 2.7.4