 |
OpenCV
3.2.0
Open Source Computer Vision
|
#include <iostream>
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"
<< "Call:\n"
<< "./minarea\n"
<<
"Using OpenCV v" <<
CV_VERSION <<
"\n" << endl;
}
int main( int , char** )
{
help();
for(;;)
{
vector<Point> points;
for(
i = 0;
i < count;
i++ )
{
pt.
x = rng.
uniform(img.cols/4, img.cols*3/4);
pt.
y = rng.
uniform(img.rows/4, img.rows*3/4);
points.push_back(pt);
}
float radius = 0;
for(
i = 0;
i < count;
i++ )
imshow(
"Rectangle, triangle & circle", img );
if( key == 27 || key == 'q' || key == 'Q' )
break;
}
return 0;
}
int uniform(int a, int b)
returns uniformly distributed integer random number from [a,b) range
static Scalar_< double > all(double v0)
returns a scalar with all elements set to v0
RNG & theRNG()
Returns the default random number generator.
@ FILLED
Definition: core.hpp:215
@ triangle
Definition: gr_skig.hpp:63
void minEnclosingCircle(InputArray points, Point2f ¢er, float &radius)
Finds a circle of the minimum area enclosing a 2D point set.
int waitKey(int delay=0)
Waits for a pressed key.
_Tp y
Definition: types.hpp:176
RotatedRect minAreaRect(InputArray points)
Finds a rotated rectangle of the minimum area enclosing the input 2D point set.
_Tp x
Definition: types.hpp:176
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.
#define CV_8UC3
Definition: interface.h:84
#define CV_VERSION
Definition: version.hpp:64
The class represents rotated (i.e. not up-right) rectangles on a plane.
Definition: types.hpp:465
int cvRound(double value)
Rounds floating-point number to the nearest integer.
Definition: fast_math.hpp:93
@ LINE_AA
antialiased line
Definition: core.hpp:218
void imshow(const String &winname, InputArray mat)
Displays an image in the specified window.
void points(Point2f pts[]) const
Scalar_< double > Scalar
Definition: types.hpp:606
Random Number Generator.
Definition: core.hpp:2690
n-dimensional dense array class
Definition: mat.hpp:741
for i
Definition: modelConvert.m:63
double minEnclosingTriangle(InputArray points, OutputArray triangle)
Finds a triangle of minimum area enclosing a 2D point set and returns its area.
Definition: affine.hpp:52
void circle(InputOutputArray img, Point center, int radius, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
Draws a circle.