00001
00002
00003
00004
00005
00006 #ifdef _CH_
00007 #pragma package <opencv>
00008 #endif
00009
00010 #define CV_NO_BACKWARD_COMPATIBILITY
00011
00012 #ifndef _EiC
00013 #include <opencv/cv.h>
00014 #include <opencv/highgui.h>
00015 #include <math.h>
00016 #endif
00017
00018 #define w 500
00019 int levels = 3;
00020 CvSeq* contours = 0;
00021
00022 void on_trackbar(int pos)
00023 {
00024 IplImage* cnt_img = cvCreateImage( cvSize(w,w), 8, 3 );
00025 CvSeq* _contours = contours;
00026 int _levels = levels - 3;
00027 if( _levels <= 0 )
00028 _contours = _contours->h_next->h_next->h_next;
00029 cvZero( cnt_img );
00030 cvDrawContours( cnt_img, _contours, CV_RGB(255,0,0), CV_RGB(0,255,0), _levels, 3, CV_AA, cvPoint(0,0) );
00031 cvShowImage( "contours", cnt_img );
00032 cvReleaseImage( &cnt_img );
00033 }
00034
00035 int main( int argc, char** argv )
00036 {
00037 int i, j;
00038 CvMemStorage* storage = cvCreateMemStorage(0);
00039 IplImage* img = cvCreateImage( cvSize(w,w), 8, 1 );
00040
00041 cvZero( img );
00042
00043 for( i=0; i < 6; i++ )
00044 {
00045 int dx = (i%2)*250 - 30;
00046 int dy = (i/2)*150;
00047 CvScalar white = cvRealScalar(255);
00048 CvScalar black = cvRealScalar(0);
00049
00050 if( i == 0 )
00051 {
00052 for( j = 0; j <= 10; j++ )
00053 {
00054 double angle = (j+5)*CV_PI/21;
00055 cvLine(img, cvPoint(cvRound(dx+100+j*10-80*cos(angle)),
00056 cvRound(dy+100-90*sin(angle))),
00057 cvPoint(cvRound(dx+100+j*10-30*cos(angle)),
00058 cvRound(dy+100-30*sin(angle))), white, 1, 8, 0);
00059 }
00060 }
00061
00062 cvEllipse( img, cvPoint(dx+150, dy+100), cvSize(100,70), 0, 0, 360, white, -1, 8, 0 );
00063 cvEllipse( img, cvPoint(dx+115, dy+70), cvSize(30,20), 0, 0, 360, black, -1, 8, 0 );
00064 cvEllipse( img, cvPoint(dx+185, dy+70), cvSize(30,20), 0, 0, 360, black, -1, 8, 0 );
00065 cvEllipse( img, cvPoint(dx+115, dy+70), cvSize(15,15), 0, 0, 360, white, -1, 8, 0 );
00066 cvEllipse( img, cvPoint(dx+185, dy+70), cvSize(15,15), 0, 0, 360, white, -1, 8, 0 );
00067 cvEllipse( img, cvPoint(dx+115, dy+70), cvSize(5,5), 0, 0, 360, black, -1, 8, 0 );
00068 cvEllipse( img, cvPoint(dx+185, dy+70), cvSize(5,5), 0, 0, 360, black, -1, 8, 0 );
00069 cvEllipse( img, cvPoint(dx+150, dy+100), cvSize(10,5), 0, 0, 360, black, -1, 8, 0 );
00070 cvEllipse( img, cvPoint(dx+150, dy+150), cvSize(40,10), 0, 0, 360, black, -1, 8, 0 );
00071 cvEllipse( img, cvPoint(dx+27, dy+100), cvSize(20,35), 0, 0, 360, white, -1, 8, 0 );
00072 cvEllipse( img, cvPoint(dx+273, dy+100), cvSize(20,35), 0, 0, 360, white, -1, 8, 0 );
00073 }
00074
00075 cvNamedWindow( "image", 1 );
00076 cvShowImage( "image", img );
00077
00078 cvFindContours( img, storage, &contours, sizeof(CvContour),
00079 CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0) );
00080
00081
00082 contours = cvApproxPoly( contours, sizeof(CvContour), storage, CV_POLY_APPROX_DP, 3, 1 );
00083
00084 cvNamedWindow( "contours", 1 );
00085 cvCreateTrackbar( "levels+3", "contours", &levels, 7, on_trackbar );
00086
00087 on_trackbar(0);
00088 cvWaitKey(0);
00089 cvReleaseMemStorage( &storage );
00090 cvReleaseImage( &img );
00091
00092 return 0;
00093 }
00094
00095 #ifdef _EiC
00096 main(1,"");
00097 #endif