mirror of
https://github.com/opencv/opencv.git
synced 2025-06-12 20:42:53 +08:00
Merge pull request #20815 from alalek:fix_20649_revert_19859
features2d: repair SimpleBlobDetector
* features2d: revert code change by PR #19859
Reverted commit 76860933f0
* features2d: check SimpleBlobDetector parameters consistency
This commit is contained in:
parent
dfa48094dc
commit
755e0143fb
@ -44,6 +44,8 @@
|
|||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
|
#include <opencv2/core/utils/logger.hpp>
|
||||||
|
|
||||||
// Requires CMake flag: DEBUG_opencv_features2d=ON
|
// Requires CMake flag: DEBUG_opencv_features2d=ON
|
||||||
//#define DEBUG_BLOB_DETECTOR
|
//#define DEBUG_BLOB_DETECTOR
|
||||||
|
|
||||||
@ -317,6 +319,19 @@ void SimpleBlobDetectorImpl::detect(InputArray image, std::vector<cv::KeyPoint>&
|
|||||||
CV_Error(Error::StsUnsupportedFormat, "Blob detector only supports 8-bit images!");
|
CV_Error(Error::StsUnsupportedFormat, "Blob detector only supports 8-bit images!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CV_CheckGT(params.thresholdStep, 0.0f, "");
|
||||||
|
if (params.minThreshold + params.thresholdStep >= params.maxThreshold)
|
||||||
|
{
|
||||||
|
// https://github.com/opencv/opencv/issues/6667
|
||||||
|
CV_LOG_ONCE_INFO(NULL, "SimpleBlobDetector: params.minDistBetweenBlobs is ignored for case with single threshold");
|
||||||
|
#if 0 // OpenCV 5.0
|
||||||
|
CV_CheckEQ(params.minRepeatability, 1u, "Incompatible parameters for case with single threshold");
|
||||||
|
#else
|
||||||
|
if (params.minRepeatability != 1)
|
||||||
|
CV_LOG_WARNING(NULL, "SimpleBlobDetector: params.minRepeatability=" << params.minRepeatability << " is incompatible for case with single threshold. Empty result is expected.");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
std::vector < std::vector<Center> > centers;
|
std::vector < std::vector<Center> > centers;
|
||||||
for (double thresh = params.minThreshold; thresh < params.maxThreshold; thresh += params.thresholdStep)
|
for (double thresh = params.minThreshold; thresh < params.maxThreshold; thresh += params.thresholdStep)
|
||||||
{
|
{
|
||||||
@ -325,19 +340,13 @@ void SimpleBlobDetectorImpl::detect(InputArray image, std::vector<cv::KeyPoint>&
|
|||||||
|
|
||||||
std::vector < Center > curCenters;
|
std::vector < Center > curCenters;
|
||||||
findBlobs(grayscaleImage, binarizedImage, curCenters);
|
findBlobs(grayscaleImage, binarizedImage, curCenters);
|
||||||
if(params.maxThreshold - params.minThreshold <= params.thresholdStep) {
|
|
||||||
// if the difference between min and max threshold is less than the threshold step
|
|
||||||
// we're only going to enter the loop once, so we need to add curCenters
|
|
||||||
// to ensure we still use minDistBetweenBlobs
|
|
||||||
centers.push_back(curCenters);
|
|
||||||
}
|
|
||||||
std::vector < std::vector<Center> > newCenters;
|
std::vector < std::vector<Center> > newCenters;
|
||||||
for (size_t i = 0; i < curCenters.size(); i++)
|
for (size_t i = 0; i < curCenters.size(); i++)
|
||||||
{
|
{
|
||||||
bool isNew = true;
|
bool isNew = true;
|
||||||
for (size_t j = 0; j < centers.size(); j++)
|
for (size_t j = 0; j < centers.size(); j++)
|
||||||
{
|
{
|
||||||
double dist = norm(centers[j][centers[j].size() / 2 ].location - curCenters[i].location);
|
double dist = norm(centers[j][ centers[j].size() / 2 ].location - curCenters[i].location);
|
||||||
isNew = dist >= params.minDistBetweenBlobs && dist >= centers[j][ centers[j].size() / 2 ].radius && dist >= curCenters[i].radius;
|
isNew = dist >= params.minDistBetweenBlobs && dist >= centers[j][ centers[j].size() / 2 ].radius && dist >= curCenters[i].radius;
|
||||||
if (!isNew)
|
if (!isNew)
|
||||||
{
|
{
|
||||||
|
@ -12,6 +12,7 @@ TEST(Features2d_BlobDetector, bug_6667)
|
|||||||
SimpleBlobDetector::Params params;
|
SimpleBlobDetector::Params params;
|
||||||
params.minThreshold = 250;
|
params.minThreshold = 250;
|
||||||
params.maxThreshold = 260;
|
params.maxThreshold = 260;
|
||||||
|
params.minRepeatability = 1; // https://github.com/opencv/opencv/issues/6667
|
||||||
std::vector<KeyPoint> keypoints;
|
std::vector<KeyPoint> keypoints;
|
||||||
|
|
||||||
Ptr<SimpleBlobDetector> detector = SimpleBlobDetector::create(params);
|
Ptr<SimpleBlobDetector> detector = SimpleBlobDetector::create(params);
|
||||||
|
Loading…
Reference in New Issue
Block a user