mirror of
https://github.com/opencv/opencv.git
synced 2025-06-11 11:45:30 +08:00
Merge pull request #20170 from danielenricocahall:fix-mser-grayscale-min-diversity
This commit is contained in:
commit
b754406352
@ -520,6 +520,9 @@ public:
|
|||||||
CV_WRAP virtual void setMaxArea(int maxArea) = 0;
|
CV_WRAP virtual void setMaxArea(int maxArea) = 0;
|
||||||
CV_WRAP virtual int getMaxArea() const = 0;
|
CV_WRAP virtual int getMaxArea() const = 0;
|
||||||
|
|
||||||
|
CV_WRAP virtual void setMinDiversity(double minDiversity) = 0;
|
||||||
|
CV_WRAP virtual double getMinDiversity() const = 0;
|
||||||
|
|
||||||
CV_WRAP virtual void setPass2Only(bool f) = 0;
|
CV_WRAP virtual void setPass2Only(bool f) = 0;
|
||||||
CV_WRAP virtual bool getPass2Only() const = 0;
|
CV_WRAP virtual bool getPass2Only() const = 0;
|
||||||
CV_WRAP virtual String getDefaultName() const CV_OVERRIDE;
|
CV_WRAP virtual String getDefaultName() const CV_OVERRIDE;
|
||||||
|
@ -96,6 +96,9 @@ public:
|
|||||||
void setMaxArea(int maxArea) CV_OVERRIDE { params.maxArea = maxArea; }
|
void setMaxArea(int maxArea) CV_OVERRIDE { params.maxArea = maxArea; }
|
||||||
int getMaxArea() const CV_OVERRIDE { return params.maxArea; }
|
int getMaxArea() const CV_OVERRIDE { return params.maxArea; }
|
||||||
|
|
||||||
|
void setMinDiversity(double minDiversity) CV_OVERRIDE { params.minDiversity = minDiversity; }
|
||||||
|
double getMinDiversity() const CV_OVERRIDE { return params.minDiversity; }
|
||||||
|
|
||||||
void setPass2Only(bool f) CV_OVERRIDE { params.pass2Only = f; }
|
void setPass2Only(bool f) CV_OVERRIDE { params.pass2Only = f; }
|
||||||
bool getPass2Only() const CV_OVERRIDE { return params.pass2Only; }
|
bool getPass2Only() const CV_OVERRIDE { return params.pass2Only; }
|
||||||
|
|
||||||
@ -200,7 +203,7 @@ public:
|
|||||||
if( checked )
|
if( checked )
|
||||||
return;
|
return;
|
||||||
checked = true;
|
checked = true;
|
||||||
if( size < wp.p.minArea || size > wp.p.maxArea || var < 0.f || var > wp.p.maxVariation )
|
if( size < wp.p.minArea || size > wp.p.maxArea || var < wp.p.minDiversity || var > wp.p.maxVariation )
|
||||||
return;
|
return;
|
||||||
if( child_ )
|
if( child_ )
|
||||||
{
|
{
|
||||||
|
@ -119,6 +119,7 @@ TEST(Features2d_MSER, cases)
|
|||||||
|
|
||||||
mserExtractor->setMinArea(kMinArea);
|
mserExtractor->setMinArea(kMinArea);
|
||||||
mserExtractor->setMaxArea(kMaxArea);
|
mserExtractor->setMaxArea(kMaxArea);
|
||||||
|
mserExtractor->setMinDiversity(0);
|
||||||
|
|
||||||
if( invert )
|
if( invert )
|
||||||
bitwise_not(src, src);
|
bitwise_not(src, src);
|
||||||
@ -170,6 +171,7 @@ TEST(Features2d_MSER, history_update_regression)
|
|||||||
{
|
{
|
||||||
Ptr<MSER> mser = MSER::create(1, minArea, (int)(tstImages[j].cols * tstImages[j].rows * 0.2));
|
Ptr<MSER> mser = MSER::create(1, minArea, (int)(tstImages[j].cols * tstImages[j].rows * 0.2));
|
||||||
mser->setPass2Only(true);
|
mser->setPass2Only(true);
|
||||||
|
mser->setMinDiversity(0);
|
||||||
vector<vector<Point> > mserContours;
|
vector<vector<Point> > mserContours;
|
||||||
vector<Rect> boxRects;
|
vector<Rect> boxRects;
|
||||||
mser->detectRegions(tstImages[j], mserContours, boxRects);
|
mser->detectRegions(tstImages[j], mserContours, boxRects);
|
||||||
@ -179,4 +181,28 @@ TEST(Features2d_MSER, history_update_regression)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TEST(Features2d_MSER, bug_5630)
|
||||||
|
{
|
||||||
|
String dataPath = cvtest::TS::ptr()->get_data_path() + "mser/";
|
||||||
|
Mat img = imread(dataPath + "mser_test.png", IMREAD_GRAYSCALE);
|
||||||
|
Ptr<MSER> mser = MSER::create(1, 1);
|
||||||
|
vector<vector<Point> > mserContours;
|
||||||
|
vector<Rect> boxRects;
|
||||||
|
|
||||||
|
// set min diversity and run detection
|
||||||
|
mser->setMinDiversity(0.1);
|
||||||
|
mser->detectRegions(img, mserContours, boxRects);
|
||||||
|
size_t originalNumberOfContours = mserContours.size();
|
||||||
|
|
||||||
|
// increase min diversity and run detection again
|
||||||
|
mser->setMinDiversity(0.2);
|
||||||
|
mser->detectRegions(img, mserContours, boxRects);
|
||||||
|
size_t newNumberOfContours = mserContours.size();
|
||||||
|
|
||||||
|
// there should be fewer regions detected with a higher min diversity
|
||||||
|
ASSERT_LT(newNumberOfContours, originalNumberOfContours);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}} // namespace
|
}} // namespace
|
||||||
|
@ -35,6 +35,7 @@ class mser_test(NewOpenCVTests):
|
|||||||
kDelta = 5
|
kDelta = 5
|
||||||
mserExtractor = cv.MSER_create()
|
mserExtractor = cv.MSER_create()
|
||||||
mserExtractor.setDelta(kDelta)
|
mserExtractor.setDelta(kDelta)
|
||||||
|
mserExtractor.setMinDiversity(0)
|
||||||
np.random.seed(10)
|
np.random.seed(10)
|
||||||
|
|
||||||
for _i in range(100):
|
for _i in range(100):
|
||||||
|
Loading…
Reference in New Issue
Block a user