drawing.c

Przykład użycia funkcji cvDestroyWindow

00001 #ifdef _CH_
00002 #pragma package <opencv>
00003 #endif
00004 
00005 #ifndef _EiC
00006 #include "cv.h"
00007 #include "highgui.h"
00008 #include <stdlib.h>
00009 #include <stdio.h>
00010 #endif
00011 
00012 #define NUMBER 100
00013 #define DELAY 5
00014 char wndname[] = "Drawing Demo";
00015 
00016 CvScalar random_color(CvRNG* rng)
00017 {
00018     int icolor = cvRandInt(rng);
00019     return CV_RGB(icolor&255, (icolor>>8)&255, (icolor>>16)&255);
00020 }
00021 
00022 int main( int argc, char** argv )
00023 {
00024     int line_type = CV_AA; // change it to 8 to see non-antialiased graphics
00025     int i;
00026     CvPoint pt1,pt2;
00027     double angle;
00028     CvSize sz;
00029     CvPoint  ptt[6];
00030     CvPoint* pt[2];
00031     int  arr[2];
00032     CvFont font;
00033     CvRNG rng;
00034     int width = 1000, height = 700;
00035     int width3 = width*3, height3 = height*3;
00036     CvSize text_size;
00037     int ymin = 0;
00038     // Load the source image
00039     IplImage* image = cvCreateImage( cvSize(width,height), 8, 3 );
00040     IplImage* image2;
00041 
00042     // Create a window
00043     cvNamedWindow(wndname, 1 );
00044     cvZero( image );
00045     cvShowImage(wndname,image);
00046 
00047     rng = cvRNG((unsigned)-1);
00048     pt[0] = &(ptt[0]);
00049     pt[1] = &(ptt[3]);
00050 
00051     arr[0] = 3;
00052     arr[1] = 3;
00053 
00054     for (i = 0; i< NUMBER; i++)
00055     {
00056         pt1.x=cvRandInt(&rng) % width3 - width;
00057         pt1.y=cvRandInt(&rng) % height3 - height;
00058         pt2.x=cvRandInt(&rng) % width3 - width;
00059         pt2.y=cvRandInt(&rng) % height3 - height;
00060 
00061         cvLine( image, pt1, pt2, random_color(&rng), cvRandInt(&rng)%10, line_type, 0 );
00062         cvShowImage(wndname,image);
00063         cvWaitKey(DELAY);
00064     }
00065 
00066     for (i = 0; i< NUMBER; i++)
00067     {
00068         pt1.x=cvRandInt(&rng) % width3 - width;
00069         pt1.y=cvRandInt(&rng) % height3 - height;
00070         pt2.x=cvRandInt(&rng) % width3 - width;
00071         pt2.y=cvRandInt(&rng) % height3 - height;
00072 
00073         cvRectangle( image,pt1, pt2, random_color(&rng), cvRandInt(&rng)%10-1, line_type, 0 );
00074         cvShowImage(wndname,image);
00075         cvWaitKey(DELAY);
00076     }
00077 
00078     for (i = 0; i< NUMBER; i++)
00079     {
00080         pt1.x=cvRandInt(&rng) % width3 - width;
00081         pt1.y=cvRandInt(&rng) % height3 - height;
00082         sz.width =cvRandInt(&rng)%200;
00083         sz.height=cvRandInt(&rng)%200;
00084         angle = (cvRandInt(&rng)%1000)*0.180;
00085 
00086         cvEllipse( image, pt1, sz, angle, angle - 100, angle + 200,
00087                    random_color(&rng), cvRandInt(&rng)%10-1, line_type, 0 );
00088         cvShowImage(wndname,image);
00089         cvWaitKey(DELAY);
00090     }
00091 
00092     for (i = 0; i< NUMBER; i++)
00093     {
00094         pt[0][0].x=cvRandInt(&rng) % width3 - width;
00095         pt[0][0].y=cvRandInt(&rng) % height3 - height;
00096         pt[0][1].x=cvRandInt(&rng) % width3 - width;
00097         pt[0][1].y=cvRandInt(&rng) % height3 - height;
00098         pt[0][2].x=cvRandInt(&rng) % width3 - width;
00099         pt[0][2].y=cvRandInt(&rng) % height3 - height;
00100         pt[1][0].x=cvRandInt(&rng) % width3 - width;
00101         pt[1][0].y=cvRandInt(&rng) % height3 - height;
00102         pt[1][1].x=cvRandInt(&rng) % width3 - width;
00103         pt[1][1].y=cvRandInt(&rng) % height3 - height;
00104         pt[1][2].x=cvRandInt(&rng) % width3 - width;
00105         pt[1][2].y=cvRandInt(&rng) % height3 - height;
00106 
00107         cvPolyLine( image, pt, arr, 2, 1, random_color(&rng), cvRandInt(&rng)%10, line_type, 0 );
00108         cvShowImage(wndname,image);
00109         cvWaitKey(DELAY);
00110     }
00111 
00112     for (i = 0; i< NUMBER; i++)
00113     {
00114         pt[0][0].x=cvRandInt(&rng) % width3 - width;
00115         pt[0][0].y=cvRandInt(&rng) % height3 - height;
00116         pt[0][1].x=cvRandInt(&rng) % width3 - width;
00117         pt[0][1].y=cvRandInt(&rng) % height3 - height;
00118         pt[0][2].x=cvRandInt(&rng) % width3 - width;
00119         pt[0][2].y=cvRandInt(&rng) % height3 - height;
00120         pt[1][0].x=cvRandInt(&rng) % width3 - width;
00121         pt[1][0].y=cvRandInt(&rng) % height3 - height;
00122         pt[1][1].x=cvRandInt(&rng) % width3 - width;
00123         pt[1][1].y=cvRandInt(&rng) % height3 - height;
00124         pt[1][2].x=cvRandInt(&rng) % width3 - width;
00125         pt[1][2].y=cvRandInt(&rng) % height3 - height;
00126 
00127         cvFillPoly( image, pt, arr, 2, random_color(&rng), line_type, 0 );
00128         cvShowImage(wndname,image);
00129         cvWaitKey(DELAY);
00130     }
00131 
00132     for (i = 0; i< NUMBER; i++)
00133     {
00134         pt1.x=cvRandInt(&rng) % width3 - width;
00135         pt1.y=cvRandInt(&rng) % height3 - height;
00136 
00137         cvCircle( image, pt1, cvRandInt(&rng)%300, random_color(&rng),
00138                   cvRandInt(&rng)%10-1, line_type, 0 );
00139         cvShowImage(wndname,image);
00140         cvWaitKey(DELAY);
00141     }
00142 
00143     for (i = 1; i< NUMBER; i++)
00144     {
00145         pt1.x=cvRandInt(&rng) % width3 - width;
00146         pt1.y=cvRandInt(&rng) % height3 - height;
00147 
00148         cvInitFont( &font, cvRandInt(&rng) % 8,
00149                     (cvRandInt(&rng)%100)*0.05+0.1, (cvRandInt(&rng)%100)*0.05+0.1, 
00150                     (cvRandInt(&rng)%5)*0.1, cvRound(cvRandInt(&rng)%10), line_type );
00151 
00152         cvPutText( image, "Testing text rendering!", pt1, &font, random_color(&rng));
00153         cvShowImage(wndname,image);
00154         cvWaitKey(DELAY);
00155     }
00156 
00157     cvInitFont( &font, CV_FONT_HERSHEY_COMPLEX, 3, 3, 0.0, 5, line_type );
00158 
00159     cvGetTextSize( "OpenCV forever!", &font, &text_size, &ymin );
00160 
00161     pt1.x = (width - text_size.width)/2;
00162     pt1.y = (height + text_size.height)/2;
00163     image2 = cvCloneImage(image);
00164 
00165     for( i = 0; i < 255; i++ )
00166     {
00167         cvSubS( image2, cvScalarAll(i), image, 0 );
00168         cvPutText( image, "OpenCV forever!", pt1, &font, CV_RGB(255,i,i));
00169         cvShowImage(wndname,image);
00170         cvWaitKey(DELAY);
00171     }
00172 
00173     // Wait for a key stroke; the same function arranges events processing
00174     cvWaitKey(0);
00175     cvReleaseImage(&image);
00176     cvReleaseImage(&image2);
00177     cvDestroyWindow(wndname);
00178 
00179     return 0;
00180 }
00181 
00182 #ifdef _EiC
00183 main(1,"drawing.c");
00184 #endif

Wygenerowano Thu Mar 1 12:15:24 2007 dla OpenCV programem  doxygen 1.4.7