/** @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
*/
/** @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.
@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 );
static double areaOfTriangle(const cv::Point2f &a, const cv::Point2f &b, const cv::Point2f &c);
-static void copyResultingTriangle(const std::vector<cv::Point2f> &resultingTriangle, cv::OutputArray triangle);
-
static void createConvexHull(cv::InputArray points, std::vector<cv::Point2f> &polygon);
static double distanceBtwPoints(const cv::Point2f &a, const cv::Point2f &b);
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
}
}
-//! 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<cv::Point2f> &resultingTriangle,
- cv::OutputArray triangle) {
- cv::Mat(resultingTriangle).copyTo(triangle);
-}
-
//! Initialisation function
/*!
* @param triangle Minimum area triangle enclosing the given polygon
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*/ )
}
// 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<Point2f> triangle;
-
+ vector<Point> 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);