From b2673a19cf7d3f92d04a50979c90dfee88060850 Mon Sep 17 00:00:00 2001 From: Suleyman TURKMEN Date: Sun, 8 Oct 2017 13:22:13 +0300 Subject: [PATCH 1/4] Updates min_enclosing_triangle.cpp --- modules/imgproc/include/opencv2/imgproc.hpp | 10 ++++------ .../imgproc/src/min_enclosing_triangle.cpp | 19 ++++++------------- samples/cpp/minarea.cpp | 17 +++++++---------- 3 files changed, 17 insertions(+), 29 deletions(-) diff --git a/modules/imgproc/include/opencv2/imgproc.hpp b/modules/imgproc/include/opencv2/imgproc.hpp index 076af528b0..7e47e2aa3a 100644 --- a/modules/imgproc/include/opencv2/imgproc.hpp +++ b/modules/imgproc/include/opencv2/imgproc.hpp @@ -3920,9 +3920,8 @@ CV_EXPORTS_W double contourArea( InputArray contour, bool oriented = false ); /** @brief Finds a rotated rectangle of the minimum area enclosing the input 2D point set. The function calculates and returns the minimum-area bounding rectangle (possibly rotated) for a -specified point set. See the OpenCV sample minarea.cpp . Developer should keep in mind that the -returned rotatedRect can contain negative indices when data is close to the containing Mat element -boundary. +specified point set. Developer should keep in mind that the returned RotatedRect can contain negative +indices when data is close to the containing Mat element boundary. @param points Input vector of 2D points, stored in std::vector\<\> or Mat */ @@ -3943,8 +3942,7 @@ CV_EXPORTS_W void boxPoints(RotatedRect box, OutputArray points); /** @brief Finds a circle of the minimum area enclosing a 2D point set. -The function finds the minimal enclosing circle of a 2D point set using an iterative algorithm. See -the OpenCV sample minarea.cpp . +The function finds the minimal enclosing circle of a 2D point set using an iterative algorithm. @param points Input vector of 2D points, stored in std::vector\<\> or Mat @param center Output center of the circle. @@ -3973,7 +3971,7 @@ than \f$\theta(n)\f$. Thus the overall complexity of the function is \f$O(n log( @param points Input vector of 2D points with depth CV_32S or CV_32F, stored in std::vector\<\> or Mat @param triangle Output vector of three 2D points defining the vertices of the triangle. The depth -of the OutputArray must be CV_32F. +of the OutputArray could be CV_32S or CV_32F. */ CV_EXPORTS_W double minEnclosingTriangle( InputArray points, CV_OUT OutputArray triangle ); diff --git a/modules/imgproc/src/min_enclosing_triangle.cpp b/modules/imgproc/src/min_enclosing_triangle.cpp index ed4d5b97d8..702d148c10 100644 --- a/modules/imgproc/src/min_enclosing_triangle.cpp +++ b/modules/imgproc/src/min_enclosing_triangle.cpp @@ -129,8 +129,6 @@ static bool areOnTheSameSideOfLine(const cv::Point2f &p1, const cv::Point2f &p2, static double areaOfTriangle(const cv::Point2f &a, const cv::Point2f &b, const cv::Point2f &c); -static void copyResultingTriangle(const std::vector &resultingTriangle, cv::OutputArray triangle); - static void createConvexHull(cv::InputArray points, std::vector &polygon); static double distanceBtwPoints(const cv::Point2f &a, const cv::Point2f &b); @@ -324,7 +322,12 @@ static void findMinEnclosingTriangle(cv::InputArray points, createConvexHull(points, polygon); findMinEnclosingTriangle(polygon, resultingTriangle, area); - copyResultingTriangle(resultingTriangle, triangle); + + if (triangle.depth() == CV_32S) { + cv::Mat(resultingTriangle).convertTo(triangle,CV_32S); + } else { + cv::Mat(resultingTriangle).copyTo(triangle); + } } //! Create the convex hull of the given set of points @@ -364,16 +367,6 @@ static void findMinEnclosingTriangle(const std::vector &polygon, } } -//! 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 returned to the user -*/ -static void copyResultingTriangle(const std::vector &resultingTriangle, - cv::OutputArray triangle) { - cv::Mat(resultingTriangle).copyTo(triangle); -} - //! Initialisation function /*! * @param triangle Minimum area triangle enclosing the given polygon diff --git a/samples/cpp/minarea.cpp b/samples/cpp/minarea.cpp index ac79db5e5a..6f3c50fc45 100644 --- a/samples/cpp/minarea.cpp +++ b/samples/cpp/minarea.cpp @@ -11,10 +11,7 @@ static void help() cout << "This program demonstrates finding the minimum enclosing box, triangle or circle of a set\n" << "of points using functions: minAreaRect() minEnclosingTriangle() minEnclosingCircle().\n" << "Random points are generated and then enclosed.\n\n" - << "Press ESC, 'q' or 'Q' to exit and any other key to regenerate the set of points.\n\n" - << "Call:\n" - << "./minarea\n" - << "Using OpenCV v" << CV_VERSION << "\n" << endl; + << "Press ESC, 'q' or 'Q' to exit and any other key to regenerate the set of points.\n\n"; } int main( int /*argc*/, char** /*argv*/ ) @@ -40,18 +37,18 @@ int main( int /*argc*/, char** /*argv*/ ) } // Find the minimum area enclosing bounding box - RotatedRect box = minAreaRect(Mat(points)); + Point2f vtx[4]; + RotatedRect box = minAreaRect(points); + box.points(vtx); // Find the minimum area enclosing triangle - vector triangle; - + vector triangle; minEnclosingTriangle(points, triangle); // Find the minimum area enclosing circle - Point2f center, vtx[4]; + Point2f center; float radius = 0; - minEnclosingCircle(Mat(points), center, radius); - box.points(vtx); + minEnclosingCircle(points, center, radius); img = Scalar::all(0); From baf9e32af3d031ebf875ae0eada695013eed50e5 Mon Sep 17 00:00:00 2001 From: Suleyman TURKMEN Date: Wed, 11 Oct 2017 17:37:38 +0300 Subject: [PATCH 2/4] Update imgproc.hpp --- modules/imgproc/include/opencv2/imgproc.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/imgproc/include/opencv2/imgproc.hpp b/modules/imgproc/include/opencv2/imgproc.hpp index 7e47e2aa3a..7dafcc004d 100644 --- a/modules/imgproc/include/opencv2/imgproc.hpp +++ b/modules/imgproc/include/opencv2/imgproc.hpp @@ -3971,7 +3971,7 @@ than \f$\theta(n)\f$. Thus the overall complexity of the function is \f$O(n log( @param points Input vector of 2D points with depth CV_32S or CV_32F, stored in std::vector\<\> or Mat @param triangle Output vector of three 2D points defining the vertices of the triangle. The depth -of the OutputArray could be CV_32S or CV_32F. +of the OutputArray must be CV_32F. */ CV_EXPORTS_W double minEnclosingTriangle( InputArray points, CV_OUT OutputArray triangle ); From 29c186a02214a080b55cf47a756fbc06cd4f35b4 Mon Sep 17 00:00:00 2001 From: Suleyman TURKMEN Date: Wed, 11 Oct 2017 17:48:19 +0300 Subject: [PATCH 3/4] Update min_enclosing_triangle.cpp --- modules/imgproc/src/min_enclosing_triangle.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/modules/imgproc/src/min_enclosing_triangle.cpp b/modules/imgproc/src/min_enclosing_triangle.cpp index 702d148c10..2e043621c0 100644 --- a/modules/imgproc/src/min_enclosing_triangle.cpp +++ b/modules/imgproc/src/min_enclosing_triangle.cpp @@ -322,12 +322,7 @@ static void findMinEnclosingTriangle(cv::InputArray points, createConvexHull(points, polygon); findMinEnclosingTriangle(polygon, resultingTriangle, area); - - if (triangle.depth() == CV_32S) { - cv::Mat(resultingTriangle).convertTo(triangle,CV_32S); - } else { - cv::Mat(resultingTriangle).copyTo(triangle); - } + cv::Mat(resultingTriangle).copyTo(triangle); } //! Create the convex hull of the given set of points From af9c8377ebadfbf5ecab2ec69b311a231b3f4b0a Mon Sep 17 00:00:00 2001 From: Suleyman TURKMEN Date: Wed, 11 Oct 2017 17:52:23 +0300 Subject: [PATCH 4/4] Update minarea.cpp --- samples/cpp/minarea.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/cpp/minarea.cpp b/samples/cpp/minarea.cpp index 6f3c50fc45..133b684e69 100644 --- a/samples/cpp/minarea.cpp +++ b/samples/cpp/minarea.cpp @@ -42,7 +42,7 @@ int main( int /*argc*/, char** /*argv*/ ) box.points(vtx); // Find the minimum area enclosing triangle - vector triangle; + vector triangle; minEnclosingTriangle(points, triangle); // Find the minimum area enclosing circle