diff --git a/modules/imgproc/include/opencv2/imgproc.hpp b/modules/imgproc/include/opencv2/imgproc.hpp index c09afe9f8d..cb3713af82 100644 --- a/modules/imgproc/include/opencv2/imgproc.hpp +++ b/modules/imgproc/include/opencv2/imgproc.hpp @@ -1451,6 +1451,10 @@ 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 ); diff --git a/modules/imgproc/src/min_enclosing_triangle.cpp b/modules/imgproc/src/min_enclosing_triangle.cpp index 3d89f473cc..ddf175c428 100644 --- a/modules/imgproc/src/min_enclosing_triangle.cpp +++ b/modules/imgproc/src/min_enclosing_triangle.cpp @@ -170,6 +170,9 @@ static bool findGammaIntersectionPoints(unsigned int polygonPointIndex, const cv const cv::Point2f &side2EndVertex, cv::Point2f &intersectionPoint1, cv::Point2f &intersectionPoint2); +static void findMinEnclosingTriangle(cv::InputArray points, + CV_OUT cv::OutputArray triangle, CV_OUT double& area); + static void findMinEnclosingTriangle(std::vector &triangle, double& area); static void findMinimumAreaEnclosingTriangle(std::vector &triangle, double &area); @@ -262,15 +265,39 @@ static void updateSidesCA(); //! Find the minimum enclosing triangle and its area for the given set of points /*! -* The overall complexity of the algorithm is theta(n) where "n" represents the number -* of vertices in the convex hull of the points -* * @param points Set of points -* @param triangle Minimum area triangle enclosing the given polygon +* @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) { + 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 area; + + findMinEnclosingTriangle(points, triangle, area); +} + + +/////////////////////////////// Helper functions definition ////////////////////////////// + + +//! Find the minimum enclosing triangle and 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 +*/ +static void findMinEnclosingTriangle(cv::InputArray points, + CV_OUT cv::OutputArray triangle, CV_OUT double& area) { std::vector resultingTriangle; CV_Assert(triangle.depth() == CV_32F); @@ -280,10 +307,6 @@ void cv::minEnclosingTriangle(cv::InputArray points, copyResultingTriangle(resultingTriangle, triangle); } - -/////////////////////////////// Helper functions definition ////////////////////////////// - - //! Create the convex hull of the given set of points /*! * @param points The provided set of points @@ -319,12 +342,20 @@ static void findMinEnclosingTriangle( std::vector &triangle, double } //! Copy resultingTriangle to the OutputArray triangle +/*! +* @param resultingTriangle Minimum area triangle enclosing the given polygon found by the algorithm +* @param triangle Minimum area triangle enclosing the given polygon return to the user +*/ static void copyResultingTriangle(const std::vector &resultingTriangle, cv::OutputArray triangle) { cv::Mat(resultingTriangle).convertTo(triangle, triangle.fixedType() ? triangle.type() : CV_32F); } //! Initialisation function +/*! +* @param triangle Minimum area triangle enclosing the given polygon +* @param area Area of the minimum area enclosing triangle +*/ static void initialise(std::vector &triangle, double &area) { nrOfPoints = static_cast(polygon.size()); area = std::numeric_limits::max(); diff --git a/samples/cpp/minarea.cpp b/samples/cpp/minarea.cpp index 6837dc70d8..91ad5a37bf 100644 --- a/samples/cpp/minarea.cpp +++ b/samples/cpp/minarea.cpp @@ -44,9 +44,8 @@ int main( int /*argc*/, char** /*argv*/ ) // Find the minimum area enclosing triangle vector triangle; - double area; - minEnclosingTriangle(points, triangle, area); + minEnclosingTriangle(points, triangle); // Find the minimum area enclosing circle Point2f center, vtx[4];