Merge remote-tracking branch 'origin/2.4'
Conflicts: 3rdparty/ffmpeg/ffmpeg_version.cmake cmake/OpenCVFindLibsGrfmt.cmake cmake/templates/cvconfig.h.cmake modules/bioinspired/doc/retina/index.rst modules/calib3d/doc/camera_calibration_and_3d_reconstruction.rst modules/calib3d/src/precomp.hpp modules/contrib/src/inputoutput.cpp modules/contrib/src/precomp.hpp modules/core/include/opencv2/core/internal.hpp modules/core/include/opencv2/core/types_c.h modules/core/src/drawing.cpp modules/core/src/precomp.hpp modules/core/src/system.cpp modules/features2d/doc/common_interfaces_of_descriptor_matchers.rst modules/features2d/doc/common_interfaces_of_feature_detectors.rst modules/features2d/include/opencv2/features2d/features2d.hpp modules/features2d/src/precomp.hpp modules/flann/src/precomp.hpp modules/gpu/doc/camera_calibration_and_3d_reconstruction.rst modules/gpu/doc/image_filtering.rst modules/gpu/doc/image_processing.rst modules/gpu/doc/video.rst modules/gpu/perf/perf_imgproc.cpp modules/gpu/perf4au/main.cpp modules/gpu/src/imgproc.cpp modules/gpu/src/precomp.hpp modules/gpu/test/test_imgproc.cpp modules/highgui/CMakeLists.txt modules/highgui/test/test_precomp.hpp modules/imgproc/doc/structural_analysis_and_shape_descriptors.rst modules/imgproc/src/precomp.hpp modules/java/generator/src/cpp/Mat.cpp modules/legacy/src/precomp.hpp modules/ml/doc/k_nearest_neighbors.rst modules/ml/src/precomp.hpp modules/nonfree/doc/feature_detection.rst modules/nonfree/src/precomp.hpp modules/objdetect/include/opencv2/objdetect/objdetect.hpp modules/objdetect/src/cascadedetect.cpp modules/objdetect/src/hog.cpp modules/objdetect/src/precomp.hpp modules/objdetect/test/test_latentsvmdetector.cpp modules/ocl/src/hog.cpp modules/ocl/src/opencl/objdetect_hog.cl modules/ocl/src/precomp.hpp modules/photo/src/precomp.hpp modules/stitching/src/precomp.hpp modules/superres/perf/perf_precomp.hpp modules/superres/src/optical_flow.cpp modules/superres/src/precomp.hpp modules/superres/test/test_precomp.hpp modules/ts/include/opencv2/ts.hpp modules/video/src/precomp.hpp modules/videostab/src/precomp.hpp modules/world/src/precomp.hpp
This commit is contained in:
@@ -113,24 +113,6 @@ struct Logger
|
||||
namespace cv
|
||||
{
|
||||
|
||||
// class for grouping object candidates, detected by Cascade Classifier, HOG etc.
|
||||
// instance of the class is to be passed to cv::partition (see cxoperations.hpp)
|
||||
class CV_EXPORTS SimilarRects
|
||||
{
|
||||
public:
|
||||
SimilarRects(double _eps) : eps(_eps) {}
|
||||
inline bool operator()(const Rect& r1, const Rect& r2) const
|
||||
{
|
||||
double delta = eps*(std::min(r1.width, r2.width) + std::min(r1.height, r2.height))*0.5;
|
||||
return std::abs(r1.x - r2.x) <= delta &&
|
||||
std::abs(r1.y - r2.y) <= delta &&
|
||||
std::abs(r1.x + r1.width - r2.x - r2.width) <= delta &&
|
||||
std::abs(r1.y + r1.height - r2.y - r2.height) <= delta;
|
||||
}
|
||||
double eps;
|
||||
};
|
||||
|
||||
|
||||
void groupRectangles(std::vector<Rect>& rectList, int groupThreshold, double eps, std::vector<int>* weights, std::vector<double>* levelWeights)
|
||||
{
|
||||
if( groupThreshold <= 0 || rectList.empty() )
|
||||
|
@@ -1303,7 +1303,7 @@ void HOGDescriptor::detectMultiScale(
|
||||
if ( useMeanshiftGrouping )
|
||||
groupRectangles_meanshift(foundLocations, foundWeights, foundScales, finalThreshold, winSize);
|
||||
else
|
||||
groupRectangles(foundLocations, (int)finalThreshold, 0.2);
|
||||
groupRectangles(foundLocations, foundWeights, (int)finalThreshold, 0.2);
|
||||
}
|
||||
|
||||
void HOGDescriptor::detectMultiScale(const Mat& img, std::vector<Rect>& foundLocations,
|
||||
@@ -2944,5 +2944,83 @@ void HOGDescriptor::readALTModel(String modelfile)
|
||||
fclose(modelfl);
|
||||
}
|
||||
|
||||
void HOGDescriptor::groupRectangles(std::vector<cv::Rect>& rectList, std::vector<double>& weights, int groupThreshold, double eps) const
|
||||
{
|
||||
if( groupThreshold <= 0 || rectList.empty() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
CV_Assert(rectList.size() == weights.size());
|
||||
|
||||
std::vector<int> labels;
|
||||
int nclasses = partition(rectList, labels, SimilarRects(eps));
|
||||
|
||||
std::vector<cv::Rect_<double> > rrects(nclasses);
|
||||
std::vector<int> numInClass(nclasses, 0);
|
||||
std::vector<double> foundWeights(nclasses, DBL_MIN);
|
||||
std::vector<double> totalFactorsPerClass(nclasses, 1);
|
||||
int i, j, nlabels = (int)labels.size();
|
||||
|
||||
for( i = 0; i < nlabels; i++ )
|
||||
{
|
||||
int cls = labels[i];
|
||||
rrects[cls].x += rectList[i].x;
|
||||
rrects[cls].y += rectList[i].y;
|
||||
rrects[cls].width += rectList[i].width;
|
||||
rrects[cls].height += rectList[i].height;
|
||||
foundWeights[cls] = max(foundWeights[cls], weights[i]);
|
||||
numInClass[cls]++;
|
||||
}
|
||||
|
||||
for( i = 0; i < nclasses; i++ )
|
||||
{
|
||||
// find the average of all ROI in the cluster
|
||||
cv::Rect_<double> r = rrects[i];
|
||||
double s = 1.0/numInClass[i];
|
||||
rrects[i] = cv::Rect_<double>(cv::saturate_cast<double>(r.x*s),
|
||||
cv::saturate_cast<double>(r.y*s),
|
||||
cv::saturate_cast<double>(r.width*s),
|
||||
cv::saturate_cast<double>(r.height*s));
|
||||
}
|
||||
|
||||
rectList.clear();
|
||||
weights.clear();
|
||||
|
||||
for( i = 0; i < nclasses; i++ )
|
||||
{
|
||||
cv::Rect r1 = rrects[i];
|
||||
int n1 = numInClass[i];
|
||||
double w1 = foundWeights[i];
|
||||
if( n1 <= groupThreshold )
|
||||
continue;
|
||||
// filter out small rectangles inside large rectangles
|
||||
for( j = 0; j < nclasses; j++ )
|
||||
{
|
||||
int n2 = numInClass[j];
|
||||
|
||||
if( j == i || n2 <= groupThreshold )
|
||||
continue;
|
||||
|
||||
cv::Rect r2 = rrects[j];
|
||||
|
||||
int dx = cv::saturate_cast<int>( r2.width * eps );
|
||||
int dy = cv::saturate_cast<int>( r2.height * eps );
|
||||
|
||||
if( r1.x >= r2.x - dx &&
|
||||
r1.y >= r2.y - dy &&
|
||||
r1.x + r1.width <= r2.x + r2.width + dx &&
|
||||
r1.y + r1.height <= r2.y + r2.height + dy &&
|
||||
(n2 > std::max(3, n1) || n1 < 3) )
|
||||
break;
|
||||
}
|
||||
|
||||
if( j == nclasses )
|
||||
{
|
||||
rectList.push_back(r1);
|
||||
weights.push_back(w1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user