3 printf("OpenCV Octave version of drawing\n");
5 ## import the necessary things for OpenCV
9 function ret=random_color ()
10 ret = CV_RGB(int32(rand()*255), int32(rand()*255), int32(rand()*255));
17 window_name = "Drawing Demo";
20 line_type = cv.CV_AA; # change it to 8 to see non-antialiased graphics
22 ## create the source image
23 image = cv.cvCreateImage (cv.cvSize (width, height), 8, 3);
25 ## create window and display the original picture in it
26 highgui.cvNamedWindow (window_name, 1);
28 highgui.cvShowImage (window_name, image);
32 pt1 = cv.cvPoint (int32(rand() * 2 * width - width),
33 int32(rand() * 2 * height - height));
34 pt2 = cv.cvPoint (int32(rand() * 2 * width - width),
35 int32(rand() * 2 * height - height));
36 cv.cvLine (image, pt1, pt2,
41 highgui.cvShowImage (window_name, image);
42 highgui.cvWaitKey (delay);
45 ## draw some rectangles
47 pt1 = cv.cvPoint (int32(rand() * 2 * width - width),
48 int32(rand() * 2 * height - height));
49 pt2 = cv.cvPoint (int32(rand() * 2 * width - width),
50 int32(rand() * 2 * height - height));
51 cv.cvRectangle (image, pt1, pt2,
53 int32(rand() * 10 - 1),
56 highgui.cvShowImage (window_name, image);
57 highgui.cvWaitKey (delay);
62 pt1 = cv.cvPoint (int32(rand() * 2 * width - width),
63 int32(rand() * 2 * height - height));
64 sz = cv.cvSize (int32(rand() * 200),
66 angle = rand() * 1000 * 0.180;
67 cv.cvEllipse (image, pt1, sz, angle, angle - 100, angle + 200,
69 int32(rand() * 10 - 1),
72 highgui.cvShowImage (window_name, image);
73 highgui.cvWaitKey (delay);
76 ## init the list of polylines
79 pt = cell(1, nb_polylines);
81 pt{a} = cell(1,polylines_size);
84 ## draw some polylines
87 for b=1:polylines_size,
88 pt {a}{b} = cv.cvPoint (int32(rand() * 2 * width - width), \
89 int32(rand() * 2 * height - height));
92 cv.cvPolyLine (image, pt, 1, random_color(), int32(rand() * 8 + 1), line_type, 0);
94 highgui.cvShowImage (window_name, image);
95 highgui.cvWaitKey (delay);
98 ## draw some filled polylines
100 for a=1:nb_polylines,
101 for b=1:polylines_size,
102 pt {a}{b} = cv.cvPoint (int32(rand() * 2 * width - width),
103 int32(rand() * 2 * height - height));
106 cv.cvFillPoly (image, pt, random_color (), line_type, 0);
108 highgui.cvShowImage (window_name, image);
109 highgui.cvWaitKey (delay);
114 pt1 = cv.cvPoint (int32(rand() * 2 * width - width),
115 int32(rand() * 2 * height - height));
116 cv.cvCircle (image, pt1, int32(rand() * 300), random_color (), \
117 int32(rand() * 10 - 1), line_type, 0);
119 highgui.cvShowImage (window_name, image);
120 highgui.cvWaitKey (delay);
125 pt1 = cv.cvPoint (int32(rand() * 2 * width - width), \
126 int32(rand() * 2 * height - height));
127 font = cv.cvInitFont (int32(rand() * 8), \
128 rand() * 100 * 0.05 + 0.01, \
129 rand() * 100 * 0.05 + 0.01, \
131 int32(rand() * 10), \
134 cv.cvPutText (image, "Testing text rendering!", \
138 highgui.cvShowImage (window_name, image);
139 highgui.cvWaitKey (delay);
142 ## prepare a text, and get it's properties
143 font = cv.cvInitFont (cv.CV_FONT_HERSHEY_COMPLEX, \
144 3, 3, 0.0, 5, line_type);
145 [text_size, ymin] = cv.cvGetTextSize ("OpenCV forever!", font);
146 pt1.x = int32((width - text_size.width) / 2);
147 pt1.y = int32((height + text_size.height) / 2);
148 image2 = cv.cvCloneImage(image);
150 ## now, draw some OpenCV pub ;-)
152 cv.cvSubS (image2, cv.cvScalarAll (i), image, []);
153 cv.cvPutText (image, "OpenCV forever!",
154 pt1, font, cv.cvScalar (255, i, i));
155 highgui.cvShowImage (window_name, image);
156 highgui.cvWaitKey (delay);
159 ## wait some key to end
160 highgui.cvWaitKey (0);