Skip to content

Commit

Permalink
Changed the signature of the minEnclosingTriangle function such that …
Browse files Browse the repository at this point in the history
…it returns the area automatically. Moreover, the overloaded function was no longer required so it was removed. Sample code, documentation and unit tests were updated correspondingly.
  • Loading branch information
ovidiuparvu committed Sep 19, 2013
1 parent 52cdae6 commit e324446
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 33 deletions.
14 changes: 4 additions & 10 deletions modules/imgproc/doc/structural_analysis_and_shape_descriptors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -562,15 +562,11 @@ The function finds the four vertices of a rotated rectangle. This function is us

minEnclosingTriangle
----------------------
Finds a triangle of minimum area enclosing a 2D point set.
Finds a triangle of minimum area enclosing a 2D point set and returns its area.

.. ocv:function:: void minEnclosingTriangle( InputArray points, OutputArray triangle )
.. ocv:function:: double minEnclosingTriangle( InputArray points, OutputArray triangle )
.. ocv:function:: void minEnclosingTriangle( InputArray points, OutputArray triangle, double &area )
.. ocv:pyfunction:: cv2.minEnclosingTriangle(points[, triangle]) -> triangle
.. ocv:pyfunction:: cv2.minEnclosingTriangle(points[, triangle]) -> triangle, area
.. ocv:pyfunction:: cv2.minEnclosingTriangle(points[, triangle]) -> retval, triangle
:param points: Input vector of 2D points with depth ``CV_32S`` or ``CV_32F``, stored in:

Expand All @@ -580,9 +576,7 @@ Finds a triangle of minimum area enclosing a 2D point set.

:param triangle: Output vector of three 2D points defining the vertices of the triangle. The depth of the OutputArray must be ``CV_32F``.

:param area: The area of the minimum enclosing triangle.

The output for a given 2D point set is shown in the image below. The 2D points are depicted in *red* and the enclosing triangle in *yellow*.
The function finds a triangle of minimum area enclosing the given set of 2D points and returns its area. The output for a given 2D point set is shown in the image below. 2D points are depicted in *red* and the enclosing triangle in *yellow*.

.. image:: pics/minenclosingtriangle.png
:height: 250px
Expand Down
9 changes: 2 additions & 7 deletions modules/imgproc/include/opencv2/imgproc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1451,13 +1451,8 @@ CV_EXPORTS_W void boxPoints(RotatedRect box, OutputArray points);
CV_EXPORTS_W void minEnclosingCircle( InputArray points,
CV_OUT Point2f& center, CV_OUT float& radius );

//! computes the minimal enclosing triangle for a set of points
CV_EXPORTS_W void minEnclosingTriangle( InputArray points,
CV_OUT OutputArray triangle );

//! computes the minimal enclosing triangle for a set of points
CV_EXPORTS_W void minEnclosingTriangle( InputArray points,
CV_OUT OutputArray triangle, CV_OUT double& area );
//! computes the minimal enclosing triangle for a set of points and returns its area
CV_EXPORTS_W double minEnclosingTriangle( InputArray points, CV_OUT OutputArray triangle );

//! matches two contours using one of the available algorithms
CV_EXPORTS_W double matchShapes( InputArray contour1, InputArray contour2,
Expand Down
18 changes: 4 additions & 14 deletions modules/imgproc/src/min_enclosing_triangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,27 +269,17 @@ static void updateSidesCA();
///////////////////////////////////// Main functions /////////////////////////////////////


//! Find the minimum enclosing triangle and its area for the given set of points
//! Find the minimum enclosing triangle for the given set of points and return its area
/*!
* @param points Set of points
* @param triangle Minimum area triangle enclosing the given set of points
* @param area Area of the minimum area enclosing triangle
*/
void cv::minEnclosingTriangle(cv::InputArray points,
CV_OUT cv::OutputArray triangle, CV_OUT double &area) {
minEnclosingTriangle::findMinEnclosingTriangle(points, triangle, area);
}

//! Find the minimum enclosing triangle and its area for the given set of points
/*!
* @param points Set of points
* @param triangle Minimum area triangle enclosing the given set of points
*/
void cv::minEnclosingTriangle(cv::InputArray points,
CV_OUT cv::OutputArray triangle) {
double cv::minEnclosingTriangle(cv::InputArray points, CV_OUT cv::OutputArray triangle) {
double area;

minEnclosingTriangle::findMinEnclosingTriangle(points, triangle, area);

return area;
}


Expand Down
3 changes: 1 addition & 2 deletions modules/imgproc/test/test_convhull.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,6 @@ class CV_MinTriangleTest : public CV_BaseShapeDescrTest

std::vector<cv::Point2f> convexPolygon;
std::vector<cv::Point2f> triangle;
double area;
};


Expand All @@ -827,7 +826,7 @@ void CV_MinTriangleTest::run_func()

cv::cvarrToMat(points).convertTo(pointsAsVector, CV_32F);

cv::minEnclosingTriangle(pointsAsVector, triangle, area);
cv::minEnclosingTriangle(pointsAsVector, triangle);
cv::convexHull(pointsAsVector, convexPolygon, true, true);
}

Expand Down

0 comments on commit e324446

Please sign in to comment.