Loading...
Searching...
No Matches
samples/cpp/minarea.cpp
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include <iostream>
using namespace cv;
using namespace std;
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";
}
int main( int /*argc*/, char** /*argv*/ )
{
help();
RNG& rng = theRNG();
for(;;)
{
vector<Point> points;
// Generate a random set of points
for( i = 0; i < count; i++ )
{
Point pt;
points.push_back(pt);
}
// Find the minimum area enclosing bounding box
Point2f vtx[4];
box.points(vtx);
// Find the minimum area enclosing triangle
vector<Point2f> triangle;
minEnclosingTriangle(points, triangle);
// Find the minimum area enclosing circle
Point2f center;
float radius = 0;
minEnclosingCircle(points, center, radius);
img = Scalar::all(0);
// Draw the points
for( i = 0; i < count; i++ )
// Draw the bounding box
for( i = 0; i < 4; i++ )
// Draw the triangle
for( i = 0; i < 3; i++ )
// Draw the circle
imshow( "Rectangle, triangle & circle", img );
char key = (char)waitKey();
if( key == 27 || key == 'q' || key == 'Q' ) // 'ESC'
break;
}
return 0;
}
int uniform(int a, int b)
returns uniformly distributed integer random number from [a,b) range
The class represents rotated (i.e. not up-right) rectangles on a plane.
Definition: types.hpp:531
void points(Point2f pts[]) const
int cvRound(double value)
Rounds floating-point number to the nearest integer.
Definition: fast_math.hpp:200
void imshow(const String &winname, InputArray mat)
Displays an image in the specified window.
void line(InputOutputArray img, Point pt1, Point pt2, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
Draws a line segment connecting two points.
double minEnclosingTriangle(InputArray points, OutputArray triangle)
Finds a triangle of minimum area enclosing a 2D point set and returns its area.
RotatedRect minAreaRect(InputArray points)
Finds a rotated rectangle of the minimum area enclosing the input 2D point set.
void minEnclosingCircle(InputArray points, Point2f ¢er, float &radius)
Finds a circle of the minimum area enclosing a 2D point set.
"black box" representation of the file storage associated with a file on disk.
Definition: core.hpp:106
STL namespace.