fixed bug in cv::gpu::HOGDescriptor::detectMultiScale
This commit is contained in:
parent
7a858885e6
commit
e7c35b1852
@ -175,18 +175,18 @@ void cv::gpu::HOGDescriptor::setSVMDetector(const vector<float>& _detector)
|
|||||||
|
|
||||||
cv::gpu::GpuMat cv::gpu::HOGDescriptor::getBuffer(const Size& sz, int type, GpuMat& buf)
|
cv::gpu::GpuMat cv::gpu::HOGDescriptor::getBuffer(const Size& sz, int type, GpuMat& buf)
|
||||||
{
|
{
|
||||||
if (buf.empty() || buf.type() != type)
|
if (buf.empty() || buf.type() != type)
|
||||||
buf.create(sz, type);
|
buf.create(sz, type);
|
||||||
else
|
else
|
||||||
if (buf.cols < sz.width || buf.rows < sz.height)
|
if (buf.cols < sz.width || buf.rows < sz.height)
|
||||||
buf.create(std::max(buf.rows, sz.height), std::max(buf.cols, sz.width), type);
|
buf.create(std::max(buf.rows, sz.height), std::max(buf.cols, sz.width), type);
|
||||||
|
|
||||||
return buf(Rect(Point(0,0), sz));
|
return buf(Rect(Point(0,0), sz));
|
||||||
}
|
}
|
||||||
|
|
||||||
cv::gpu::GpuMat cv::gpu::HOGDescriptor::getBuffer(int rows, int cols, int type, GpuMat& buf)
|
cv::gpu::GpuMat cv::gpu::HOGDescriptor::getBuffer(int rows, int cols, int type, GpuMat& buf)
|
||||||
{
|
{
|
||||||
return getBuffer(Size(cols, rows), type, buf);
|
return getBuffer(Size(cols, rows), type, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -202,7 +202,7 @@ void cv::gpu::HOGDescriptor::computeGradient(const GpuMat& img, GpuMat& _grad, G
|
|||||||
|
|
||||||
float angleScale = (float)(nbins / CV_PI);
|
float angleScale = (float)(nbins / CV_PI);
|
||||||
switch (img.type())
|
switch (img.type())
|
||||||
{
|
{
|
||||||
case CV_8UC1:
|
case CV_8UC1:
|
||||||
hog::compute_gradients_8UC1(nbins, img.rows, img.cols, img, angleScale, _grad, _qangle, gamma_correction);
|
hog::compute_gradients_8UC1(nbins, img.rows, img.cols, img, angleScale, _grad, _qangle, gamma_correction);
|
||||||
break;
|
break;
|
||||||
@ -220,11 +220,11 @@ void cv::gpu::HOGDescriptor::computeBlockHistograms(const GpuMat& img)
|
|||||||
size_t block_hist_size = getBlockHistogramSize();
|
size_t block_hist_size = getBlockHistogramSize();
|
||||||
Size blocks_per_img = numPartsWithin(img.size(), block_size, block_stride);
|
Size blocks_per_img = numPartsWithin(img.size(), block_size, block_stride);
|
||||||
|
|
||||||
// block_hists.create(1, block_hist_size * blocks_per_img.area(), CV_32F);
|
// block_hists.create(1, block_hist_size * blocks_per_img.area(), CV_32F);
|
||||||
block_hists = getBuffer(1, static_cast<int>(block_hist_size * blocks_per_img.area()), CV_32F, block_hists_buf);
|
block_hists = getBuffer(1, static_cast<int>(block_hist_size * blocks_per_img.area()), CV_32F, block_hists_buf);
|
||||||
|
|
||||||
hog::compute_hists(nbins, block_stride.width, block_stride.height, img.rows, img.cols,
|
hog::compute_hists(nbins, block_stride.width, block_stride.height, img.rows, img.cols,
|
||||||
grad, qangle, (float)getWinSigma(), block_hists.ptr<float>());
|
grad, qangle, (float)getWinSigma(), block_hists.ptr<float>());
|
||||||
|
|
||||||
hog::normalize_hists(nbins, block_stride.width, block_stride.height, img.rows, img.cols,
|
hog::normalize_hists(nbins, block_stride.width, block_stride.height, img.rows, img.cols,
|
||||||
block_hists.ptr<float>(), (float)threshold_L2hys);
|
block_hists.ptr<float>(), (float)threshold_L2hys);
|
||||||
@ -277,7 +277,7 @@ void cv::gpu::HOGDescriptor::detect(const GpuMat& img, vector<Point>& hits, doub
|
|||||||
|
|
||||||
Size wins_per_img = numPartsWithin(img.size(), win_size, win_stride);
|
Size wins_per_img = numPartsWithin(img.size(), win_size, win_stride);
|
||||||
// labels.create(1, wins_per_img.area(), CV_8U);
|
// labels.create(1, wins_per_img.area(), CV_8U);
|
||||||
labels = getBuffer(1, wins_per_img.area(), CV_8U, labels_buf);
|
labels = getBuffer(1, wins_per_img.area(), CV_8U, labels_buf);
|
||||||
|
|
||||||
hog::classify_hists(win_size.height, win_size.width, block_stride.height, block_stride.width,
|
hog::classify_hists(win_size.height, win_size.width, block_stride.height, block_stride.width,
|
||||||
win_stride.height, win_stride.width, img.rows, img.cols, block_hists.ptr<float>(),
|
win_stride.height, win_stride.width, img.rows, img.cols, block_hists.ptr<float>(),
|
||||||
@ -297,10 +297,10 @@ void cv::gpu::HOGDescriptor::detect(const GpuMat& img, vector<Point>& hits, doub
|
|||||||
|
|
||||||
|
|
||||||
void cv::gpu::HOGDescriptor::detectMultiScale(const GpuMat& img, vector<Rect>& found_locations, double hit_threshold,
|
void cv::gpu::HOGDescriptor::detectMultiScale(const GpuMat& img, vector<Rect>& found_locations, double hit_threshold,
|
||||||
Size win_stride, Size padding, double scale0, int group_threshold)
|
Size win_stride, Size padding, double scale0, int group_threshold)
|
||||||
{
|
{
|
||||||
|
|
||||||
CV_Assert(img.type() == CV_8UC1 || img.type() == CV_8UC4);
|
CV_Assert(img.type() == CV_8UC1 || img.type() == CV_8UC4);
|
||||||
|
|
||||||
vector<double> level_scale;
|
vector<double> level_scale;
|
||||||
double scale = 1.;
|
double scale = 1.;
|
||||||
@ -316,15 +316,15 @@ void cv::gpu::HOGDescriptor::detectMultiScale(const GpuMat& img, vector<Rect>& f
|
|||||||
}
|
}
|
||||||
levels = std::max(levels, 1);
|
levels = std::max(levels, 1);
|
||||||
level_scale.resize(levels);
|
level_scale.resize(levels);
|
||||||
image_scales.resize(levels);
|
image_scales.resize(levels);
|
||||||
|
|
||||||
std::vector<Rect> all_candidates;
|
std::vector<Rect> all_candidates;
|
||||||
vector<Point> locations;
|
vector<Point> locations;
|
||||||
|
|
||||||
for (size_t i = 0; i < level_scale.size(); i++)
|
for (size_t i = 0; i < level_scale.size(); i++)
|
||||||
{
|
{
|
||||||
double _scale = level_scale[i];
|
scale = level_scale[i];
|
||||||
Size sz(cvRound(img.cols / _scale), cvRound(img.rows / _scale));
|
Size sz(cvRound(img.cols / scale), cvRound(img.rows / scale));
|
||||||
GpuMat smaller_img;
|
GpuMat smaller_img;
|
||||||
|
|
||||||
if (sz == img.size())
|
if (sz == img.size())
|
||||||
@ -333,11 +333,11 @@ void cv::gpu::HOGDescriptor::detectMultiScale(const GpuMat& img, vector<Rect>& f
|
|||||||
{
|
{
|
||||||
image_scales[i].create(sz, img.type());
|
image_scales[i].create(sz, img.type());
|
||||||
switch (img.type())
|
switch (img.type())
|
||||||
{
|
{
|
||||||
case CV_8UC1: hog::resize_8UC1(img, image_scales[i]); break;
|
case CV_8UC1: hog::resize_8UC1(img, image_scales[i]); break;
|
||||||
case CV_8UC4: hog::resize_8UC4(img, image_scales[i]); break;
|
case CV_8UC4: hog::resize_8UC4(img, image_scales[i]); break;
|
||||||
}
|
}
|
||||||
smaller_img = image_scales[i];
|
smaller_img = image_scales[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
detect(smaller_img, locations, hit_threshold, win_stride, padding);
|
detect(smaller_img, locations, hit_threshold, win_stride, padding);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user