From e324446c70e119b6f31955342cfc7bf5f03b2db8 Mon Sep 17 00:00:00 2001 From: Ovidiu Parvu Date: Thu, 19 Sep 2013 16:22:30 +0100 Subject: [PATCH] Changed the signature of the minEnclosingTriangle function such that 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. --- ...ructural_analysis_and_shape_descriptors.rst | 14 ++++---------- modules/imgproc/include/opencv2/imgproc.hpp | 9 ++------- modules/imgproc/src/min_enclosing_triangle.cpp | 18 ++++-------------- modules/imgproc/test/test_convhull.cpp | 3 +-- 4 files changed, 11 insertions(+), 33 deletions(-) diff --git a/modules/imgproc/doc/structural_analysis_and_shape_descriptors.rst b/modules/imgproc/doc/structural_analysis_and_shape_descriptors.rst index 7dc3ef0b27..094424178f 100644 --- a/modules/imgproc/doc/structural_analysis_and_shape_descriptors.rst +++ b/modules/imgproc/doc/structural_analysis_and_shape_descriptors.rst @@ -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: @@ -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 diff --git a/modules/imgproc/include/opencv2/imgproc.hpp b/modules/imgproc/include/opencv2/imgproc.hpp index cb3713af82..cc64174cf2 100644 --- a/modules/imgproc/include/opencv2/imgproc.hpp +++ b/modules/imgproc/include/opencv2/imgproc.hpp @@ -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, diff --git a/modules/imgproc/src/min_enclosing_triangle.cpp b/modules/imgproc/src/min_enclosing_triangle.cpp index a952fe46ec..df2d75490f 100644 --- a/modules/imgproc/src/min_enclosing_triangle.cpp +++ b/modules/imgproc/src/min_enclosing_triangle.cpp @@ -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; } diff --git a/modules/imgproc/test/test_convhull.cpp b/modules/imgproc/test/test_convhull.cpp index 7e1f02bb10..9e4cd07c44 100644 --- a/modules/imgproc/test/test_convhull.cpp +++ b/modules/imgproc/test/test_convhull.cpp @@ -801,7 +801,6 @@ protected: std::vector convexPolygon; std::vector triangle; - double area; }; @@ -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); }