refactor integral channels

This commit is contained in:
marina.kolpakova 2012-11-05 23:28:37 +04:00
parent 65543c53f6
commit 6a3a723938
3 changed files with 39 additions and 39 deletions

View File

@ -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<cv::Mat>& 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<cv::Mat>& 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<cv::Mat>& 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<cv::Mat>& integrals) const;
private:
int shrinkage;
};
//////////////// HOG (Histogram-of-Oriented-Gradients) Descriptor and Object Detector //////////////
// struct for detection region of interest (ROI)

View File

@ -44,7 +44,9 @@
#include <opencv2/objdetect/objdetect.hpp>
#include <opencv2/core/core.hpp>
void cv::IntegralChannels::createHogBins(const cv::Mat gray, std::vector<cv::Mat>& integrals, int bins) const
cv::SCascade::Channels::Channels(int shr) : shrinkage(shr) {}
void cv::SCascade::Channels::appendHogBins(const cv::Mat gray, std::vector<cv::Mat>& 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<cv::Mat
CV_Assert(!(w % shrinkage) && !(h % shrinkage));
cv::Mat df_dx, df_dy, mag, angle;
cv::Sobel(gray, df_dx, CV_32F, 1, 0, 3, 0.125);
cv::Sobel(gray, df_dy, CV_32F, 0, 1, 3, 0.125);
cv::Sobel(gray, df_dx, CV_32F, 1, 0);
cv::Sobel(gray, df_dy, CV_32F, 0, 1);
cv::cartToPolar(df_dx, df_dy, mag, angle, true);
mag *= (1.f / sqrt(2));
mag *= (1.f / (8 * sqrt(2)));
cv::Mat nmag;
mag.convertTo(nmag, CV_8UC1);
@ -92,22 +94,22 @@ void cv::IntegralChannels::createHogBins(const cv::Mat gray, std::vector<cv::Mat
integrals.push_back(mag);
}
void cv::IntegralChannels::createLuvBins(const cv::Mat frame, std::vector<cv::Mat>& integrals) const
void cv::SCascade::Channels::appendLuvBins(const cv::Mat frame, std::vector<cv::Mat>& 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<cv::Mat> 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);
}
}

View File

@ -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;
}