2 #pragma package <opencv>
5 #define CV_NO_BACKWARD_COMPATIBILITY
15 int main( int argc, char** argv )
17 IplImage* img = cvCreateImage( cvSize( 500, 500 ), 8, 3 );
19 CvMemStorage* storage = cvCreateMemStorage(0);
22 cvNamedWindow( "rect & circle", 1 );
27 int i, count = rand()%100 + 1;
30 CvPoint2D32f box_vtx[4];
35 CvSeq* ptseq = cvCreateSeq( CV_SEQ_KIND_GENERIC|CV_32SC2, sizeof(CvContour),
36 sizeof(CvPoint), storage );
37 for( i = 0; i < count; i++ )
39 pt0.x = rand() % (img->width/2) + img->width/4;
40 pt0.y = rand() % (img->height/2) + img->height/4;
41 cvSeqPush( ptseq, &pt0 );
43 #ifndef _EiC /* unfortunately, here EiC crashes */
44 box = cvMinAreaRect2( ptseq, 0 );
46 cvMinEnclosingCircle( ptseq, ¢er, &radius );
48 CvPoint* points = (CvPoint*)malloc( count * sizeof(points[0]));
49 CvMat pointMat = cvMat( 1, count, CV_32SC2, points );
51 for( i = 0; i < count; i++ )
53 pt0.x = rand() % (img->width/2) + img->width/4;
54 pt0.y = rand() % (img->height/2) + img->height/4;
58 box = cvMinAreaRect2( &pointMat, 0 );
60 cvMinEnclosingCircle( &pointMat, ¢er, &radius );
62 cvBoxPoints( box, box_vtx );
64 for( i = 0; i < count; i++ )
67 pt0 = *CV_GET_SEQ_ELEM( CvPoint, ptseq, i );
71 cvCircle( img, pt0, 2, CV_RGB( 255, 0, 0 ), CV_FILLED, CV_AA, 0 );
75 pt0.x = cvRound(box_vtx[3].x);
76 pt0.y = cvRound(box_vtx[3].y);
77 for( i = 0; i < 4; i++ )
79 pt.x = cvRound(box_vtx[i].x);
80 pt.y = cvRound(box_vtx[i].y);
81 cvLine(img, pt0, pt, CV_RGB(0, 255, 0), 1, CV_AA, 0);
85 icenter.x = cvRound(center.x);
86 icenter.y = cvRound(center.y);
87 cvCircle( img, icenter, cvRound(radius), CV_RGB(255, 255, 0), 1, CV_AA, 0 );
89 cvShowImage( "rect & circle", img );
91 key = (char) cvWaitKey(0);
92 if( key == 27 || key == 'q' || key == 'Q' ) // 'ESC'
96 cvClearMemStorage( storage );
102 cvDestroyWindow( "rect & circle" );
107 main(1,"convexhull.c");