#include <math.h>
#include <iostream>
static void help(char** argv)
{
cout
<< "\nThis program illustrates the use of findContours and drawContours\n"
<< "The original image is put up along with the image of drawn contours\n"
<< "Usage:\n";
cout
<< argv[0]
<< "\nA trackbar is put up which controls the contour level from -3 to 3\n"
<< endl;
}
const int w = 500;
int levels = 3;
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
static void on_trackbar(int, void*)
{
Mat cnt_img = Mat::zeros(w, w,
CV_8UC3);
int _levels = levels - 3;
}
int main(
int argc,
char** argv)
{
if (parser.has("help"))
{
help(argv);
return 0;
}
Mat img = Mat::zeros(w, w,
CV_8UC1);
for( int i = 0; i < 6; i++ )
{
int dx = (i%2)*250 - 30;
int dy = (i/2)*150;
if( i == 0 )
{
for( int j = 0; j <= 10; j++ )
{
double angle = (j+5)*
CV_PI/21;
}
}
ellipse( img,
Point(dx+150, dy+100),
Size(100,70), 0, 0, 360, white, -1, 8, 0 );
ellipse( img,
Point(dx+115, dy+70),
Size(30,20), 0, 0, 360, black, -1, 8, 0 );
ellipse( img,
Point(dx+185, dy+70),
Size(30,20), 0, 0, 360, black, -1, 8, 0 );
ellipse( img,
Point(dx+115, dy+70),
Size(15,15), 0, 0, 360, white, -1, 8, 0 );
ellipse( img,
Point(dx+185, dy+70),
Size(15,15), 0, 0, 360, white, -1, 8, 0 );
ellipse( img,
Point(dx+115, dy+70),
Size(5,5), 0, 0, 360, black, -1, 8, 0 );
ellipse( img,
Point(dx+185, dy+70),
Size(5,5), 0, 0, 360, black, -1, 8, 0 );
ellipse( img,
Point(dx+150, dy+100),
Size(10,5), 0, 0, 360, black, -1, 8, 0 );
ellipse( img,
Point(dx+150, dy+150),
Size(40,10), 0, 0, 360, black, -1, 8, 0 );
ellipse( img,
Point(dx+27, dy+100),
Size(20,35), 0, 0, 360, white, -1, 8, 0 );
ellipse( img,
Point(dx+273, dy+100),
Size(20,35), 0, 0, 360, white, -1, 8, 0 );
}
vector<vector<Point> > contours0;
contours.resize(contours0.size());
for( size_t k = 0; k < contours0.size(); k++ )
on_trackbar(0,0);
return 0;
}
Designed for command line parsing.
Definition: utility.hpp:890
Point2i Point
Definition: modules/core/include/opencv2/core/types.hpp:209
Size2i Size
Definition: modules/core/include/opencv2/core/types.hpp:370
Scalar_< double > Scalar
Definition: modules/core/include/opencv2/core/types.hpp:709
#define CV_8UC1
Definition: core/include/opencv2/core/hal/interface.h:88
#define CV_8UC3
Definition: core/include/opencv2/core/hal/interface.h:90
Quat< T > cos(const Quat< T > &q)
Quat< T > sin(const Quat< T > &q)
int cvRound(double value)
Rounds floating-point number to the nearest integer.
Definition: fast_math.hpp:200
#define CV_PI
Definition: cvdef.h:380
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 namedWindow(const String &winname, int flags=WINDOW_AUTOSIZE)
Creates a window.
int createTrackbar(const String &trackbarname, const String &winname, int *value, int count, TrackbarCallback onChange=0, void *userdata=0)
Creates a trackbar and attaches it to the specified window.
void ellipse(InputOutputArray img, Point center, Size axes, double angle, double startAngle, double endAngle, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
Draws a simple or thick elliptic arc or fills an ellipse sector.
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.
void drawContours(InputOutputArray image, InputArrayOfArrays contours, int contourIdx, const Scalar &color, int thickness=1, int lineType=LINE_8, InputArray hierarchy=noArray(), int maxLevel=INT_MAX, Point offset=Point())
Draws contours outlines or filled contours.
@ LINE_AA
antialiased line
Definition: imgproc/include/opencv2/imgproc.hpp:894
void approxPolyDP(InputArray curve, OutputArray approxCurve, double epsilon, bool closed)
Approximates a polygonal curve(s) with the specified precision.
void findContours(InputArray image, OutputArrayOfArrays contours, OutputArray hierarchy, int mode, int method, Point offset=Point())
Finds contours in a binary image.
@ CHAIN_APPROX_SIMPLE
Definition: imgproc/include/opencv2/imgproc.hpp:446
@ RETR_TREE
Definition: imgproc/include/opencv2/imgproc.hpp:434
int main(int argc, char *argv[])
Definition: highgui_qt.cpp:3
Definition: core/include/opencv2/core.hpp:107
static uchar abs(uchar a)
Definition: cvstd.hpp:66