Merge pull request #20912 from AleksandrPanov:fix_findMinEnclosingTriangle

pull/20928/head^2
Alexander Alekhin 3 years ago
commit 12507aab8a
  1. 3
      modules/imgproc/src/min_enclosing_triangle.cpp
  2. 33
      modules/imgproc/test/test_convhull.cpp

@ -317,8 +317,9 @@ namespace minEnclosingTriangle {
*/
static void findMinEnclosingTriangle(cv::InputArray points,
CV_OUT cv::OutputArray triangle, CV_OUT double &area) {
std::vector<cv::Point2f> resultingTriangle, polygon;
CV_Assert(!points.empty());
std::vector<cv::Point2f> resultingTriangle;
cv::Mat polygon;
convexHull(points, polygon, true, true);
findMinEnclosingTriangle(polygon, resultingTriangle, area);
cv::Mat(resultingTriangle).copyTo(triangle);

@ -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<void*>(pts_));
vector<Point2f> triangle;
EXPECT_NO_THROW(minEnclosingTriangle(points, triangle));
}
TEST(Imgproc_minEnclosingTriangle, regression_20890)
{
vector<Point> points;
points.push_back(Point(0, 0));
points.push_back(Point(0, 1));
points.push_back(Point(1, 1));
vector<Point2f> 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<void*>(pts_));
cv::Mat pointsNx1(N, 1, CV_32FC2, static_cast<void*>(pts_));
vector<Point2f> triangle;
EXPECT_NO_THROW(minEnclosingTriangle(points1xN, triangle));
EXPECT_NO_THROW(minEnclosingTriangle(pointsNx1, triangle));
}
}} // namespace
/* End of file. */

Loading…
Cancel
Save