1 #include <opencv2/imgproc/imgproc.hpp>
2 #include <opencv2/highgui/highgui.hpp>
8 void on_trackbar(int pos)
10 IplImage* cnt_img = cvCreateImage( cvSize(w,w), 8, 3 );
11 CvSeq* _contours = contours;
12 int _levels = levels - 3;
13 if( _levels <= 0 ) // get to the nearest face to make it look more funny
14 _contours = _contours->h_next->h_next->h_next;
16 cvDrawContours( cnt_img, _contours, CV_RGB(255,0,0), CV_RGB(0,255,0), _levels, 3, CV_AA, cvPoint(0,0) );
17 cvShowImage( "contours", cnt_img );
18 cvReleaseImage( &cnt_img );
21 int main( int argc, char** argv )
24 CvMemStorage* storage = cvCreateMemStorage(0);
25 IplImage* img = cvCreateImage( cvSize(w,w), 8, 1 );
29 for( i=0; i < 6; i++ )
31 int dx = (i%2)*250 - 30;
33 CvScalar white = cvRealScalar(255);
34 CvScalar black = cvRealScalar(0);
38 for( j = 0; j <= 10; j++ )
40 double angle = (j+5)*CV_PI/21;
41 cvLine(img, cvPoint(cvRound(dx+100+j*10-80*cos(angle)),
42 cvRound(dy+100-90*sin(angle))),
43 cvPoint(cvRound(dx+100+j*10-30*cos(angle)),
44 cvRound(dy+100-30*sin(angle))), white, 1, 8, 0);
48 cvEllipse( img, cvPoint(dx+150, dy+100), cvSize(100,70), 0, 0, 360, white, -1, 8, 0 );
49 cvEllipse( img, cvPoint(dx+115, dy+70), cvSize(30,20), 0, 0, 360, black, -1, 8, 0 );
50 cvEllipse( img, cvPoint(dx+185, dy+70), cvSize(30,20), 0, 0, 360, black, -1, 8, 0 );
51 cvEllipse( img, cvPoint(dx+115, dy+70), cvSize(15,15), 0, 0, 360, white, -1, 8, 0 );
52 cvEllipse( img, cvPoint(dx+185, dy+70), cvSize(15,15), 0, 0, 360, white, -1, 8, 0 );
53 cvEllipse( img, cvPoint(dx+115, dy+70), cvSize(5,5), 0, 0, 360, black, -1, 8, 0 );
54 cvEllipse( img, cvPoint(dx+185, dy+70), cvSize(5,5), 0, 0, 360, black, -1, 8, 0 );
55 cvEllipse( img, cvPoint(dx+150, dy+100), cvSize(10,5), 0, 0, 360, black, -1, 8, 0 );
56 cvEllipse( img, cvPoint(dx+150, dy+150), cvSize(40,10), 0, 0, 360, black, -1, 8, 0 );
57 cvEllipse( img, cvPoint(dx+27, dy+100), cvSize(20,35), 0, 0, 360, white, -1, 8, 0 );
58 cvEllipse( img, cvPoint(dx+273, dy+100), cvSize(20,35), 0, 0, 360, white, -1, 8, 0 );
61 cvNamedWindow( "image", 1 );
62 cvShowImage( "image", img );
64 cvFindContours( img, storage, &contours, sizeof(CvContour),
65 CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0) );
67 // comment this out if you do not want approximation
68 contours = cvApproxPoly( contours, sizeof(CvContour), storage, CV_POLY_APPROX_DP, 3, 1 );
70 cvNamedWindow( "contours", 1 );
71 cvCreateTrackbar( "levels+3", "contours", &levels, 7, on_trackbar );
75 cvReleaseMemStorage( &storage );
76 cvReleaseImage( &img );