Optimised one assert statement in the min_enclosing_triangle.cpp file. Added the minEnclosingTriangle functionality to the existing minarea.cpp sample file.
This commit is contained in:
parent
9902affae6
commit
0ed2f6201d
@ -273,7 +273,7 @@ void cv::minEnclosingTriangle(cv::InputArray points,
|
|||||||
CV_OUT cv::OutputArray triangle, CV_OUT double& area) {
|
CV_OUT cv::OutputArray triangle, CV_OUT double& area) {
|
||||||
std::vector<cv::Point2f> resultingTriangle;
|
std::vector<cv::Point2f> resultingTriangle;
|
||||||
|
|
||||||
CV_Assert(triangle.getMat().depth() == CV_32F);
|
CV_Assert(triangle.depth() == CV_32F);
|
||||||
|
|
||||||
createConvexHull(points);
|
createConvexHull(points);
|
||||||
findMinEnclosingTriangle(resultingTriangle, area);
|
findMinEnclosingTriangle(resultingTriangle, area);
|
||||||
|
@ -8,12 +8,13 @@ using namespace std;
|
|||||||
|
|
||||||
static void help()
|
static void help()
|
||||||
{
|
{
|
||||||
cout << "This program demonstrates finding the minimum enclosing box or circle of a set\n"
|
cout << "This program demonstrates finding the minimum enclosing box, triangle or circle of a set\n"
|
||||||
"of points using functions: minAreaRect() minEnclosingCircle().\n"
|
<< "of points using functions: minAreaRect() minEnclosingTriangle() minEnclosingCircle().\n"
|
||||||
"Random points are generated and then enclosed.\n"
|
<< "Random points are generated and then enclosed.\n\n"
|
||||||
"Call:\n"
|
<< "Press ESC, 'q' or 'Q' to exit and any other key to regenerate the set of points.\n\n"
|
||||||
"./minarea\n"
|
<< "Call:\n"
|
||||||
"Using OpenCV v" << CV_VERSION << "\n" << endl;
|
<< "./minarea\n"
|
||||||
|
<< "Using OpenCV v" << CV_VERSION << "\n" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main( int /*argc*/, char** /*argv*/ )
|
int main( int /*argc*/, char** /*argv*/ )
|
||||||
@ -27,6 +28,8 @@ int main( int /*argc*/, char** /*argv*/ )
|
|||||||
{
|
{
|
||||||
int i, count = rng.uniform(1, 101);
|
int i, count = rng.uniform(1, 101);
|
||||||
vector<Point> points;
|
vector<Point> points;
|
||||||
|
|
||||||
|
// Generate a random set of points
|
||||||
for( i = 0; i < count; i++ )
|
for( i = 0; i < count; i++ )
|
||||||
{
|
{
|
||||||
Point pt;
|
Point pt;
|
||||||
@ -36,23 +39,39 @@ int main( int /*argc*/, char** /*argv*/ )
|
|||||||
points.push_back(pt);
|
points.push_back(pt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Find the minimum area enclosing bounding box
|
||||||
RotatedRect box = minAreaRect(Mat(points));
|
RotatedRect box = minAreaRect(Mat(points));
|
||||||
|
|
||||||
|
// Find the minimum area enclosing triangle
|
||||||
|
vector<Point2f> triangle;
|
||||||
|
double area;
|
||||||
|
|
||||||
|
minEnclosingTriangle(points, triangle, area);
|
||||||
|
|
||||||
|
// Find the minimum area enclosing circle
|
||||||
Point2f center, vtx[4];
|
Point2f center, vtx[4];
|
||||||
float radius = 0;
|
float radius = 0;
|
||||||
minEnclosingCircle(Mat(points), center, radius);
|
minEnclosingCircle(Mat(points), center, radius);
|
||||||
box.points(vtx);
|
box.points(vtx);
|
||||||
|
|
||||||
img = Scalar::all(0);
|
img = Scalar::all(0);
|
||||||
|
|
||||||
|
// Draw the points
|
||||||
for( i = 0; i < count; i++ )
|
for( i = 0; i < count; i++ )
|
||||||
circle( img, points[i], 3, Scalar(0, 0, 255), FILLED, LINE_AA );
|
circle( img, points[i], 3, Scalar(0, 0, 255), FILLED, LINE_AA );
|
||||||
|
|
||||||
|
// Draw the bounding box
|
||||||
for( i = 0; i < 4; i++ )
|
for( i = 0; i < 4; i++ )
|
||||||
line(img, vtx[i], vtx[(i+1)%4], Scalar(0, 255, 0), 1, LINE_AA);
|
line(img, vtx[i], vtx[(i+1)%4], Scalar(0, 255, 0), 1, LINE_AA);
|
||||||
|
|
||||||
|
// Draw the triangle
|
||||||
|
for( i = 0; i < 3; i++ )
|
||||||
|
line(img, triangle[i], triangle[(i+1)%3], Scalar(255, 255, 0), 1, LINE_AA);
|
||||||
|
|
||||||
|
// Draw the circle
|
||||||
circle(img, center, cvRound(radius), Scalar(0, 255, 255), 1, LINE_AA);
|
circle(img, center, cvRound(radius), Scalar(0, 255, 255), 1, LINE_AA);
|
||||||
|
|
||||||
imshow( "rect & circle", img );
|
imshow( "Rectangle, triangle & circle", img );
|
||||||
|
|
||||||
char key = (char)waitKey();
|
char key = (char)waitKey();
|
||||||
if( key == 27 || key == 'q' || key == 'Q' ) // 'ESC'
|
if( key == 27 || key == 'q' || key == 'Q' ) // 'ESC'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user