#include "cv.h" #include "highgui.h" #include #include #define NUMBER 100 #define DELAY 5 CvScalar random_color(CvRNG* rng) { int icolor = cvRandInt(rng); return CV_RGB(icolor&255, (icolor>>8)&255, (icolor>>16)&255); } int main( int argc, char** argv ) { // Set up variables CvFont font; CvPoint pt; CvRNG rng; // Random number generator CvSize text_size; char window_name[] = "Hello World! The Return"; int arr[2], i; int line_type = CV_AA; // change it to 8 to see non-antialiased graphics int width = 1000, height = 700; int width2 = width*2, height2 = height*2; // Initialise the random number generator rng = cvRNG((unsigned)-1); // Create an image IplImage* image = cvCreateImage( cvSize(width,height), 8, 3 ); // Create a window cvNamedWindow(window_name, 1 ); // Zero the image data cvZero( image ); for (i = 1; i < NUMBER; i++) { // Set random text location pt.x=cvRandInt(&rng) % width2 - width; pt.y=cvRandInt(&rng) % height2 - height; // Initialise random font cvInitFont( &font, cvRandInt(&rng) % 8, (cvRandInt(&rng)%100)*0.05+0.1, (cvRandInt(&rng)%100)*0.05+0.1, (cvRandInt(&rng)%5)*0.1, cvRound(cvRandInt(&rng)%10), line_type ); // Add text to image cvPutText( image, "Hello World!", pt, &font, random_color(&rng)); // Display image cvShowImage(window_name,image); // Wait for a tiny little bit cvWaitKey(DELAY); } // Wait for a key stroke, then release memory and exit cvWaitKey(0); cvReleaseImage(&image); cvDestroyWindow(window_name); return 0; }