diff --git a/modules/imgproc/src/min_enclosing_triangle.cpp b/modules/imgproc/src/min_enclosing_triangle.cpp index 2651871412..7bd15fced0 100644 --- a/modules/imgproc/src/min_enclosing_triangle.cpp +++ b/modules/imgproc/src/min_enclosing_triangle.cpp @@ -317,8 +317,9 @@ namespace minEnclosingTriangle { */ static void findMinEnclosingTriangle(cv::InputArray points, CV_OUT cv::OutputArray triangle, CV_OUT double &area) { - std::vector resultingTriangle, polygon; CV_Assert(!points.empty()); + std::vector resultingTriangle; + cv::Mat polygon; convexHull(points, polygon, true, true); findMinEnclosingTriangle(polygon, resultingTriangle, area); cv::Mat(resultingTriangle).copyTo(triangle); diff --git a/modules/imgproc/test/test_convhull.cpp b/modules/imgproc/test/test_convhull.cpp index dee3769762..bc5c940827 100644 --- a/modules/imgproc/test/test_convhull.cpp +++ b/modules/imgproc/test/test_convhull.cpp @@ -2457,5 +2457,38 @@ TEST(Imgproc_minAreaRect, reproducer_19769) EXPECT_TRUE(checkMinAreaRect(rr, contour)) << rr.center << " " << rr.size << " " << rr.angle; } +TEST(Imgproc_minEnclosingTriangle, regression_17585) +{ + const int N = 3; + float pts_[N][2] = { {0, 0}, {0, 1}, {1, 1} }; + cv::Mat points(N, 2, CV_32FC1, static_cast(pts_)); + vector triangle; + + EXPECT_NO_THROW(minEnclosingTriangle(points, triangle)); +} + +TEST(Imgproc_minEnclosingTriangle, regression_20890) +{ + vector points; + points.push_back(Point(0, 0)); + points.push_back(Point(0, 1)); + points.push_back(Point(1, 1)); + vector triangle; + + EXPECT_NO_THROW(minEnclosingTriangle(points, triangle)); +} + +TEST(Imgproc_minEnclosingTriangle, regression_mat_with_diff_channels) +{ + const int N = 3; + float pts_[N][2] = { {0, 0}, {0, 1}, {1, 1} }; + cv::Mat points1xN(1, N, CV_32FC2, static_cast(pts_)); + cv::Mat pointsNx1(N, 1, CV_32FC2, static_cast(pts_)); + vector triangle; + + EXPECT_NO_THROW(minEnclosingTriangle(points1xN, triangle)); + EXPECT_NO_THROW(minEnclosingTriangle(pointsNx1, triangle)); +} + }} // namespace /* End of file. */