1 \section{Drawing Functions}
3 Drawing functions work with matrices/images of arbitrary depth.
4 The boundaries of the shapes can be rendered with antialiasing (implemented only for 8-bit images for now).
5 All the functions include the parameter color that uses a rgb value (that may be constructed
6 with \texttt{CV\_RGB} \cvC{macro or the \cvCppCross{cvScalar} function}
7 \cvCpp{or the \cross{Scalar} constructor}) for color
8 images and brightness for grayscale images. For color images the order channel
9 is normally \emph{Blue, Green, Red}, this is what \cvCppCross{imshow}, \cvCppCross{imread} and \cvCppCross{imwrite} expect
11 , so if you form a color using \cross{Scalar} constructor, it should look like:
12 \[\texttt{Scalar}(blue\_component, green\_component, red\_component[, alpha\_component])\]
15 , so if you form a color using \cvCppCross{cvScalar}, it should look like:
16 \[\texttt{cvScalar}(blue\_component, green\_component, red\_component[, alpha\_component])\]
19 If you are using your own image rendering and I/O functions, you can use any channel ordering, the drawing functions process each channel independently and do not depend on the channel order or even on the color space used. The whole image can be converted from BGR to RGB or to a different color space using \cvCppCross{cvtColor}.
21 If a drawn figure is partially or completely outside the image, the drawing functions clip it. Also, many drawing functions can handle pixel coordinates specified with sub-pixel accuracy, that is, the coordinates can be passed as fixed-point numbers, encoded as integers. The number of fractional bits is specified by the \texttt{shift} parameter and the real point coordinates are calculated as $\texttt{Point}(x,y)\rightarrow\texttt{Point2f}(x*2^{-shift},y*2^{-shift})$. This feature is especially effective wehn rendering antialiased shapes.
23 Also, note that the functions do not support alpha-transparency - when the target image is 4-channnel, then the \texttt{color[3]} is simply copied to the repainted pixels. Thus, if you want to paint semi-transparent shapes, you can paint them in a separate buffer and then blend it with the main image.
30 \cvdefC{void cvCircle( \par CvArr* img,\par CvPoint center,\par int radius,\par CvScalar color,\par int thickness=1,\par int lineType=8,\par int shift=0 );}
31 \cvdefPy{Circle(img,center,radius,color,thickness=1,lineType=8,shift=0)-> None}
34 \cvarg{img}{Image where the circle is drawn}
35 \cvarg{center}{Center of the circle}
36 \cvarg{radius}{Radius of the circle}
37 \cvarg{color}{Circle color}
38 \cvarg{thickness}{Thickness of the circle outline if positive, otherwise this indicates that a filled circle is to be drawn}
39 \cvarg{lineType}{Type of the circle boundary, see \cross{Line} description}
40 \cvarg{shift}{Number of fractional bits in the center coordinates and radius value}
43 The function draws a simple or filled circle with a
44 given center and radius.
47 Clips the line against the image rectangle.
49 \cvdefC{int cvClipLine( \par CvSize imgSize,\par CvPoint* pt1,\par CvPoint* pt2 );}
50 \cvdefPy{ClipLine(imgSize, pt1, pt2) -> (clipped\_pt1, clipped\_pt2)}
52 \cvarg{imgSize}{Size of the image}
53 \cvarg{pt1}{First ending point of the line segment. \cvC{It is modified by the function.}}
54 \cvarg{pt2}{Second ending point of the line segment. \cvC{It is modified by the function.}}
57 The function calculates a part of the line segment which is entirely within the image.
58 \cvC{It returns 0 if the line segment is completely outside the image and 1 otherwise.}
59 \cvPy{If the line segment is outside the image, it returns None. If the line segment is inside the image it returns a new pair of points.}
61 \cvCPyFunc{DrawContours}
62 Draws contour outlines or interiors in an image.
65 void cvDrawContours( \par CvArr *img,\par CvSeq* contour,\par CvScalar external\_color,\par CvScalar hole\_color,\par int max\_level,\par int thickness=1,\par int lineType=8 );
67 \cvdefPy{DrawContours(img,contour,external\_color,hole\_color,max\_level,thickness=1,lineType=8,offset=(0,0))-> None}
70 \cvarg{img}{Image where the contours are to be drawn. As with any other drawing function, the contours are clipped with the ROI.}
71 \cvarg{contour}{Pointer to the first contour}
72 \cvarg{external\_color}{Color of the external contours}
73 \cvarg{hole\_color}{Color of internal contours (holes)}
74 \cvarg{max\_level}{Maximal level for drawn contours. If 0, only
75 \texttt{contour} is drawn. If 1, the contour and all contours following
76 it on the same level are drawn. If 2, all contours following and all
77 contours one level below the contours are drawn, and so forth. If the value
78 is negative, the function does not draw the contours following after
79 \texttt{contour} but draws the child contours of \texttt{contour} up
80 to the $|\texttt{max\_level}|-1$ level.}
81 \cvarg{thickness}{Thickness of lines the contours are drawn with.
82 If it is negative (For example, =CV\_FILLED), the contour interiors are
84 \cvarg{lineType}{Type of the contour segments, see \cross{Line} description}
87 The function draws contour outlines in the image if $\texttt{thickness} \ge 0$ or fills the area bounded by the contours if $ \texttt{thickness}<0$.
90 Example: Connected component detection via contour functions
96 int main( int argc, char** argv )
99 // the first command line parameter must be file name of binary
100 // (black-n-white) image
101 if( argc == 2 && (src=cvLoadImage(argv[1], 0))!= 0)
103 IplImage* dst = cvCreateImage( cvGetSize(src), 8, 3 );
104 CvMemStorage* storage = cvCreateMemStorage(0);
107 cvThreshold( src, src, 1, 255, CV_THRESH_BINARY );
108 cvNamedWindow( "Source", 1 );
109 cvShowImage( "Source", src );
111 cvFindContours( src, storage, &contour, sizeof(CvContour),
112 CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE );
115 for( ; contour != 0; contour = contour->h_next )
117 CvScalar color = CV_RGB( rand()&255, rand()&255, rand()&255 );
118 /* replace CV_FILLED with 1 to see the outlines */
119 cvDrawContours( dst, contour, color, color, -1, CV_FILLED, 8 );
122 cvNamedWindow( "Components", 1 );
123 cvShowImage( "Components", dst );
131 Draws a simple or thick elliptic arc or an fills ellipse sector.
133 \cvdefC{void cvEllipse( \par CvArr* img,\par CvPoint center,\par CvSize axes,\par double angle,\par double start\_angle,\par double end\_angle,\par CvScalar color,\par int thickness=1,\par int lineType=8,\par int shift=0 );}
134 \cvdefPy{Ellipse(img,center,axes,angle,start\_angle,end\_angle,color,thickness=1,lineType=8,shift=0)-> None}
137 \cvarg{img}{The image}
138 \cvarg{center}{Center of the ellipse}
139 \cvarg{axes}{Length of the ellipse axes}
140 \cvarg{angle}{Rotation angle}
141 \cvarg{start\_angle}{Starting angle of the elliptic arc}
142 \cvarg{end\_angle}{Ending angle of the elliptic arc.}
143 \cvarg{color}{Ellipse color}
144 \cvarg{thickness}{Thickness of the ellipse arc outline if positive, otherwise this indicates that a filled ellipse sector is to be drawn}
145 \cvarg{lineType}{Type of the ellipse boundary, see \cross{Line} description}
146 \cvarg{shift}{Number of fractional bits in the center coordinates and axes' values}
149 The function draws a simple or thick elliptic
150 arc or fills an ellipse sector. The arc is clipped by the ROI rectangle.
151 A piecewise-linear approximation is used for antialiased arcs and
152 thick arcs. All the angles are given in degrees. The picture below
153 explains the meaning of the parameters.
155 Parameters of Elliptic Arc
157 \includegraphics[width=0.5\textwidth]{pics/ellipse.png}
159 \cvCPyFunc{EllipseBox}
161 Draws a simple or thick elliptic arc or fills an ellipse sector.
163 \cvdefC{void cvEllipseBox( \par CvArr* img, \par CvBox2D box, \par CvScalar color,
164 \par int thickness=1, \par int lineType=8, \par int shift=0 );}
165 \cvdefPy{EllipseBox(img,box,color,thickness=1,lineType=8,shift=0)-> None}
169 \cvarg{box}{The enclosing box of the ellipse drawn}
170 \cvarg{thickness}{Thickness of the ellipse boundary}
171 \cvarg{lineType}{Type of the ellipse boundary, see \cross{Line} description}
172 \cvarg{shift}{Number of fractional bits in the box vertex coordinates}
175 The function draws a simple or thick ellipse outline, or fills an ellipse. The functions provides a convenient way to draw an ellipse approximating some shape; that is what \cross{CamShift} and \cross{FitEllipse} do. The ellipse drawn is clipped by ROI rectangle. A piecewise-linear approximation is used for antialiased arcs and thick arcs.
177 \cvCPyFunc{FillConvexPoly}
178 Fills a convex polygon.
181 void cvFillConvexPoly( \par CvArr* img,\par CvPoint* pts,\par int npts,\par CvScalar color,\par int lineType=8,\par int shift=0 );}
182 \cvdefPy{FillConvexPoly(img,pn,color,lineType=8,shift=0)-> None}
187 \cvarg{pts}{Array of pointers to a single polygon}
188 \cvarg{npts}{Polygon vertex counter}
190 \cvarg{pn}{List of coordinate pairs}
192 \cvarg{color}{Polygon color}
193 \cvarg{lineType}{Type of the polygon boundaries, see \cross{Line} description}
194 \cvarg{shift}{Number of fractional bits in the vertex coordinates}
197 The function fills a convex polygon's interior.
198 This function is much faster than the function \texttt{cvFillPoly}
199 and can fill not only convex polygons but any monotonic polygon,
200 i.e., a polygon whose contour intersects every horizontal line (scan
201 line) twice at the most.
205 Fills a polygon's interior.
208 void cvFillPoly( \par CvArr* img,\par CvPoint** pts,\par int* npts,\par int contours,\par CvScalar color,\par int lineType=8,\par int shift=0 );
210 \cvdefPy{FillPoly(img,polys,color,lineType=8,shift=0)-> None}
215 \cvarg{pts}{Array of pointers to polygons}
216 \cvarg{npts}{Array of polygon vertex counters}
217 \cvarg{contours}{Number of contours that bind the filled region}
220 \cvarg{polys}{List of lists of (x,y) pairs. Each list of points is a polygon.}
222 \cvarg{color}{Polygon color}
223 \cvarg{lineType}{Type of the polygon boundaries, see \cross{Line} description}
224 \cvarg{shift}{Number of fractional bits in the vertex coordinates}
228 The function fills an area bounded by several
229 polygonal contours. The function fills complex areas, for example,
230 areas with holes, contour self-intersection, and so forth.
232 \cvCPyFunc{GetTextSize}
233 Retrieves the width and height of a text string.
236 void cvGetTextSize( \par const char* textString,\par const CvFont* font,\par CvSize* textSize,\par int* baseline );}
237 \cvdefPy{GetTextSize(textString,font)-> (textSize,baseline)}
240 \cvarg{font}{Pointer to the font structure}
241 \cvarg{textString}{Input string}
242 \cvarg{textSize}{Resultant size of the text string. Height of the text does not include the height of character parts that are below the baseline.}
243 \cvarg{baseline}{y-coordinate of the baseline relative to the bottom-most text point}
246 The function calculates the dimensions of a rectangle to enclose a text string when a specified font is used.
249 Initializes font structure.
252 void cvInitFont( \par CvFont* font,\par int fontFace,\par double hscale,\par double vscale,\par double shear=0,\par int thickness=1,\par int lineType=8 );}
253 \cvdefPy{InitFont(fontFace,hscale,vscale,shear=0,thickness=1,lineType=8)-> font}
256 \cvarg{font}{Pointer to the font structure initialized by the function}
257 \cvarg{fontFace}{Font name identifier. Only a subset of Hershey fonts \url{http://sources.isc.org/utils/misc/hershey-font.txt} are supported now:
259 \cvarg{CV\_FONT\_HERSHEY\_SIMPLEX}{normal size sans-serif font}
260 \cvarg{CV\_FONT\_HERSHEY\_PLAIN}{small size sans-serif font}
261 \cvarg{CV\_FONT\_HERSHEY\_DUPLEX}{normal size sans-serif font (more complex than \par \texttt{CV\_FONT\_HERSHEY\_SIMPLEX})}
262 \cvarg{CV\_FONT\_HERSHEY\_COMPLEX}{normal size serif font}
263 \cvarg{CV\_FONT\_HERSHEY\_TRIPLEX}{normal size serif font (more complex than \texttt{CV\_FONT\_HERSHEY\_COMPLEX})}
264 \cvarg{CV\_FONT\_HERSHEY\_COMPLEX\_SMALL}{smaller version of \texttt{CV\_FONT\_HERSHEY\_COMPLEX}}
265 \cvarg{CV\_FONT\_HERSHEY\_SCRIPT\_SIMPLEX}{hand-writing style font}
266 \cvarg{CV\_FONT\_HERSHEY\_SCRIPT\_COMPLEX}{more complex variant of \texttt{CV\_FONT\_HERSHEY\_SCRIPT\_SIMPLEX}}
268 The parameter can be composited from one of the values above and an optional \texttt{CV\_FONT\_ITALIC} flag, which indicates italic or oblique font.}
269 \cvarg{hscale}{Horizontal scale. If equal to \texttt{1.0f}, the characters have the original width depending on the font type. If equal to \texttt{0.5f}, the characters are of half the original width.}
270 \cvarg{vscale}{Vertical scale. If equal to \texttt{1.0f}, the characters have the original height depending on the font type. If equal to \texttt{0.5f}, the characters are of half the original height.}
271 \cvarg{shear}{Approximate tangent of the character slope relative to the vertical line. A zero value means a non-italic font, \texttt{1.0f} means about a 45 degree slope, etc.}
272 \cvarg{thickness}{Thickness of the text strokes}
273 \cvarg{lineType}{Type of the strokes, see \cross{Line} description}
276 The function initializes the font structure that can be passed to text rendering functions.
279 \cvCPyFunc{InitLineIterator}
280 Initializes the line iterator.
283 int cvInitLineIterator( \par const CvArr* image,\par CvPoint pt1,\par CvPoint pt2,\par CvLineIterator* line\_iterator,\par int connectivity=8,\par int left\_to\_right=0 );
285 \cvdefPy{InitLineIterator(image, pt1, pt2, connectivity=8, left\_to\_right=0) -> None}
288 \cvarg{image}{Image to sample the line from}
289 \cvarg{pt1}{First ending point of the line segment}
290 \cvarg{pt2}{Second ending point of the line segment}
291 \cvC{\cvarg{line\_iterator}{Pointer to the line iterator state structure}}
292 \cvarg{connectivity}{The scanned line connectivity, 4 or 8.}
293 \cvarg{left\_to\_right}{
294 If ($ \texttt{left\_to\_right} = 0 $ ) then the line is scanned in the specified order, from \texttt{pt1} to \texttt{pt2}.
295 If ($ \texttt{left\_to\_right} \ne 0$) the line is scanned from left-most point to right-most.}
298 The function initializes the line
299 iterator and returns the number of pixels between the two end points.
300 Both points must be inside the image. After the iterator has been
301 initialized, all the points on the raster line that connects the
302 two ending points may be retrieved by successive calls of
303 \texttt{CV\_NEXT\_LINE\_POINT} point. The points on the line are
304 calculated one by one using a 4-connected or 8-connected Bresenham
308 % Example: Using line iterator to calculate the sum of pixel values along the color line
312 CvScalar sum_line_pixels( IplImage* image, CvPoint pt1, CvPoint pt2 )
314 CvLineIterator iterator;
315 int blue_sum = 0, green_sum = 0, red_sum = 0;
316 int count = cvInitLineIterator( image, pt1, pt2, &iterator, 8, 0 );
318 for( int i = 0; i < count; i++ ){
319 blue_sum += iterator.ptr[0];
320 green_sum += iterator.ptr[1];
321 red_sum += iterator.ptr[2];
322 CV_NEXT_LINE_POINT(iterator);
324 /* print the pixel coordinates: demonstrates how to calculate the
328 /* assume that ROI is not set, otherwise need to take it
330 offset = iterator.ptr - (uchar*)(image->imageData);
331 y = offset/image->widthStep;
332 x = (offset - y*image->widthStep)/(3*sizeof(uchar)
333 /* size of pixel */);
334 printf("(%d,%d)\n", x, y );
337 return cvScalar( blue_sum, green_sum, red_sum );
344 Draws a line segment connecting two points.
347 void cvLine( \par CvArr* img,\par CvPoint pt1,\par CvPoint pt2,\par CvScalar color,\par int thickness=1,\par int lineType=8,\par int shift=0 );
349 \cvdefPy{Line(img,pt1,pt2,color,thickness=1,lineType=8,shift=0)-> None}
352 \cvarg{img}{The image}
353 \cvarg{pt1}{First point of the line segment}
354 \cvarg{pt2}{Second point of the line segment}
355 \cvarg{color}{Line color}
356 \cvarg{thickness}{Line thickness}
357 \cvarg{lineType}{Type of the line:
359 \cvarg{8}{(or omitted) 8-connected line.}
360 \cvarg{4}{4-connected line.}
361 \cvarg{CV\_AA}{antialiased line.}
363 \cvarg{shift}{Number of fractional bits in the point coordinates}
366 The function draws the line segment between
367 \texttt{pt1} and \texttt{pt2} points in the image. The line is
368 clipped by the image or ROI rectangle. For non-antialiased lines
369 with integer coordinates the 8-connected or 4-connected Bresenham
370 algorithm is used. Thick lines are drawn with rounding endings.
371 Antialiased lines are drawn using Gaussian filtering. To specify
372 the line color, the user may use the macro
373 \texttt{CV\_RGB( r, g, b )}.
376 Draws simple or thick polygons.
379 void cvPolyLine( \par CvArr* img,\par CvPoint** pts,\par int* npts,\par int contours,\par int is\_closed,\par CvScalar color,\par int thickness=1,\par int lineType=8,\par int shift=0 );}
380 \cvdefPy{PolyLine(img,polys,is\_closed,color,thickness=1,lineType=8,shift=0)-> None}
384 \cvarg{pts}{Array of pointers to polygons}
385 \cvarg{npts}{Array of polygon vertex counters}
386 \cvarg{contours}{Number of contours that bind the filled region}
389 \cvarg{polys}{List of lists of (x,y) pairs. Each list of points is a polygon.}
392 \cvarg{is\_closed}{Indicates whether the polylines must be drawn
393 closed. If closed, the function draws the line from the last vertex
394 of every contour to the first vertex.}
395 \cvarg{color}{Polyline color}
396 \cvarg{thickness}{Thickness of the polyline edges}
397 \cvarg{lineType}{Type of the line segments, see \cross{Line} description}
398 \cvarg{shift}{Number of fractional bits in the vertex coordinates}
401 The function draws single or multiple polygonal curves.
407 void cvPutText( \par CvArr* img,\par const char* text,\par CvPoint org,\par const CvFont* font,\par CvScalar color );}
408 \cvdefPy{PutText(img,text,org,font,color)-> None}
411 \cvarg{img}{Input image}
412 \cvarg{text}{String to print}
413 \cvarg{org}{Coordinates of the bottom-left corner of the first letter}
414 \cvarg{font}{Pointer to the font structure}
415 \cvarg{color}{Text color}
419 The function renders the text in the image with
420 the specified font and color. The printed text is clipped by the ROI
421 rectangle. Symbols that do not belong to the specified font are
422 replaced with the symbol for a rectangle.
424 \cvCPyFunc{Rectangle}
425 Draws a simple, thick, or filled rectangle.
427 \cvdefC{void cvRectangle( \par CvArr* img,\par CvPoint pt1,\par CvPoint pt2,\par CvScalar color,\par int thickness=1,\par int lineType=8,\par int shift=0 );}
428 \cvdefPy{Rectangle(img,pt1,pt2,color,thickness=1,lineType=8,shift=0)-> None}
432 \cvarg{pt1}{One of the rectangle's vertices}
433 \cvarg{pt2}{Opposite rectangle vertex}
434 \cvarg{color}{Line color (RGB) or brightness (grayscale image)}
435 \cvarg{thickness}{Thickness of lines that make up the rectangle. Negative values, e.g., CV\_FILLED, cause the function to draw a filled rectangle.}
436 \cvarg{lineType}{Type of the line, see \cross{Line} description}
437 \cvarg{shift}{Number of fractional bits in the point coordinates}
440 The function draws a rectangle with two opposite corners \texttt{pt1} and \texttt{pt2}.
442 \cvfunc{CV\_RGB}\label{CV_RGB}
443 Constructs a color value.
445 \cvdefC{\#define CV\_RGB( r, g, b ) cvScalar( (b), (g), (r) )}
446 \cvdefPy{CV\_RGB(red,grn,blu)->CvScalar}
449 \cvarg{red}{Red component}
450 \cvarg{grn}{Green component}
451 \cvarg{blu}{Blue component}
462 void circle(Mat\& img, Point center, int radius,\par
463 const Scalar\& color, int thickness=1,\par
464 int lineType=8, int shift=0);
467 \cvarg{img}{Image where the circle is drawn}
468 \cvarg{center}{Center of the circle}
469 \cvarg{radius}{Radius of the circle}
470 \cvarg{color}{Circle color}
471 \cvarg{thickness}{Thickness of the circle outline if positive; negative thickness means that a filled circle is to be drawn}
472 \cvarg{lineType}{Type of the circle boundary, see \cvCppCross{line} description}
473 \cvarg{shift}{Number of fractional bits in the center coordinates and radius value}
476 The function \texttt{circle} draws a simple or filled circle with a
477 given center and radius.
480 Clips the line against the image rectangle
483 bool clipLine(Size imgSize, Point\& pt1, Point\& pt2);\newline
484 bool clipLine(Rect imgRect, Point\& pt1, Point\& pt2);\newline
487 \cvarg{imgSize}{The image size; the image rectangle will be \texttt{Rect(0, 0, imgSize.width, imgSize.height)}}
488 \cvarg{imgSize}{The image rectangle}
489 \cvarg{pt1}{The first line point}
490 \cvarg{pt2}{The second line point}
493 The functions \texttt{clipLine} calculate a part of the line
494 segment which is entirely within the specified rectangle.
495 They return \texttt{false} if the line segment is completely outside the rectangle and \texttt{true} otherwise.
499 Draws a simple or thick elliptic arc or an fills ellipse sector.
502 void ellipse(Mat\& img, Point center, Size axes,\par
503 double angle, double startAngle, double endAngle,\par
504 const Scalar\& color, int thickness=1,\par
505 int lineType=8, int shift=0);\newline
506 void ellipse(Mat\& img, const RotatedRect\& box, const Scalar\& color,\par
507 int thickness=1, int lineType=8);\newline
510 \cvarg{img}{The image}
511 \cvarg{center}{Center of the ellipse}
512 \cvarg{axes}{Length of the ellipse axes}
513 \cvarg{angle}{The ellipse rotation angle in degrees}
514 \cvarg{startAngle}{Starting angle of the elliptic arc in degrees}
515 \cvarg{endAngle}{Ending angle of the elliptic arc in degrees}
516 \cvarg{box}{Alternative ellipse representation via a \cross{RotatedRect}, i.e. the function draws an ellipse inscribed in the rotated rectangle}
517 \cvarg{color}{Ellipse color}
518 \cvarg{thickness}{Thickness of the ellipse arc outline if positive, otherwise this indicates that a filled ellipse sector is to be drawn}
519 \cvarg{lineType}{Type of the ellipse boundary, see \cvCppCross{line} description}
520 \cvarg{shift}{Number of fractional bits in the center coordinates and axes' values}
523 The functions \texttt{ellipse} with less parameters draw an ellipse outline, a filled ellipse, an elliptic
524 arc or a filled ellipse sector.
525 A piecewise-linear curve is used to approximate the elliptic arc boundary. If you need more control of the ellipse rendering, you can retrieve the curve using \cvCppCross{ellipse2Poly} and then render it with \cvCppCross{polylines} or fill it with \cvCppCross{fillPoly}. If you use the first variant of the function and want to draw the whole ellipse, not an arc, pass \texttt{startAngle=0} and \texttt{endAngle=360}. The picture below
526 explains the meaning of the parameters.
528 Parameters of Elliptic Arc
530 \includegraphics[width=0.5\textwidth]{pics/ellipse.png}
532 \cvCppFunc{ellipse2Poly}
533 Approximates an elliptic arc with a polyline
536 void ellipse2Poly( Point center, Size axes, int angle,\par
537 int startAngle, int endAngle, int delta,\par
538 vector<Point>\& pts );\newline
541 \cvarg{center}{Center of the arc}
542 \cvarg{axes}{Half-sizes of the arc. See \cvCppCross{ellipse}}
543 \cvarg{angle}{Rotation angle of the ellipse in degrees. See \cvCppCross{ellipse}}
544 \cvarg{startAngle}{Starting angle of the elliptic arc in degrees}
545 \cvarg{endAngle}{Ending angle of the elliptic arc in degrees}
546 \cvarg{delta}{Angle between the subsequent polyline vertices. It defines the approximation accuracy.}
547 \cvarg{pts}{The output vector of polyline vertices}
550 The function \texttt{ellipse2Poly} computes the vertices of a polyline that approximates the specified elliptic arc. It is used by \cvCppCross{ellipse}.
552 \cvCppFunc{fillConvexPoly}
553 Fills a convex polygon.
556 void fillConvexPoly(Mat\& img, const Point* pts, int npts,\par
557 const Scalar\& color, int lineType=8,\par
558 int shift=0);\newline
562 \cvarg{pts}{The polygon vertices}
563 \cvarg{npts}{The number of polygon vertices}
564 \cvarg{color}{Polygon color}
565 \cvarg{lineType}{Type of the polygon boundaries, see \cvCppCross{line} description}
566 \cvarg{shift}{The number of fractional bits in the vertex coordinates}
569 The function \texttt{fillConvexPoly} draws a filled convex polygon.
570 This function is much faster than the function \texttt{fillPoly}
571 and can fill not only convex polygons but any monotonic polygon without self-intersections,
572 i.e., a polygon whose contour intersects every horizontal line (scan
573 line) twice at the most (though, its top-most and/or the bottom edge could be horizontal).
576 Fills the area bounded by one or more polygons
578 \cvdefCpp{void fillPoly(Mat\& img, const Point** pts, \par
579 const int* npts, int ncontours,\par
580 const Scalar\& color, int lineType=8,\par
581 int shift=0, Point offset=Point() );}
584 \cvarg{pts}{Array of polygons, each represented as an array of points}
585 \cvarg{npts}{The array of polygon vertex counters}
586 \cvarg{ncontours}{The number of contours that bind the filled region}
587 \cvarg{color}{Polygon color}
588 \cvarg{lineType}{Type of the polygon boundaries, see \cvCppCross{line} description}
589 \cvarg{shift}{The number of fractional bits in the vertex coordinates}
592 The function \texttt{fillPoly} fills an area bounded by several
593 polygonal contours. The function can fills complex areas, for example,
594 areas with holes, contours with self-intersections (some of thier parts), and so forth.
596 \cvCppFunc{getTextSize}
597 Calculates the width and height of a text string.
599 \cvdefCpp{Size getTextSize(const string\& text, int fontFace,\par
600 double fontScale, int thickness,\par
601 int* baseLine);\newline}
603 \cvarg{text}{The input text string}
604 \cvarg{fontFace}{The font to use; see \cvCppCross{putText}}
605 \cvarg{fontScale}{The font scale; see \cvCppCross{putText}}
606 \cvarg{thickness}{The thickness of lines used to render the text; see \cvCppCross{putText}}
607 \cvarg{baseLine}{The output parameter - y-coordinate of the baseline relative to the bottom-most text point}
610 The function \texttt{getTextSize} calculates and returns size of the box that contain the specified text.
611 That is, the following code will render some text, the tight box surrounding it and the baseline:
614 // Use "y" to show that the baseLine is about
615 string text = "Funny text inside the box";
616 int fontFace = FONT_HERSHEY_SCRIPT_SIMPLEX;
617 double fontScale = 2;
620 Mat img(600, 800, CV_8UC3, Scalar::all(0));
623 Size textSize = getTextSize(text, fontFace,
624 fontScale, thickness, &baseline);
625 baseline += thickness;
628 Point textOrg((img.cols - textSize.width)/2,
629 (img.rows + textSize.height)/2);
632 rectangle(img, textOrg + Point(0, baseline),
633 textOrg + Point(textSize.width, -textSize.height),
635 // ... and the baseline first
636 line(img, textOrg + Point(0, thickness),
637 textOrg + Point(textSize.width, thickness),
640 // then put the text itself
641 putText(img, text, textOrg, fontFace, fontScale,
642 Scalar::all(255), thickness, 8);
647 Draws a line segment connecting two points
649 \cvdefCpp{void line(Mat\& img, Point pt1, Point pt2, const Scalar\& color,\par
650 int thickness=1, int lineType=8, int shift=0);\newline}
652 \cvarg{img}{The image}
653 \cvarg{pt1}{First point of the line segment}
654 \cvarg{pt2}{Second point of the line segment}
655 \cvarg{color}{Line color}
656 \cvarg{thickness}{Line thickness}
657 \cvarg{lineType}{Type of the line:
659 \cvarg{8}{(or omitted) 8-connected line.}
660 \cvarg{4}{4-connected line.}
661 \cvarg{CV\_AA}{antialiased line.}
663 \cvarg{shift}{Number of fractional bits in the point coordinates}
666 The function \texttt{line} draws the line segment between
667 \texttt{pt1} and \texttt{pt2} points in the image. The line is
668 clipped by the image boundaries. For non-antialiased lines
669 with integer coordinates the 8-connected or 4-connected Bresenham
670 algorithm is used. Thick lines are drawn with rounding endings.
671 Antialiased lines are drawn using Gaussian filtering. To specify
672 the line color, the user may use the macro
673 \texttt{CV\_RGB(r, g, b)}.
676 \cvclass{LineIterator}
677 Class for iterating pixels on a raster line
683 // creates iterators for the line connecting pt1 and pt2
684 // the line will be clipped on the image boundaries
685 // the line is 8-connected or 4-connected
686 // If leftToRight=true, then the iteration is always done
687 // from the left-most point to the right most,
688 // not to depend on the ordering of pt1 and pt2 parameters
689 LineIterator(const Mat& img, Point pt1, Point pt2,
690 int connectivity=8, bool leftToRight=false);newline
691 // returns pointer to the current line pixel
692 uchar* operator *();newline
693 // move the iterator to the next pixel
694 LineIterator& operator ++();newline
695 LineIterator operator ++(int);newline
697 // internal state of the iterator
699 int err, count;newline
700 int minusDelta, plusDelta;newline
701 int minusStep, plusStep;newline
705 The class \texttt{LineIterator} is used to get each pixel of a raster line. It can be treated as versatile implementation of the Bresenham algorithm, where you can stop at each pixel and do some extra processing, for example, grab pixel values along the line, or draw a line with some effect (e.g. with XOR operation).
707 The number of pixels along the line is store in \texttt{LineIterator::count}.
710 // grabs pixels along the line (pt1, pt2)
711 // from 8-bit 3-channel image to the buffer
712 LineIterator it(img, pt1, pt2, 8);
713 vector<Vec3b> buf(it.count);
715 for(int i = 0; i < it.count; i++, ++it)
716 buf[i] = *(const Vec3b)*it;
720 \cvCppFunc{rectangle}
721 Draws a simple, thick, or filled up-right rectangle.
723 \cvdefCpp{void rectangle(Mat\& img, Point pt1, Point pt2,\par
724 const Scalar\& color, int thickness=1,\par
725 int lineType=8, int shift=0);}
728 \cvarg{pt1}{One of the rectangle's vertices}
729 \cvarg{pt2}{Opposite to \texttt{pt1} rectangle vertex}
730 \cvarg{color}{Rectangle color or brightness (grayscale image)}
731 \cvarg{thickness}{Thickness of lines that make up the rectangle. Negative values, e.g. \texttt{CV\_FILLED}, mean that the function has to draw a filled rectangle.}
732 \cvarg{lineType}{Type of the line, see \cvCppCross{line} description}
733 \cvarg{shift}{Number of fractional bits in the point coordinates}
736 The function \texttt{rectangle} draws a rectangle outline or a filled rectangle, which two opposite corners are \texttt{pt1} and \texttt{pt2}.
739 \cvCppFunc{polylines}
740 Draws several polygonal curves
742 \cvdefCpp{void polylines(Mat\& img, const Point** pts, const int* npts,\par
743 int ncontours, bool isClosed, const Scalar\& color,\par
744 int thickness=1, int lineType=8, int shift=0 );\newline}
746 \cvarg{img}{The image}
747 \cvarg{pts}{Array of polygonal curves}
748 \cvarg{npts}{Array of polygon vertex counters}
749 \cvarg{ncontours}{The number of curves}
750 \cvarg{isClosed}{Indicates whether the drawn polylines are closed or not. If they are closed, the function draws the line from the last vertex of each curve to its first vertex}
751 \cvarg{color}{Polyline color}
752 \cvarg{thickness}{Thickness of the polyline edges}
753 \cvarg{lineType}{Type of the line segments, see \cvCppCross{line} description}
754 \cvarg{shift}{The number of fractional bits in the vertex coordinates}
757 The function \texttt{polylines} draws one or more polygonal curves.
762 \cvdefCpp{void putText( Mat\& img, const string\& text, Point org,\par
763 int fontFace, double fontScale, Scalar color,\par
764 int thickness=1, int lineType=8,\par
765 bool bottomLeftOrigin=false );}
767 \cvarg{img}{The image}
768 \cvarg{text}{The text string to be drawn}
769 \cvarg{org}{The bottom-left corner of the text string in the image}
770 \cvarg{fontFace}{The font type, one of \texttt{FONT\_HERSHEY\_SIMPLEX}, \texttt{FONT\_HERSHEY\_PLAIN},
771 \texttt{FONT\_HERSHEY\_DUPLEX}, \texttt{FONT\_HERSHEY\_COMPLEX}, \texttt{FONT\_HERSHEY\_TRIPLEX},
772 \texttt{FONT\_HERSHEY\_COMPLEX\_SMALL}, \texttt{FONT\_HERSHEY\_SCRIPT\_SIMPLEX} or \texttt{FONT\_HERSHEY\_SCRIPT\_COMPLEX},
773 where each of the font id's can be combined with \texttt{FONT\_HERSHEY\_ITALIC} to get the slanted letters.}
774 \cvarg{fontScale}{The font scale factor that is multiplied by the font-specific base size}
775 \cvarg{thickness}{Thickness of the lines used to draw the text}
776 \cvarg{lineType}{The line type; see \texttt{line} for details}
777 \cvarg{bottomLeftOrigin}{When true, the image data origin is at the bottom-left corner, otherwise it's at the top-left corner}
780 The function \texttt{putText} draws a text string in the image.
781 Symbols that can not be rendered using the specified font are
782 replaced question marks. See \cvCppCross{getTextSize} for a text rendering code example.