From 6a3a72393867e8377523fd23ef8ae8c54ea8e626 Mon Sep 17 00:00:00 2001 From: "marina.kolpakova" Date: Mon, 5 Nov 2012 23:28:37 +0400 Subject: [PATCH] refactor integral channels --- .../include/opencv2/objdetect/objdetect.hpp | 49 ++++++++++------------ modules/objdetect/src/{isf.cpp => icf.cpp} | 22 +++++----- modules/objdetect/src/softcascade.cpp | 7 ++-- 3 files changed, 39 insertions(+), 39 deletions(-) rename modules/objdetect/src/{isf.cpp => icf.cpp} (86%) diff --git a/modules/objdetect/include/opencv2/objdetect/objdetect.hpp b/modules/objdetect/include/opencv2/objdetect/objdetect.hpp index 84f41e1..4d6db66 100644 --- a/modules/objdetect/include/opencv2/objdetect/objdetect.hpp +++ b/modules/objdetect/include/opencv2/objdetect/objdetect.hpp @@ -511,6 +511,29 @@ public: int kind; }; + // Create channel integrals for Soft Cascade detector. + class CV_EXPORTS Channels + { + public: + // constrictor form resizing factor. + // Param shr is a resizing factor. Resize is applied before the computing integral sum + Channels(const int shrinkage); + + // Appends specified number of HOG first-order features integrals into given vector. + // Param gray is an input 1-channel gray image. + // Param integrals is a vector of integrals. Hog-channels will be appended to it. + // Param bins is a number of hog-bins + void appendHogBins(const cv::Mat gray, std::vector& integrals, int bins) const; + + // Converts 3-channel BGR input frame in Luv and appends each channel to the integrals. + // Param frame is an input 3-channel BGR colored image. + // Param integrals is a vector of integrals. Computed from the frame luv-channels will be appended to it. + void appendLuvBins(const cv::Mat frame, std::vector& integrals) const; + + private: + int shrinkage; + }; + // An empty cascade will be created. // Param minScale is a minimum scale relative to the original size of the image on which cascade will be applyed. // Param minScale is a maximum scale relative to the original size of the image on which cascade will be applyed. @@ -547,32 +570,6 @@ private: CV_EXPORTS bool initModule_objdetect(void); -/** - * \class IntegralChannels - * \brief Create channel integrals for Soft Cascade detector. - */ -class CV_EXPORTS IntegralChannels -{ -public: - //! constrictor form resizing factor. - //! Param shr is a resizing factor. Resize is applied before integral sum computing - IntegralChannels(const int shr) : shrinkage(shr) {} - - //! Appends specified number of hog first order feature integrals into given vector. - //! Param gray is an input 1-chennel gray image. - //! Param integrals is a vector of integrals. Computed from frame frame hog-channels will be appended to it. - //! Param bins is a number of hog-bins - void createHogBins(const cv::Mat gray, std::vector& integrals, int bins) const; - - //! Converts 3-chennel BGR input frame to Luv and append each channel to the integrals. - //! Param frame is an input 3-chennel BGR colored image. - //! Param integrals is a vector of integrals. Computed from frame frame luv-channels will be appended to it. - void createLuvBins(const cv::Mat frame, std::vector& integrals) const; - -private: - int shrinkage; -}; - //////////////// HOG (Histogram-of-Oriented-Gradients) Descriptor and Object Detector ////////////// // struct for detection region of interest (ROI) diff --git a/modules/objdetect/src/isf.cpp b/modules/objdetect/src/icf.cpp similarity index 86% rename from modules/objdetect/src/isf.cpp rename to modules/objdetect/src/icf.cpp index bbf4f27..b6bd113 100644 --- a/modules/objdetect/src/isf.cpp +++ b/modules/objdetect/src/icf.cpp @@ -44,7 +44,9 @@ #include #include -void cv::IntegralChannels::createHogBins(const cv::Mat gray, std::vector& integrals, int bins) const +cv::SCascade::Channels::Channels(int shr) : shrinkage(shr) {} + +void cv::SCascade::Channels::appendHogBins(const cv::Mat gray, std::vector& integrals, int bins) const { CV_Assert(gray.type() == CV_8UC1); int h = gray.rows; @@ -52,11 +54,11 @@ void cv::IntegralChannels::createHogBins(const cv::Mat gray, std::vector& integrals) const +void cv::SCascade::Channels::appendLuvBins(const cv::Mat frame, std::vector& integrals) const { CV_Assert(frame.type() == CV_8UC3); CV_Assert(!(frame.cols % shrinkage) && !(frame.rows % shrinkage)); - cv::Mat luv; + cv::Mat luv, shrunk; cv::cvtColor(frame, luv, CV_BGR2Luv); + cv::resize(luv, shrunk, cv::Size(), 1.0 / shrinkage, 1.0 / shrinkage, CV_INTER_AREA); std::vector splited; - split(luv, splited); + split(shrunk, splited); for (size_t i = 0; i < splited.size(); ++i) { - cv::Mat shrunk, sum; - cv::resize(splited[i], shrunk, cv::Size(), 1.0 / shrinkage, 1.0 / shrinkage, CV_INTER_AREA); - cv::integral(shrunk, sum, cv::noArray(), CV_32S); + cv::Mat sum; + cv::integral(splited[i], sum, cv::noArray(), CV_32S); integrals.push_back(sum); } } \ No newline at end of file diff --git a/modules/objdetect/src/softcascade.cpp b/modules/objdetect/src/softcascade.cpp index 5b4b031..37ab091 100644 --- a/modules/objdetect/src/softcascade.cpp +++ b/modules/objdetect/src/softcascade.cpp @@ -223,14 +223,15 @@ struct ChannelStorage ChannelStorage(const cv::Mat& colored, int shr) : shrinkage(shr) { hog.clear(); - cv::IntegralChannels ints(shr); + hog.reserve(10); + cv::SCascade::Channels ints(shr); // convert to grey cv::Mat grey; cv::cvtColor(colored, grey, CV_BGR2GRAY); - ints.createHogBins(grey, hog, 6); - ints.createLuvBins(colored, hog); + ints.appendHogBins(grey, hog, 6); + ints.appendLuvBins(colored, hog); step = hog[0].cols; } -- 2.7.4