Skip to content

Commit e955bcb

Browse files
committed
Merge pull request opencv#9824 from sturkmen72:upd_minEnclosingTriangle
2 parents ec24091 + af9c837 commit e955bcb

File tree

3 files changed

+10
-27
lines changed

3 files changed

+10
-27
lines changed

modules/imgproc/include/opencv2/imgproc.hpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3920,9 +3920,8 @@ CV_EXPORTS_W double contourArea( InputArray contour, bool oriented = false );
39203920
/** @brief Finds a rotated rectangle of the minimum area enclosing the input 2D point set.
39213921
39223922
The function calculates and returns the minimum-area bounding rectangle (possibly rotated) for a
3923-
specified point set. See the OpenCV sample minarea.cpp . Developer should keep in mind that the
3924-
returned rotatedRect can contain negative indices when data is close to the containing Mat element
3925-
boundary.
3923+
specified point set. Developer should keep in mind that the returned RotatedRect can contain negative
3924+
indices when data is close to the containing Mat element boundary.
39263925
39273926
@param points Input vector of 2D points, stored in std::vector\<\> or Mat
39283927
*/
@@ -3943,8 +3942,7 @@ CV_EXPORTS_W void boxPoints(RotatedRect box, OutputArray points);
39433942

39443943
/** @brief Finds a circle of the minimum area enclosing a 2D point set.
39453944
3946-
The function finds the minimal enclosing circle of a 2D point set using an iterative algorithm. See
3947-
the OpenCV sample minarea.cpp .
3945+
The function finds the minimal enclosing circle of a 2D point set using an iterative algorithm.
39483946
39493947
@param points Input vector of 2D points, stored in std::vector\<\> or Mat
39503948
@param center Output center of the circle.

modules/imgproc/src/min_enclosing_triangle.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,6 @@ static bool areOnTheSameSideOfLine(const cv::Point2f &p1, const cv::Point2f &p2,
129129

130130
static double areaOfTriangle(const cv::Point2f &a, const cv::Point2f &b, const cv::Point2f &c);
131131

132-
static void copyResultingTriangle(const std::vector<cv::Point2f> &resultingTriangle, cv::OutputArray triangle);
133-
134132
static void createConvexHull(cv::InputArray points, std::vector<cv::Point2f> &polygon);
135133

136134
static double distanceBtwPoints(const cv::Point2f &a, const cv::Point2f &b);
@@ -324,7 +322,7 @@ static void findMinEnclosingTriangle(cv::InputArray points,
324322

325323
createConvexHull(points, polygon);
326324
findMinEnclosingTriangle(polygon, resultingTriangle, area);
327-
copyResultingTriangle(resultingTriangle, triangle);
325+
cv::Mat(resultingTriangle).copyTo(triangle);
328326
}
329327

330328
//! Create the convex hull of the given set of points
@@ -364,16 +362,6 @@ static void findMinEnclosingTriangle(const std::vector<cv::Point2f> &polygon,
364362
}
365363
}
366364

367-
//! Copy resultingTriangle to the OutputArray triangle
368-
/*!
369-
* @param resultingTriangle Minimum area triangle enclosing the given polygon found by the algorithm
370-
* @param triangle Minimum area triangle enclosing the given polygon returned to the user
371-
*/
372-
static void copyResultingTriangle(const std::vector<cv::Point2f> &resultingTriangle,
373-
cv::OutputArray triangle) {
374-
cv::Mat(resultingTriangle).copyTo(triangle);
375-
}
376-
377365
//! Initialisation function
378366
/*!
379367
* @param triangle Minimum area triangle enclosing the given polygon

samples/cpp/minarea.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@ static void help()
1111
cout << "This program demonstrates finding the minimum enclosing box, triangle or circle of a set\n"
1212
<< "of points using functions: minAreaRect() minEnclosingTriangle() minEnclosingCircle().\n"
1313
<< "Random points are generated and then enclosed.\n\n"
14-
<< "Press ESC, 'q' or 'Q' to exit and any other key to regenerate the set of points.\n\n"
15-
<< "Call:\n"
16-
<< "./minarea\n"
17-
<< "Using OpenCV v" << CV_VERSION << "\n" << endl;
14+
<< "Press ESC, 'q' or 'Q' to exit and any other key to regenerate the set of points.\n\n";
1815
}
1916

2017
int main( int /*argc*/, char** /*argv*/ )
@@ -40,18 +37,18 @@ int main( int /*argc*/, char** /*argv*/ )
4037
}
4138

4239
// Find the minimum area enclosing bounding box
43-
RotatedRect box = minAreaRect(Mat(points));
40+
Point2f vtx[4];
41+
RotatedRect box = minAreaRect(points);
42+
box.points(vtx);
4443

4544
// Find the minimum area enclosing triangle
4645
vector<Point2f> triangle;
47-
4846
minEnclosingTriangle(points, triangle);
4947

5048
// Find the minimum area enclosing circle
51-
Point2f center, vtx[4];
49+
Point2f center;
5250
float radius = 0;
53-
minEnclosingCircle(Mat(points), center, radius);
54-
box.points(vtx);
51+
minEnclosingCircle(points, center, radius);
5552

5653
img = Scalar::all(0);
5754

0 commit comments

Comments
 (0)