diff --git a/modules/imgproc/src/shapedescr.cpp b/modules/imgproc/src/shapedescr.cpp index f2de38168a..75e8582521 100644 --- a/modules/imgproc/src/shapedescr.cpp +++ b/modules/imgproc/src/shapedescr.cpp @@ -62,25 +62,8 @@ static void findCircle3pts(Point2f *pts, Point2f ¢er, float &radius) float det = v1.x * v2.y - v1.y * v2.x; if (fabs(det) <= EPS) { - // v1 and v2 are colinear, so the longest distance between any 2 points - // is the diameter of the minimum enclosing circle. - float d1 = normL2Sqr(pts[0] - pts[1]); - float d2 = normL2Sqr(pts[0] - pts[2]); - float d3 = normL2Sqr(pts[1] - pts[2]); - radius = sqrt(std::max(d1, std::max(d2, d3))) * 0.5f + EPS; - if (d1 >= d2 && d1 >= d3) - { - center = (pts[0] + pts[1]) * 0.5f; - } - else if (d2 >= d1 && d2 >= d3) - { - center = (pts[0] + pts[2]) * 0.5f; - } - else - { - CV_DbgAssert(d3 >= d1 && d3 >= d2); - center = (pts[1] + pts[2]) * 0.5f; - } + // triangle is degenerate, so this is 2-points case + // 2-points case should be taken into account in previous step return; } float cx = (c1 * v2.y - c2 * v1.y) / det; diff --git a/modules/imgproc/test/test_convhull.cpp b/modules/imgproc/test/test_convhull.cpp index 654df9167d..e5d3f8a482 100644 --- a/modules/imgproc/test/test_convhull.cpp +++ b/modules/imgproc/test/test_convhull.cpp @@ -127,6 +127,44 @@ TEST(Imgproc_minEnclosingCircle, regression_16051) { EXPECT_NEAR(2.1024551f, radius, 1e-3); } +TEST(Imgproc_minEnclosingCircle, regression_27891) { + { + const vector pts = { {219, 301}, {639, 635}, {740, 569}, {740, 569}, {309, 123}, {349, 88} }; + + Point2f center; + float radius; + minEnclosingCircle(pts, center, radius); + + EXPECT_NEAR(center.x, 522.476f, 1e-3f); + EXPECT_NEAR(center.y, 346.4029f, 1e-3f); + EXPECT_NEAR(radius, 311.2331f, 1e-3f); + } + + { + const vector pts = { {219, 301}, {639, 635}, {740, 569}, {740, 569}, {349, 88} }; + + Point2f center; + float radius; + minEnclosingCircle(pts, center, radius); + + EXPECT_NEAR(center.x, 522.476f, 1e-3f); + EXPECT_NEAR(center.y, 346.4029f, 1e-3f); + EXPECT_NEAR(radius, 311.2331f, 1e-3f); + } + + { + const vector pts = { {639, 635}, {740, 569}, {740, 569}, {349, 88} }; + + Point2f center; + float radius; + minEnclosingCircle(pts, center, radius); + + EXPECT_NEAR(center.x, 522.476f, 1e-3f); + EXPECT_NEAR(center.y, 346.4029f, 1e-3f); + EXPECT_NEAR(radius, 311.2331f, 1e-3f); + } +} + PARAM_TEST_CASE(ConvexityDefects_regression_5908, bool, int) { public: