$darkmode
404 Not Found

404 Not Found


nginx
OpenCV 4.11.0
Open Source Computer Vision
BEGIN_CUSTOM_MATHJAX // END_CUSTOM_MATHJAX
samples/cpp/minarea.cpp
#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();
Mat img(500, 500, CV_8UC3, Scalar::all(0));
RNG& rng = theRNG();
for(;;)
{
int i, count = rng.uniform(1, 101);
vector<Point> points;
// Generate a random set of points
for( i = 0; i < count; i++ )
{
Point pt;
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);
}
// Find the minimum area enclosing bounding box
Point2f vtx[4];
RotatedRect box = minAreaRect(points);
box.points(vtx);
// Find the minimum area enclosing triangle
vector<Point2f> 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++ )
circle( img, points[i], 3, Scalar(0, 0, 255), FILLED, LINE_AA );
// Draw the bounding box
for( i = 0; i < 4; i++ )
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);
imshow( "Rectangle, triangle & circle", img );
char key = (char)waitKey();
if( key == 27 || key == 'q' || key == 'Q' ) // 'ESC'
break;
}
return 0;
}
_Tp x
x coordinate of the point
Definition: modules/core/include/opencv2/core/types.hpp:201
RNG & theRNG()
Returns the default random number generator.
Point2i Point
Definition: modules/core/include/opencv2/core/types.hpp:209
Scalar_< double > Scalar
Definition: modules/core/include/opencv2/core/types.hpp:709
Point_< float > Point2f
Definition: modules/core/include/opencv2/core/types.hpp:207
#define CV_8UC3
Definition: core/include/opencv2/core/hal/interface.h:90
int cvRound(double value)
Rounds floating-point number to the nearest integer.
Definition: fast_math.hpp:200
@ triangle
Definition: gr_skig.hpp:63
@ circle
Definition: gr_skig.hpp:62
void imshow(const String &winname, InputArray mat)
Displays an image in the specified window.
int waitKey(int delay=0)
Waits for a pressed key.
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.
@ LINE_AA
antialiased line
Definition: imgproc/include/opencv2/imgproc.hpp:894
@ FILLED
Definition: imgproc/include/opencv2/imgproc.hpp:891
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 &center, float &radius)
Finds a circle of the minimum area enclosing a 2D point set.
int main(int argc, char *argv[])
Definition: highgui_qt.cpp:3
Definition: core/include/opencv2/core.hpp:107
STL namespace.