Move the sources to trunk
[opencv] / docs / ref / opencvref_cxcore.htm
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
2 <html><head>
3 <link rel="STYLESHEET" href="opencvref.css" charset="ISO-8859-1" type="text/css">
4 <title>CXCORE Reference Manual</title>
5 </head><body>
6
7 <h1>CXCORE Reference Manual</h1>
8
9 <hr><p><ul>
10 <li><a href="#cxcore_basic_structures">Basic Structures</a>
11 <li><a href="#cxcore_arrays">Operations on Arrays</a>
12 <ul>
13 <li><a href="#cxcore_arrays_alloc_free">Initialization</a>
14 <li><a href="#cxcore_arrays_get_set">Accessing Elements and sub-Arrays</a>
15 <li><a href="#cxcore_arrays_copying">Copying and Filling</a>
16 <li><a href="#cxcore_arrays_permute">Transforms and Permutations</a>
17 <li><a href="#cxcore_arrays_arithm_logic">Arithmetic, Logic and Comparison</a>
18 <li><a href="#cxcore_arrays_stat">Statistics</a>
19 <li><a href="#cxcore_arrays_matrix">Linear Algebra</a>
20 <li><a href="#cxcore_arrays_math">Math Functions</a>
21 <li><a href="#cxcore_arrays_rng">Random Number Generation</a>
22 <li><a href="#cxcore_arrays_dxt">Discrete Transforms</a>
23 </ul>
24 <li><a href="#cxcore_ds">Dynamic Structures</a>
25 <ul>
26 <li><a href="#cxcore_ds_storages">Memory Storages</a>
27 <li><a href="#cxcore_ds_sequences">Sequences</a>
28 <li><a href="#cxcore_ds_sets">Sets</a>
29 <li><a href="#cxcore_ds_graphs">Graphs</a>
30 <li><a href="#cxcore_ds_trees">Trees</a>
31 </ul>
32 <li><a href="#cxcore_drawing">Drawing Functions</a>
33 <ul>
34 <li><a href="#cxcore_drawing_shapes">Curves and Shapes</a>
35 <li><a href="#cxcore_drawing_text">Text</a>
36 <li><a href="#cxcore_drawing_seq">Point Sets and Contours</a>
37 </ul>
38 <li><a href="#cxcore_persistence">Data Persistence and RTTI</a>
39 <ul>
40 <li><a href="#cxcore_persistence_ds">File Storage</a>
41 <li><a href="#cxcore_persistence_writing">Writing Data</a>
42 <li><a href="#cxcore_persistence_reading">Reading Data</a>
43 <li><a href="#cxcore_persistence_rtti">RTTI and Generic Functions</a>
44 </ul>
45 <li><a href="#cxcore_misc">Miscellaneous Functions</a>
46 <li><a href="#cxcore_system">Error Handling and System Functions</a>
47 <ul>
48 <li><a href="#cxcore_system_error">Error Handling</a>
49 <li><a href="#cxcore_system_sys">System Functions</a>
50 </ul>
51 <li><a href="#cxcore_func_index">Alphabetical List of Functions</a>
52 <li><a href="#cxcore_sample_index">List of Examples</a>
53 </ul></p>
54
55
56 <!-- *****************************************************************************************
57      *****************************************************************************************
58      ***************************************************************************************** -->
59
60 <hr><h1><a name="cxcore_basic_structures">Basic Structures</a></h1>
61
62 <hr><h3><a name="decl_CvPoint">CvPoint</a></h3>
63 <p class="Blurb">2D point with integer coordinates</p>
64 <pre>
65     typedef struct CvPoint
66     {
67         int x; /* x-coordinate, usually zero-based */
68         int y; /* y-coordinate, usually zero-based */
69     }
70     CvPoint;
71
72     /* the constructor function */
73     inline CvPoint cvPoint( int x, int y );
74
75     /* conversion from CvPoint2D32f */
76     inline CvPoint cvPointFrom32f( CvPoint2D32f point );
77 </pre>
78
79 <hr><h3><a name="decl_CvPoint2D32f">CvPoint2D32f</a></h3>
80 <p class="Blurb">2D point with floating-point coordinates</p>
81 <pre>
82     typedef struct CvPoint2D32f
83     {
84         float x; /* x-coordinate, usually zero-based */
85         float y; /* y-coordinate, usually zero-based */
86     }
87     CvPoint2D32f;
88
89     /* the constructor function */
90     inline CvPoint2D32f cvPoint2D32f( double x, double y );
91
92     /* conversion from CvPoint */
93     inline CvPoint2D32f cvPointTo32f( CvPoint point );
94 </pre>
95
96
97 <hr><h3><a name="decl_CvPoint3D32f">CvPoint3D32f</a></h3>
98 <p class="Blurb">3D point with floating-point coordinates</p>
99 <pre>
100     typedef struct CvPoint3D32f
101     {
102         float x; /* x-coordinate, usually zero-based */
103         float y; /* y-coordinate, usually zero-based */
104         float z; /* z-coordinate, usually zero-based */
105     }
106     CvPoint3D32f;
107
108     /* the constructor function */
109     inline CvPoint3D32f cvPoint3D32f( double x, double y, double z );
110 </pre>
111
112
113 <hr><h3><a name="decl_CvPoint2D64f">CvPoint2D64f</a></h3>
114 <p class="Blurb">2D point with double precision floating-point coordinates</p>
115 <pre>
116     typedef struct CvPoint2D64f
117     {
118         double x; /* x-coordinate, usually zero-based */
119         double y; /* y-coordinate, usually zero-based */
120     }
121     CvPoint2D64f;
122
123     /* the constructor function */
124     inline CvPoint2D64f cvPoint2D64f( double x, double y );
125
126     /* conversion from CvPoint */
127     inline CvPoint2D64f cvPointTo64f( CvPoint point );
128 </pre>
129
130
131 <hr><h3><a name="decl_CvPoint3D64f">CvPoint3D64f</a></h3>
132 <p class="Blurb">3D point with double precision floating-point coordinates</p>
133 <pre>
134     typedef struct CvPoint3D64f
135     {
136         double x; /* x-coordinate, usually zero-based */
137         double y; /* y-coordinate, usually zero-based */
138         double z; /* z-coordinate, usually zero-based */
139     }
140     CvPoint3D64f;
141
142     /* the constructor function */
143     inline CvPoint3D64f cvPoint3D64f( double x, double y, double z );
144 </pre>
145
146
147 <hr><h3><a name="decl_CvSize">CvSize</a></h3>
148 <p class="Blurb">pixel-accurate size of a rectangle</p>
149 <pre>
150     typedef struct CvSize
151     {
152         int width; /* width of the rectangle */
153         int height; /* height of the rectangle */
154     }
155     CvSize;
156
157     /* the constructor function */
158     inline CvSize cvSize( int width, int height );
159 </pre>
160
161
162 <hr><h3><a name="decl_CvSize2D32f">CvSize2D32f</a></h3>
163 <p class="Blurb">sub-pixel accurate size of a rectangle</p>
164 <pre>
165     typedef struct CvSize2D32f
166     {
167         float width; /* width of the box */
168         float height; /* height of the box */
169     }
170     CvSize2D32f;
171
172     /* the constructor function */
173     inline CvSize2D32f cvSize2D32f( double width, double height );
174 </pre>
175
176
177 <hr><h3><a name="decl_CvRect">CvRect</a></h3>
178 <p class="Blurb">offset and size of a rectangle</p>
179 <pre>
180     typedef struct CvRect
181     {
182         int x; /* x-coordinate of the left-most rectangle corner[s] */
183         int y; /* y-coordinate of the top-most or bottom-most
184                   rectangle corner[s] */
185         int width; /* width of the rectangle */
186         int height; /* height of the rectangle */
187     }
188     CvRect;
189
190     /* the constructor function */
191     inline CvRect cvRect( int x, int y, int width, int height );
192 </pre>
193
194
195 <hr><h3><a name="decl_CvScalar">CvScalar</a></h3>
196 <p class="Blurb">A container for 1-,2-,3- or 4-tuples of numbers</p>
197 <pre>
198     typedef struct CvScalar
199     {
200         double val[4];
201     }
202     CvScalar;
203
204     /* the constructor function: initializes val[0] with val0, val[1] with val1 etc. */
205     inline CvScalar cvScalar( double val0, double val1=0,
206                               double val2=0, double val3=0 );
207     /* the constructor function: initializes val[0]...val[3] with val0123 */
208     inline CvScalar cvScalarAll( double val0123 );
209
210     /* the constructor function: initializes val[0] with val0, val[1]...val[3] with zeros */
211     inline CvScalar cvRealScalar( double val0 );
212 </pre>
213
214
215 <hr><h3><a name="decl_CvTermCriteria">CvTermCriteria</a></h3>
216 <p class="Blurb">Termination criteria for iterative algorithms</p>
217 <pre>
218 #define CV_TERMCRIT_ITER    1
219 #define CV_TERMCRIT_NUMBER  CV_TERMCRIT_ITER
220 #define CV_TERMCRIT_EPS     2
221
222 typedef struct CvTermCriteria
223 {
224     int    type;  /* a combination of CV_TERMCRIT_ITER and CV_TERMCRIT_EPS */
225     int    max_iter; /* maximum number of iterations */
226     double epsilon; /* accuracy to achieve */
227 }
228 CvTermCriteria;
229
230 /* the constructor function */
231 inline  CvTermCriteria  cvTermCriteria( int type, int max_iter, double epsilon );
232
233 /* check termination criteria and transform it so that type=CV_TERMCRIT_ITER+CV_TERMCRIT_EPS,
234    and both max_iter and epsilon are valid */
235 CvTermCriteria cvCheckTermCriteria( CvTermCriteria criteria,
236                                     double default_eps,
237                                     int default_max_iters );
238 </pre>
239
240
241 <!-- *****************************************************************************************
242      *****************************************************************************************
243      ***************************************************************************************** -->
244
245 <!-- <hr><h2><a name="ch1_array_structs">Array structures</a></h2> -->
246
247 <hr><h3><a name="decl_CvMat">CvMat</a></h3>
248 <p class="Blurb">Multi-channel matrix</p>
249 <pre>
250     typedef struct CvMat
251     {
252         int type; /* CvMat signature (CV_MAT_MAGIC_VAL), element type and flags */
253         int step; /* full row length in bytes */
254
255         int* refcount; /* underlying data reference counter */
256
257         union
258         {
259             uchar* ptr;
260             short* s;
261             int* i;
262             float* fl;
263             double* db;
264         } data; /* data pointers */
265
266     #ifdef __cplusplus
267         union
268         {
269             int rows;
270             int height;
271         };
272
273         union
274         {
275             int cols;
276             int width;
277         };
278     #else
279         int rows; /* number of rows */
280         int cols; /* number of columns */
281     #endif
282
283     } CvMat;
284 </pre>
285
286
287 <hr><h3><a name="decl_CvMatND">CvMatND</a></h3>
288 <p class="Blurb">Multi-dimensional dense multi-channel array</p>
289 <pre>
290     typedef struct CvMatND
291     {
292         int type; /* CvMatND signature (CV_MATND_MAGIC_VAL), element type and flags */
293         int dims; /* number of array dimensions */
294
295         int* refcount; /* underlying data reference counter */
296
297         union
298         {
299             uchar* ptr;
300             short* s;
301             int* i;
302             float* fl;
303             double* db;
304         } data; /* data pointers */
305
306         /* pairs (number of elements, distance between elements in bytes) for
307            every dimension */
308         struct
309         {
310             int size;
311             int step;
312         }
313         dim[CV_MAX_DIM];
314
315     } CvMatND;
316 </pre>
317
318
319 <hr><h3><a name="decl_CvSparseMat">CvSparseMat</a></h3>
320 <p class="Blurb">Multi-dimensional sparse multi-channel array</p>
321 <pre>
322     typedef struct CvSparseMat
323     {
324         int type; /* CvSparseMat signature (CV_SPARSE_MAT_MAGIC_VAL), element type and flags */
325         int dims; /* number of dimensions */
326         int* refcount; /* reference counter - not used */
327         struct CvSet* heap; /* a pool of hashtable nodes */
328         void** hashtable; /* hashtable: each entry has a list of nodes
329                              having the same "hashvalue modulo hashsize" */
330         int hashsize; /* size of hashtable */
331         int total; /* total number of sparse array nodes */
332         int valoffset; /* value offset in bytes for the array nodes */
333         int idxoffset; /* index offset in bytes for the array nodes */
334         int size[CV_MAX_DIM]; /* arr of dimension sizes */
335
336     } CvSparseMat;
337 </pre>
338
339
340 <hr><h3><a name="decl_IplImage">IplImage</a></h3>
341 <p class="Blurb">IPL image header</p>
342 <pre>
343     typedef struct _IplImage
344     {
345         int  nSize;         /* sizeof(IplImage) */
346         int  ID;            /* version (=0)*/
347         int  nChannels;     /* Most of OpenCV functions support 1,2,3 or 4 channels */
348         int  alphaChannel;  /* ignored by OpenCV */
349         int  depth;         /* pixel depth in bits: IPL_DEPTH_8U, IPL_DEPTH_8S, IPL_DEPTH_16U,
350                                IPL_DEPTH_16S, IPL_DEPTH_32S, IPL_DEPTH_32F and IPL_DEPTH_64F are supported */
351         char colorModel[4]; /* ignored by OpenCV */
352         char channelSeq[4]; /* ditto */
353         int  dataOrder;     /* 0 - interleaved color channels, 1 - separate color channels.
354                                cvCreateImage can only create interleaved images */
355         int  origin;        /* 0 - top-left origin,
356                                1 - bottom-left origin (Windows bitmaps style) */
357         int  align;         /* Alignment of image rows (4 or 8).
358                                OpenCV ignores it and uses widthStep instead */
359         int  width;         /* image width in pixels */
360         int  height;        /* image height in pixels */
361         struct _IplROI *roi;/* image ROI. when it is not NULL, this specifies image region to process */
362         struct _IplImage *maskROI; /* must be NULL in OpenCV */
363         void  *imageId;     /* ditto */
364         struct _IplTileInfo *tileInfo; /* ditto */
365         int  imageSize;     /* image data size in bytes
366                                (=image->height*image->widthStep
367                                in case of interleaved data)*/
368         char *imageData;  /* pointer to aligned image data */
369         int  widthStep;   /* size of aligned image row in bytes */
370         int  BorderMode[4]; /* border completion mode, ignored by OpenCV */
371         int  BorderConst[4]; /* ditto */
372         char *imageDataOrigin; /* pointer to a very origin of image data
373                                   (not necessarily aligned) -
374                                   it is needed for correct image deallocation */
375     }
376     IplImage;
377 </pre>
378 <p>
379 The structure <code>IplImage</code> came from <em>Intel Image Processing Library</em> where
380 the format is native. OpenCV supports only a subset of possible <code>IplImage</code> formats:
381 <ul>
382 <li><code>alphaChannel</code> is ignored by OpenCV.
383 <li><code>colorModel</code> and <code>channelSeq</code> are ignored by OpenCV. The single OpenCV function
384 <a href="#decl_cvCvtColor">cvCvtColor</a> working with color spaces takes the source and destination color spaces
385 as a parameter.
386 <li><code>dataOrder</code> must be IPL_DATA_ORDER_PIXEL (the color channels are interleaved), however
387 selected channels of planar images can be processed as well if COI is set.
388 <li><code>align</code> is ignored by OpenCV, while <code>widthStep</code> is used to access to subsequent image rows.
389 <li><code>maskROI</code> is not supported. The function that can work with mask take it as a
390 separate parameter. Also the mask in OpenCV is 8-bit, whereas in IPL it is 1-bit.
391 <li><code>tileInfo</code> is not supported.
392 <li><code>BorderMode</code> and <code>BorderConst</code> are not supported. Every OpenCV function
393 working with a pixel neighborhood uses a single hard-coded border mode (most often, replication).
394 </ul>
395 Besides the above restrictions, OpenCV handles ROI differently. It requires that the sizes or ROI sizes of
396 all source and destination images match exactly (according to the operation, e.g. for <a href="#decl_cvPyrDown">cvPyrDown</a>
397 destination width(height) must be equal to source width(height) divided by 2 &plusmn;1),
398 whereas IPL processes the intersection area - that is, the sizes or ROI sizes of all images may
399 vary independently.
400 </p>
401
402
403 <hr><h3><a name="decl_CvArr">CvArr</a></h3>
404 <p class="Blurb">Arbitrary array</p>
405 <pre>
406     typedef void CvArr;
407 </pre>
408 <p>
409 The metatype <code>CvArr*</code> is used <em>only</em> as a function parameter to
410 specify that the function accepts arrays of more than a
411 single type, for example IplImage*, CvMat* or even CvSeq*. The particular array
412 type is determined at runtime by analysing the first 4 bytes of the header.
413 </p>
414
415 <!-- *****************************************************************************************
416      *****************************************************************************************
417      ***************************************************************************************** -->
418
419 <hr><h1><a name="cxcore_arrays">Operations on Arrays</a></h1>
420 <hr><h2><a name="cxcore_arrays_alloc_free">Initialization</a></h2>
421
422 <hr><h3><a name="decl_cvCreateImage">CreateImage</a></h3>
423 <p class="Blurb">Creates header and allocates data</p>
424 <pre>
425 IplImage* cvCreateImage( CvSize size, int depth, int channels );
426 </pre><p><dl>
427 <dt>size<dd>Image width and height.
428 <dt>depth<dd>Bit depth of image elements. Can be one of:<br>
429              IPL_DEPTH_8U - unsigned 8-bit integers<br>
430              IPL_DEPTH_8S - signed 8-bit integers<br>
431              IPL_DEPTH_16U - unsigned 16-bit integers<br>
432              IPL_DEPTH_16S - signed 16-bit integers<br>
433              IPL_DEPTH_32S - signed 32-bit integers<br>
434              IPL_DEPTH_32F - single precision floating-point numbers<br>
435              IPL_DEPTH_64F - double precision floating-point numbers<br>
436 <dt>channels<dd>Number of channels per element(pixel). Can be 1, 2, 3 or 4.
437              The channels are interleaved, for example the
438              usual data layout of a color image is:<br>
439              b0 g0 r0 b1 g1 r1 ...<br>
440              Although in general IPL image format can store
441              non-interleaved images as well and some of OpenCV
442              can process it, this function can create interleaved images
443              only.
444 </dl><p>
445 The function <code>cvCreateImage</code> creates the header and allocates data. This call is a
446 shortened form of
447 <pre>
448     header = cvCreateImageHeader(size,depth,channels);
449     cvCreateData(header);
450 </pre>
451 </p>
452
453
454 <hr><h3><a name="decl_cvCreateImageHeader">CreateImageHeader</a></h3>
455 <p class="Blurb">Allocates, initializes, and returns structure IplImage</p>
456 <pre>
457 IplImage* cvCreateImageHeader( CvSize size, int depth, int channels );
458 </pre><p><dl>
459 <dt>size<dd>Image width and height.
460 <dt>depth<dd>Image depth (see CreateImage).
461 <dt>channels<dd>Number of channels (see CreateImage).
462 </dl><p>
463 The function <code>cvCreateImageHeader</code> allocates, initializes, and returns the structure
464 <code>IplImage</code>. This call is an analogue of
465 <pre>
466   iplCreateImageHeader( channels, 0, depth,
467                         channels == 1 ? "GRAY" : "RGB",
468                         channels == 1 ? "GRAY" : channels == 3 ? "BGR" :
469                         channels == 4 ? "BGRA" : "",
470                         IPL_DATA_ORDER_PIXEL, IPL_ORIGIN_TL, 4,
471                         size.width, size.height,
472                         0,0,0,0);
473 </pre>
474 though it does not use IPL functions by default
475 (see also <code>CV_TURN_ON_IPL_COMPATIBILITY</code> macro)
476 </p>
477
478
479 <hr><h3><a name="decl_cvReleaseImageHeader">ReleaseImageHeader</a></h3>
480 <p class="Blurb">Releases header</p>
481 <pre>
482 void cvReleaseImageHeader( IplImage** image );
483 </pre><p><dl>
484 <dt>image<dd>Double pointer to the deallocated header.
485 </dl><p>
486 The function <code>cvReleaseImageHeader</code> releases the header.
487 This call is an analogue of
488 <pre>
489     if( image )
490     {
491         iplDeallocate( *image, IPL_IMAGE_HEADER | IPL_IMAGE_ROI );
492         *image = 0;
493     }
494 </pre>
495 though it does not use IPL functions by default
496 (see also <code>CV_TURN_ON_IPL_COMPATIBILITY</code>)
497 </p>
498
499
500 <hr><h3><a name="decl_cvReleaseImage">ReleaseImage</a></h3>
501 <p class="Blurb">Releases header and image data</p>
502 <pre>
503 void cvReleaseImage( IplImage** image );
504 </pre><p><dl>
505 <dt>image<dd>Double pointer to the header of the deallocated image.
506 </dl></p><p>
507 The function <code>cvReleaseImage</code> releases the header and the image data. This call is a
508 shortened form of
509 <pre>
510     if( *image )
511     {
512         cvReleaseData( *image );
513         cvReleaseImageHeader( image );
514     }
515 </pre>
516 </p>
517
518
519 <hr><h3><a name="decl_cvInitImageHeader">InitImageHeader</a></h3>
520 <p class="Blurb">Initializes allocated by user image header</p>
521 <pre>
522 IplImage* cvInitImageHeader( IplImage* image, CvSize size, int depth,
523                              int channels, int origin=0, int align=4 );
524 </pre><p><dl>
525 <dt>image<dd>Image header to initialise.
526 <dt>size<dd>Image width and height.
527 <dt>depth<dd>Image depth (see CreateImage).
528 <dt>channels<dd>Number of channels (see CreateImage).
529 <dt>origin<dd><code>IPL_ORIGIN_TL</code> or <code>IPL_ORIGIN_BL</code>.
530 <dt>align<dd>Alignment for image rows, typically 4 or 8 bytes.
531 </dl></p><p>
532 The function <code>cvInitImageHeader</code> initializes the image header structure,
533 pointer to which is passed by the user, and returns the pointer.
534 </p>
535
536
537 <hr><h3><a name="decl_cvCloneImage">CloneImage</a></h3>
538 <p class="Blurb">Makes a full copy of image</p>
539 <pre>
540 IplImage* cvCloneImage( const IplImage* image );
541 </pre><p><dl>
542 <dt>image<dd>Original image.
543 </dl></p><p>
544 The function <code>cvCloneImage</code> makes a full copy of the image including
545 header, ROI and data
546 </p>
547
548
549 <hr><h3><a name="decl_cvSetImageCOI">SetImageCOI</a></h3>
550 <p class="Blurb">Sets channel of interest to given value</p>
551 <pre>
552 void cvSetImageCOI( IplImage* image, int coi );
553 </pre><p><dl>
554 <dt>image<dd>Image header.
555 <dt>coi<dd>Channel of interest.
556 </dl><p>
557 The function <code>cvSetImageCOI</code> sets the channel of interest
558 to a given value. Value 0 means that all channels are selected,
559 1 means that the first channel is selected etc.
560 If ROI is <code>NULL</code> and <code>coi != 0</code>, ROI is allocated.
561 Note that most of OpenCV functions do not support COI, so
562 to process separate image/matrix channel one may copy (via <a href="#decl_cvCopy">cvCopy</a> or
563 <a href="#decl_cvSplit">cvSplit</a>) the channel to separate image/matrix,
564 process it and copy the result back (via <a href="#decl_cvCopy">cvCopy</a> or <a href="#decl_cvCvtPlaneToPix">cvCvtPlaneToPix</a>)
565 if need.</p>
566
567
568 <hr><h3><a name="decl_cvGetImageCOI">GetImageCOI</a></h3>
569 <p class="Blurb">Returns index of channel of interest</p>
570 <pre>
571 int cvGetImageCOI( const IplImage* image );
572 </pre><p><dl>
573 <dt>image<dd>Image header.
574 </dl><p>
575 The function <code>cvGetImageCOI</code> returns channel of interest of
576 the image (it returns 0 if all the channels are selected).</p>
577
578
579 <hr><h3><a name="decl_cvSetImageROI">SetImageROI</a></h3>
580 <p class="Blurb">Sets image ROI to given rectangle</p>
581 <pre>
582 void cvSetImageROI( IplImage* image, CvRect rect );
583 </pre><p><dl>
584 <dt>image<dd>Image header.
585 <dt>rect<dd>ROI rectangle.
586 </dl><p>
587 The function <code>cvSetImageROI</code> sets the image ROI to a given rectangle. If ROI is <code>NULL</code>
588 and the value of the parameter <code>rect</code> is not equal to the whole image, ROI is
589 allocated. Unlike COI, most of OpenCV functions do support ROI and treat
590 it in a way as it would be a separate image (for example, all the pixel
591 coordinates are counted from top-left or bottom-left
592 (depending on the image origin) corner of ROI)</p>
593
594
595 <hr><h3><a name="decl_cvResetImageROI">ResetImageROI</a></h3>
596 <p class="Blurb">Releases image ROI</p>
597 <pre>
598 void cvResetImageROI( IplImage* image );
599 </pre><p><dl>
600 <dt>image<dd>Image header.
601 </dl><p>
602 The function <code>cvResetImageROI</code> releases image ROI. After that the whole image
603 is considered selected. The similar result can be achieved by</p>
604 <pre>
605 cvSetImageROI( image, cvRect( 0, 0, image->width, image->height ));
606 cvSetImageCOI( image, 0 );
607 </pre>
608 <p>
609 But the latter variant does not deallocate <code>image->roi</code>.
610 </p>
611
612
613 <hr><h3><a name="decl_cvGetImageROI">GetImageROI</a></h3>
614 <p class="Blurb">Returns image ROI coordinates</p>
615 <pre>
616 CvRect cvGetImageROI( const IplImage* image );
617 </pre><p><dl>
618 <dt>image<dd>Image header.
619 </dl><p>
620 The function <code>cvGetImageROI</code> returns image ROI coordinates.
621 The rectangle <a href="#decl_cvRect">cvRect</a>(0,0,image->width,image->height) is returned if
622 there is no ROI</p>
623
624
625 <hr><h3><a name="decl_cvCreateMat">CreateMat</a></h3>
626 <p class="Blurb">Creates new matrix</p>
627 <pre>
628 CvMat* cvCreateMat( int rows, int cols, int type );
629 </pre><p><dl>
630 <dt>rows<dd>Number of rows in the matrix.
631 <dt>cols<dd>Number of columns in the matrix.
632 <dt>type<dd>Type of the matrix elements.
633             Usually it is specified in form
634             <code>CV_&lt;bit_depth&gt;(S|U|F)C&lt;number_of_channels&gt;</code>, for example:<br>
635             <code>CV_8UC1</code> means an 8-bit unsigned single-channel matrix,
636             <code>CV_32SC2</code> means a 32-bit signed matrix with two channels.
637 </dl><p>
638 The function <code>cvCreateMat</code> allocates header for the new matrix and underlying data,
639 and returns a pointer to the created matrix. It is a short form for:</p>
640 <pre>
641     CvMat* mat = cvCreateMatHeader( rows, cols, type );
642     cvCreateData( mat );
643 </pre><p>
644 Matrices are stored row by row. All the rows are aligned by 4 bytes.
645 </p>
646
647
648 <hr><h3><a name="decl_cvCreateMatHeader">CreateMatHeader</a></h3>
649 <p class="Blurb">Creates new matrix header</p>
650 <pre>
651 CvMat* cvCreateMatHeader( int rows, int cols, int type );
652 </pre><p><dl>
653 <dt>rows<dd>Number of rows in the matrix.
654 <dt>cols<dd>Number of columns in the matrix.
655 <dt>type<dd>Type of the matrix elements (see <a href="#decl_cvCreateMat">cvCreateMat</a>).
656 </dl><p>
657 The function <code>cvCreateMatHeader</code> allocates new matrix header and returns pointer to
658 it. The matrix data can further be allocated using <a href="#decl_cvCreateData">cvCreateData</a> or set
659 explicitly to user-allocated data via <a href="#decl_cvSetData">cvSetData</a>.
660 </p>
661
662
663 <hr><h3><a name="decl_cvReleaseMat">ReleaseMat</a></h3>
664 <p class="Blurb">Deallocates matrix</p>
665 <pre>
666 void cvReleaseMat( CvMat** mat );
667 </pre><p><dl>
668 <dt>mat<dd>Double pointer to the matrix.
669 </dl><p>
670 The function <code>cvReleaseMat</code> decrements the matrix data reference counter and
671 releases matrix header:</p>
672 <pre>
673     if( *mat )
674         cvDecRefData( *mat );
675     cvFree( (void**)mat );
676 </pre>
677 </p>
678
679
680 <hr><h3><a name="decl_cvInitMatHeader">InitMatHeader</a></h3>
681 <p class="Blurb">Initializes matrix header</p>
682 <pre>
683 CvMat* cvInitMatHeader( CvMat* mat, int rows, int cols, int type,
684                         void* data=NULL, int step=CV_AUTOSTEP );
685 </pre><p><dl>
686 <dt>mat<dd>Pointer to the matrix header to be initialised.
687 <dt>rows<dd>Number of rows in the matrix.
688 <dt>cols<dd>Number of columns in the matrix.
689 <dt>type<dd>Type of the matrix elements.
690 <dt>data<dd>Optional data pointer assigned to the matrix header.
691 <dt>step<dd>Full row width in bytes of the data assigned. By default, the minimal
692 possible step is used, i.e., no gaps is assumed between subsequent rows of the
693 matrix.
694 </dl><p>
695 The function <code>cvInitMatHeader</code> initializes already allocated <a href="#decl_CvMat">CvMat</a> structure. It can
696 be used to process raw data with OpenCV matrix functions.
697 <p>
698 For example, the following code computes matrix product of two matrices, stored
699 as ordinary arrays.
700 </p>
701 </p><p>
702 <font color=blue size=4>Calculating Product of Two Matrices</font></p>
703 <pre>
704    double a[] = { 1, 2, 3, 4
705                   5, 6, 7, 8,
706                   9, 10, 11, 12 };
707
708    double b[] = { 1, 5, 9,
709                   2, 6, 10,
710                   3, 7, 11,
711                   4, 8, 12 };
712
713    double c[9];
714    CvMat Ma, Mb, Mc ;
715
716    cvInitMatHeader( &amp;Ma, 3, 4, CV_64FC1, a );
717    cvInitMatHeader( &amp;Mb, 4, 3, CV_64FC1, b );
718    cvInitMatHeader( &amp;Mc, 3, 3, CV_64FC1, c );
719
720    cvMatMulAdd( &amp;Ma, &amp;Mb, 0, &amp;Mc );
721    // c array now contains product of a(3x4) and b(4x3) matrices
722 </pre></p>
723
724
725 <hr><h3><a name="decl_cvMat">Mat</a></h3>
726 <p class="Blurb">Initializes matrix header (light-weight variant)</p>
727 <pre>
728 CvMat cvMat( int rows, int cols, int type, void* data=NULL );
729 </pre><p><dl>
730 <dt>rows<dd>Number of rows in the matrix.
731 <dt>cols<dd>Number of columns in the matrix.
732 <dt>type<dd>Type of the matrix elements (see CreateMat).
733 <dt>data<dd>Optional data pointer assigned to the matrix header.
734 </dl><p>
735 The function <code>cvMat</code> is a fast inline substitution for <a href="#decl_cvInitMatHeader">cvInitMatHeader</a>.
736 Namely, it is equivalent to:
737 <pre>
738      CvMat mat;
739      cvInitMatHeader( &amp;mat, rows, cols, type, data, CV_AUTOSTEP );
740 </pre>
741 </p>
742
743
744 <hr><h3><a name="decl_cvCloneMat">CloneMat</a></h3>
745 <p class="Blurb">Creates matrix copy</p>
746 <pre>
747 CvMat* cvCloneMat( const CvMat* mat );
748 </pre><p><dl>
749 <dt>mat<dd>Input matrix.
750 </dl><p>
751 The function <code>cvCloneMat</code> creates a copy of input matrix and returns the pointer to
752 it.
753 </p>
754
755
756 <hr><h3><a name="decl_cvCreateMatND">CreateMatND</a></h3>
757 <p class="Blurb">Creates multi-dimensional dense array</p>
758 <pre>
759 CvMatND* cvCreateMatND( int dims, const int* sizes, int type );
760 </pre><p><dl>
761 <dt>dims<dd>Number of array dimensions. It must not exceed CV_MAX_DIM (=32 by default,
762             though it may be changed at build time)
763 <dt>sizes<dd>Array of dimension sizes.
764 <dt>type<dd>Type of array elements. The same as for <a href="#decl_CvMat">CvMat</a>
765 </dl><p>
766 The function <code>cvCreateMatND</code> allocates header for multi-dimensional dense array
767 and the underlying data, and returns pointer to the created array. It is a short form for:</p>
768 <pre>
769     CvMatND* mat = cvCreateMatNDHeader( dims, sizes, type );
770     cvCreateData( mat );
771 </pre><p>
772 Array data is stored row by row. All the rows are aligned by 4 bytes.
773 </p>
774
775
776 <hr><h3><a name="decl_cvCreateMatNDHeader">CreateMatNDHeader</a></h3>
777 <p class="Blurb">Creates new matrix header</p>
778 <pre>
779 CvMatND* cvCreateMatNDHeader( int dims, const int* sizes, int type );
780 </pre><p><dl>
781 <dt>dims<dd>Number of array dimensions.
782 <dt>sizes<dd>Array of dimension sizes.
783 <dt>type<dd>Type of array elements. The same as for CvMat
784 </dl><p>
785 The function <code>cvCreateMatND</code> allocates header for multi-dimensional dense array.
786 The array data can further be allocated using <a href="#decl_cvCreateData">cvCreateData</a> or set
787 explicitly to user-allocated data via <a href="#decl_cvSetData">cvSetData</a>.
788 </p>
789
790
791 <hr><h3><a name="decl_cvReleaseMatND">ReleaseMatND</a></h3>
792 <p class="Blurb">Deallocates multi-dimensional array</p>
793 <pre>
794 void cvReleaseMatND( CvMatND** mat );
795 </pre><p><dl>
796 <dt>mat<dd>Double pointer to the array.
797 </dl><p>
798 The function <code>cvReleaseMatND</code> decrements the array data reference counter and
799 releases the array header:</p>
800 <pre>
801     if( *mat )
802         cvDecRefData( *mat );
803     cvFree( (void**)mat );
804 </pre>
805 </p>
806
807
808 <hr><h3><a name="decl_cvInitMatNDHeader">InitMatNDHeader</a></h3>
809 <p class="Blurb">Initializes multi-dimensional array header</p>
810 <pre>
811 CvMatND* cvInitMatNDHeader( CvMatND* mat, int dims, const int* sizes, int type, void* data=NULL );
812 </pre><p><dl>
813 <dt>mat<dd>Pointer to the array header to be initialized.
814 <dt>dims<dd>Number of array dimensions.
815 <dt>sizes<dd>Array of dimension sizes.
816 <dt>type<dd>Type of array elements. The same as for CvMat
817 <dt>data<dd>Optional data pointer assigned to the matrix header.
818 </dl><p>
819 The function <code>cvInitMatNDHeader</code> initializes <a href="#decl_CvMatND">CvMatND</a> structure allocated by
820 the user.
821 </p>
822
823
824 <hr><h3><a name="decl_cvCloneMatND">CloneMatND</a></h3>
825 <p class="Blurb">Creates full copy of multi-dimensional array</p>
826 <pre>
827 CvMatND* cvCloneMatND( const CvMatND* mat );
828 </pre><p><dl>
829 <dt>mat<dd>Input array.
830 </dl><p>
831 The function <code>cvCloneMatND</code> creates a copy of input array and returns pointer to
832 it.
833 </p>
834
835
836 <hr><h3><a name="decl_cvDecRefData">DecRefData</a></h3>
837 <p class="Blurb">Decrements array data reference counter</p>
838 <pre>
839 void cvDecRefData( CvArr* arr );
840 </pre><p><dl>
841 <dt>arr<dd>array header.
842 </dl><p>
843 The function <code>cvDecRefData</code> decrements <a href="#decl_CvMat">CvMat</a> or <a href="#decl_CvMatND">CvMatND</a> data reference counter if the
844 reference counter pointer is not NULL and deallocates the data if the counter reaches zero.
845 In the current implementation the reference counter is not NULL only if the data was allocated using
846 <a href="#decl_cvCreateData">cvCreateData</a> function, in other cases such as:<br>
847 external data was assigned to the header using <a href="#decl_cvSetData">cvSetData</a><br>
848 the matrix header presents a part of a larger matrix or image<br>
849 the matrix header was converted from image or n-dimensional matrix header<br>
850 <br>
851 the reference counter is set to NULL and thus it is not decremented.
852 Whenever the data is deallocated or not,
853 the data pointer and reference counter pointers are cleared by the function.
854 </p>
855
856
857 <hr><h3><a name="decl_cvIncRefData">IncRefData</a></h3>
858 <p class="Blurb">Increments array data reference counter</p>
859 <pre>
860 int cvIncRefData( CvArr* arr );
861 </pre><p><dl>
862 <dt>arr<dd>array header.
863 </dl><p>
864 The function <code>cvIncRefData</code> increments <a href="#decl_CvMat">CvMat</a> or <a href="#decl_CvMatND">CvMatND</a> data reference counter and
865 returns the new counter value if the reference counter pointer is not NULL, otherwise it returns zero.
866 </p>
867
868
869 <hr><h3><a name="decl_cvCreateData">CreateData</a></h3>
870 <p class="Blurb">Allocates array data</p>
871 <pre>
872 void cvCreateData( CvArr* arr );
873 </pre><p><dl>
874 <dt>arr<dd>Array header.
875 </dl></p><p>
876 The function <code>cvCreateData</code> allocates image, matrix or multi-dimensional array data.
877 Note that in case of matrix types OpenCV allocation functions are used and
878 in case of IplImage they are used too unless <code>CV_TURN_ON_IPL_COMPATIBILITY</code> was called.
879 In the latter case IPL functions are used to allocate the data
880 </p>
881
882
883 <hr><h3><a name="decl_cvReleaseData">ReleaseData</a></h3>
884 <p class="Blurb">Releases array data</p>
885 <pre>
886 void cvReleaseData( CvArr* arr );
887 </pre><p><dl>
888 <dt>arr<dd>Array header
889 </dl><p>
890 The function <code>cvReleaseData</code> releases the array data.
891 In case of <a href="#decl_CvMat">CvMat</a> or <a href="#decl_CvMatND">CvMatND</a> it simply calls cvDecRefData(), that is
892 the function can not deallocate external data. See also the note to <a href="#decl_cvCreateData">cvCreateData</a>.
893 </p>
894
895
896 <hr><h3><a name="decl_cvSetData">SetData</a></h3>
897 <p class="Blurb">Assigns user data to the array header</p>
898 <pre>
899 void cvSetData( CvArr* arr, void* data, int step );
900 </pre><p><dl>
901 <dt>arr<dd>Array header.
902 <dt>data<dd>User data.
903 <dt>step<dd>Full row length in bytes.
904 </dl><p>
905 The function <code>cvSetData</code> assigns user data to the array header.
906 Header should be initialized before using cvCreate*Header,
907 cvInit*Header or <a href="#decl_cvMat">cvMat</a> (in case of matrix) function.
908 </p>
909
910
911 <hr><h3><a name="decl_cvGetRawData">GetRawData</a></h3>
912 <p class="Blurb">Retrieves low-level information about the array</p>
913 <pre>
914 void cvGetRawData( const CvArr* arr, uchar** data,
915                    int* step=NULL, CvSize* roi_size=NULL );
916 </pre><p><dl>
917 <dt>arr<dd>Array header.
918 <dt>data<dd>Output pointer to the whole image origin or ROI origin if
919 ROI is set.
920 <dt>step<dd>Output full row length in bytes.
921 <dt>roi_size<dd>Output ROI size.
922 </dl><p>
923 The function <code>cvGetRawData</code> fills output variables with low-level
924 information about the array data.
925 All output parameters are optional, so some of the pointers
926 may be set to <code>NULL</code>.
927 If the array is <code>IplImage</code> with ROI set,
928 parameters of ROI are returned.
929 </p>
930 <p>The following example shows how to get access to array elements using
931 this function.</p>
932 <p>
933 <font color=blue size=4>Using GetRawData to calculate absolute value of elements of
934 a single-channel floating-point array.</font>
935 <pre>
936     float* data;
937     int step;
938
939     CvSize size;
940     int x, y;
941
942     cvGetRawData( array, (uchar**)&amp;data, &amp;step, &amp;size );
943     step /= sizeof(data[0]);
944
945     for( y = 0; y &lt; size.height; y++, data += step )
946         for( x = 0; x &lt; size.width; x++ )
947             data[x] = (float)fabs(data[x]);
948 </pre></p>
949
950
951 <hr><h3><a name="decl_cvGetMat">GetMat</a></h3>
952 <p class="Blurb">Returns matrix header for arbitrary array</p>
953 <pre>
954 CvMat* cvGetMat( const CvArr* arr, CvMat* header, int* coi=NULL, int allowND=0 );
955 </pre><p><dl>
956 <dt>arr<dd>Input array.
957 <dt>header<dd>Pointer to <a href="#decl_CvMat">CvMat</a> structure used as a temporary buffer.
958 <dt>coi<dd>Optional output parameter for storing COI.
959 <dt>allowND<dd>If non-zero, the function accepts multi-dimensional dense
960               arrays (CvMatND*) and returns 2D (if CvMatND has two dimensions)
961               or 1D matrix (when CvMatND has 1 dimension or more than 2 dimensions).
962               The array must be continuous.
963 </dl><p>
964 The function <code>cvGetMat</code> returns matrix header for the input array that can be
965 matrix - <a href="#decl_CvMat">CvMat</a>, image - <code>IplImage</code> or multi-dimensional dense array - <a href="#decl_CvMatND*">CvMatND*</a>
966 (latter case is allowed only if <code>allowND != 0</code>) .
967 In the case of matrix the function simply returns the input pointer.
968 In the case of <code>IplImage*</code> or <a href="#decl_CvMatND*">CvMatND*</a> it initializes <code>header</code> structure
969 with parameters of the current image ROI and returns pointer to this temporary
970 structure. Because COI is not supported by <a href="#decl_CvMat">CvMat</a>, it is returned separately.
971 <p>
972 The function provides an easy way to handle both types of array - <code>IplImage</code> and
973 <a href="#decl_CvMat">CvMat</a> -, using the same code. Reverse transform from <a href="#decl_CvMat">CvMat</a> to <code>IplImage</code> can be
974 done using <a href="#decl_cvGetImage">cvGetImage</a> function.
975 </p><p>
976 Input array must have underlying data allocated or attached, otherwise the
977 function fails.
978 </p>
979 If the input array is <code>IplImage</code> with planar data layout and COI set, the function
980 returns pointer to the selected plane and COI = 0. It enables per-plane
981 processing of multi-channel images with planar data layout using OpenCV
982 functions.</p>
983
984
985 <hr><h3><a name="decl_cvGetImage">GetImage</a></h3>
986 <p class="Blurb">Returns image header for arbitrary array</p>
987 <pre>
988 IplImage* cvGetImage( const CvArr* arr, IplImage* image_header );
989 </pre><p><dl>
990 <dt>arr<dd>Input array.
991 <dt>image_header<dd>Pointer to <code>IplImage</code> structure used as a temporary buffer.
992 </dl><p>
993 The function <code>cvGetImage</code> returns image header for the input array that can be
994 matrix - <a href="#decl_CvMat*">CvMat*</a>, or image - <code>IplImage*</code>. In the case of image the function simply
995 returns the input pointer. In the case of <a href="#decl_CvMat*">CvMat*</a> it initializes <code>image_header</code> structure
996 with parameters of the input matrix. Note that if we transform <code>IplImage</code> to <a href="#decl_CvMat">CvMat</a> and then transform
997 CvMat back to IplImage, we can get different headers if the ROI is set, and thus some IPL functions
998 that calculate image stride from its width and align may fail on the resultant image.</p>
999
1000
1001 <hr><h3><a name="decl_cvCreateSparseMat">CreateSparseMat</a></h3>
1002 <p class="Blurb">Creates sparse array</p>
1003 <pre>
1004 CvSparseMat* cvCreateSparseMat( int dims, const int* sizes, int type );
1005 </pre><p><dl>
1006 <dt>dims<dd>Number of array dimensions. As opposite to the dense matrix, the number
1007             of dimensions is practically unlimited (up to 2<sup>16</sup>).
1008 <dt>sizes<dd>Array of dimension sizes.
1009 <dt>type<dd>Type of array elements. The same as for CvMat
1010 </dl><p>
1011 The function <code>cvCreateSparseMat</code> allocates multi-dimensional sparse array.
1012 Initially the array contains no elements, that is <a href="#decl_cvGet*D">cvGet*D</a> or
1013 <a href="#decl_cvGetReal*D">cvGetReal*D</a> return zero for every index</p>
1014
1015
1016 <hr><h3><a name="decl_cvReleaseSparseMat">ReleaseSparseMat</a></h3>
1017 <p class="Blurb">Deallocates sparse array</p>
1018 <pre>
1019 void cvReleaseSparseMat( CvSparseMat** mat );
1020 </pre><p><dl>
1021 <dt>mat<dd>Double pointer to the array.
1022 </dl><p>
1023 The function <code>cvReleaseSparseMat</code> releases the sparse array and clears the array pointer upon exit</p>
1024
1025
1026 <hr><h3><a name="decl_cvCloneSparseMat">CloneSparseMat</a></h3>
1027 <p class="Blurb">Creates full copy of sparse array</p>
1028 <pre>
1029 CvSparseMat* cvCloneSparseMat( const CvSparseMat* mat );
1030 </pre><p><dl>
1031 <dt>mat<dd>Input array.
1032 </dl><p>
1033 The function <code>cvCloneSparseMat</code> creates a copy of the input array and returns pointer to the copy.</p>
1034
1035
1036 <hr><h2><a name="cxcore_arrays_get_set">Accessing Elements and sub-Arrays</a></h2>
1037
1038 <hr><h3><a name="decl_cvGetSubRect">GetSubRect</a></h3>
1039 <p class="Blurb">Returns matrix header corresponding to the rectangular sub-array of input image or matrix</p>
1040 <pre>
1041 CvMat* cvGetSubRect( const CvArr* arr, CvMat* submat, CvRect rect );
1042 </pre><p><dl>
1043 <dt>arr<dd>Input array.
1044 <dt>submat<dd>Pointer to the resultant sub-array header.
1045 <dt>rect<dd>Zero-based coordinates of the rectangle of interest.
1046 </dl><p>
1047 The function <code>cvGetSubRect</code> returns header, corresponding
1048 to a specified rectangle of the input array.
1049 In other words, it allows the user to treat a rectangular part
1050 of input array as a stand-alone array. ROI is taken into account by the function
1051 so the sub-array of ROI is actually extracted.</p>
1052
1053
1054 <hr><h3><a name="decl_cvGetRow">GetRow, GetRows</a></h3>
1055 <p class="Blurb">Returns array row or row span</p>
1056 <pre>
1057 CvMat* cvGetRow( const CvArr* arr, CvMat* submat, int row );
1058 CvMat* cvGetRows( const CvArr* arr, CvMat* submat, int start_row, int end_row, int delta_row=1 );
1059 </pre><p><dl>
1060 <dt>arr<dd>Input array.
1061 <dt>submat<dd>Pointer to the resulting sub-array header.
1062 <dt>row<dd>Zero-based index of the selected row.
1063 <dt>start_row<dd>Zero-based index of the starting row (inclusive) of the span.
1064 <dt>end_row<dd>Zero-based index of the ending row (exclusive) of the span.
1065 <dt>delta_row<dd>Index step in the row span. That is, the function extracts every <code>delta_row</code>-th
1066 row from <code>start_row</code> and up to (but not including) <code>end_row</code>.
1067 </dl><p>
1068 The functions <code>GetRow</code> and <code>GetRows</code> return the header, corresponding to a specified
1069 row/row span of the input array. Note that <code>GetRow</code> is a shortcut for <a href="#decl_cvGetRows">cvGetRows</a>:
1070 <pre>
1071 cvGetRow( arr, submat, row ) ~ cvGetRows( arr, submat, row, row + 1, 1 );
1072 </pre></p>
1073
1074
1075 <hr><h3><a name="decl_cvGetCol">GetCol, GetCols</a></h3>
1076 <p class="Blurb">Returns array column or column span</p>
1077 <pre>
1078 CvMat* cvGetCol( const CvArr* arr, CvMat* submat, int col );
1079 CvMat* cvGetCols( const CvArr* arr, CvMat* submat, int start_col, int end_col );
1080 </pre><p><dl>
1081 <dt>arr<dd>Input array.
1082 <dt>submat<dd>Pointer to the resulting sub-array header.
1083 <dt>col<dd>Zero-based index of the selected column.
1084 <dt>start_col<dd>Zero-based index of the starting column (inclusive) of the span.
1085 <dt>end_col<dd>Zero-based index of the ending column (exclusive) of the span.
1086 </dl><p>
1087 The functions <code>GetCol</code> and <code>GetCols</code> return the header, corresponding to a specified
1088 column/column span of the input array. Note that <code>GetCol</code> is a shortcut for <a href="#decl_cvGetCols">cvGetCols</a>:
1089 <pre>
1090 cvGetCol( arr, submat, col ); // ~ cvGetCols( arr, submat, col, col + 1 );
1091 </pre></p>
1092
1093
1094 <hr><h3><a name="decl_cvGetDiag">GetDiag</a></h3>
1095 <p class="Blurb">Returns one of array diagonals</p>
1096 <pre>
1097 CvMat* cvGetDiag( const CvArr* arr, CvMat* submat, int diag=0 );
1098 </pre><p><dl>
1099 <dt>arr<dd>Input array.
1100 <dt>submat<dd>Pointer to the resulting sub-array header.
1101 <dt>diag<dd>Array diagonal. Zero corresponds to the main diagonal, -1 corresponds to the diagonal above
1102 the main etc., 1 corresponds to the diagonal below the main etc.
1103 </dl><p>
1104 The function <code>cvGetDiag</code> returns the header, corresponding to a specified
1105 diagonal of the input array.</p>
1106
1107
1108 <hr><h3><a name="decl_cvGetSize">GetSize</a></h3>
1109 <p class="Blurb">Returns size of matrix or image ROI</p>
1110 <pre>
1111 CvSize cvGetSize( const CvArr* arr );
1112 </pre><p><dl>
1113 <dt>arr<dd>array header.
1114 </dl><p>
1115 The function <code>cvGetSize</code> returns number of rows (CvSize::height) and number of columns
1116 (CvSize::width) of the input matrix or image. In case of image the size of ROI is returned.</p>
1117
1118
1119 <hr><h3><a name="decl_cvInitSparseMatIterator">InitSparseMatIterator</a></h3>
1120 <p class="Blurb">Initializes sparse array elements iterator</p>
1121 <pre>
1122 CvSparseNode* cvInitSparseMatIterator( const CvSparseMat* mat,
1123                                        CvSparseMatIterator* mat_iterator );
1124 </pre><p><dl>
1125 <dt>mat<dd>Input array.
1126 <dt>mat_iterator<dd>Initialized iterator.
1127 </dl><p>
1128 The function <code>cvInitSparseMatIterator</code> initializes iterator of sparse array elements and
1129 returns pointer to the first element, or NULL if the array is empty.</p>
1130
1131
1132 <hr><h3><a name="decl_cvGetNextSparseNode">GetNextSparseNode</a></h3>
1133 <p class="Blurb">Initializes sparse array elements iterator</p>
1134 <pre>
1135 CvSparseNode* cvGetNextSparseNode( CvSparseMatIterator* mat_iterator );
1136 </pre><p><dl>
1137 <dt>mat_iterator<dd>Sparse array iterator.
1138 </dl><p>
1139 The function <code>cvGetNextSparseNode</code> moves iterator to the next sparse matrix element and returns
1140 pointer to it. In the current version there is no any particular order of the elements, because they
1141 are stored in hash table. The sample below demonstrates how to iterate through the sparse matrix:</p>
1142 <p>
1143 <font color=blue size=4>Using <a href="#decl_cvInitSparseMatIterator">cvInitSparseMatIterator</a> and <a href="#decl_cvGetNextSparseNode">cvGetNextSparseNode</a> to calculate sum of
1144 floating-point sparse array.</font>
1145 <pre>
1146     double sum;
1147     int i, dims = cvGetDims( array );
1148     CvSparseMatIterator mat_iterator;
1149     CvSparseNode* node = cvInitSparseMatIterator( array, &amp;mat_iterator );
1150
1151     for( ; node != 0; node = cvGetNextSparseNode( &amp;mat_iterator ))
1152     {
1153         const int* idx = CV_NODE_IDX( array, node ); /* get pointer to the element indices */
1154         float val = *(float*)CV_NODE_VAL( array, node ); /* get value of the element
1155                                                           (assume that the type is CV_32FC1) */
1156         printf( "(" );
1157         for( i = 0; i &lt; dims; i++ )
1158             printf( "%4d%s", idx[i], i &lt; dims - 1 "," : "): " );
1159         printf( "%g\n", val );
1160
1161         sum += val;
1162     }
1163
1164     printf( "\nTotal sum = %g\n", sum );
1165 </pre></p>
1166
1167 <hr><h3><a name="decl_cvGetElemType">GetElemType</a></h3>
1168 <p class="Blurb">Returns type of array elements</p>
1169 <pre>
1170 int cvGetElemType( const CvArr* arr );
1171 </pre><p><dl>
1172 <dt>arr<dd>Input array.
1173 </dl><p>
1174 The functions <code>GetElemType</code> returns type of the array elements as it is described in
1175 cvCreateMat discussion: <pre>CV_8UC1 ... CV_64FC4</pre></p>
1176
1177
1178 <hr><h3><a name="decl_cvGetDims">GetDims, GetDimSize</a></h3>
1179 <p class="Blurb">Return number of array dimensions and their sizes or the size of particular dimension</p>
1180 <pre>
1181 int cvGetDims( const CvArr* arr, int* sizes=NULL );
1182 int cvGetDimSize( const CvArr* arr, int index );
1183 </pre><p><dl>
1184 <dt>arr<dd>Input array.
1185 <dt>sizes<dd>Optional output vector of the array dimension sizes. For 2d arrays the number of rows (height)
1186 goes first, number of columns (width) next.
1187 <dt>index<dd>Zero-based dimension index (for matrices 0 means number of rows, 1 means number of columns;
1188 for images 0 means height, 1 means width).
1189 </dl><p>
1190 The function <code>cvGetDims</code> returns number of array dimensions and their sizes.
1191 In case of <code>IplImage</code> or <a href="#decl_CvMat">CvMat</a> it always returns 2 regardless of number of image/matrix rows.
1192 The function <code>cvGetDimSize</code> returns the particular dimension size (number of elements per that dimension).
1193 For example, the following code calculates total number of array elements in two ways:<pre>
1194
1195 // via cvGetDims()
1196 int sizes[CV_MAX_DIM];
1197 int i, total = 1;
1198 int dims = cvGetDims( arr, size );
1199 for( i = 0; i &lt; dims; i++ )
1200     total *= sizes[i];
1201
1202 // via cvGetDims() and cvGetDimSize()
1203 int i, total = 1;
1204 int dims = cvGetDims( arr );
1205 for( i = 0; i &lt; dims; i++ )
1206     total *= cvGetDimsSize( arr, i );
1207 </pre>
1208 </p>
1209
1210
1211 <hr><h3><a name="decl_cvPtr*D">Ptr*D</a></h3>
1212 <p class="Blurb">Return pointer to the particular array element</p>
1213 <pre>
1214 uchar* cvPtr1D( const CvArr* arr, int idx0, int* type=NULL );
1215 uchar* cvPtr2D( const CvArr* arr, int idx0, int idx1, int* type=NULL );
1216 uchar* cvPtr3D( const CvArr* arr, int idx0, int idx1, int idx2, int* type=NULL );
1217 uchar* cvPtrND( const CvArr* arr, const int* idx, int* type=NULL, int create_node=1, unsigned* precalc_hashval=NULL );
1218 </pre><p><dl>
1219 <dt>arr<dd>Input array.
1220 <dt>idx0<dd>The first zero-based component of the element index
1221 <dt>idx1<dd>The second zero-based component of the element index
1222 <dt>idx2<dd>The third zero-based component of the element index
1223 <dt>idx<dd>Array of the element indices
1224 <dt>type<dd>Optional output parameter: type of matrix elements
1225 <dt>create_node<dd>Optional input parameter for sparse matrices. Non-zero value of the parameter means that
1226 the requested element is created if it does not exist already.
1227 <dt>precalc_hashval<dd>Optional input parameter for sparse matrices. If the pointer is not NULL, the function
1228 does not recalculate the node hash value, but takes it from the specified location. It is useful for speeding
1229 up pair-wise operations (TODO: provide an example)
1230 </dl><p>
1231 The functions <code>>cvPtr*D</code> return pointer to the particular array element.
1232 Number of array dimension should match to the number of indices passed to the function except
1233 for <code>cvPtr1D</code> function that can be used for sequential access to 1D, 2D or nD dense arrays.
1234 </p><p>
1235 The functions can be used for sparse arrays as well - if the requested node does not exist they
1236 create it and set it to zero.</p><p>
1237 All these as well as other functions accessing array elements
1238 (<a href="#decl_cvGet*D">cvGet*D</a>, <a href="#decl_cvGetReal*D">cvGetReal*D</a>,
1239 <a href="#decl_cvSet*D">cvSet*D</a>, <a href="#decl_cvSetReal*D">cvSetReal*D</a>)
1240 raise an error in case if the element index is out of range.
1241 </p>
1242
1243
1244 <hr><h3><a name="decl_cvGet*D">Get*D</a></h3>
1245 <p class="Blurb">Return the particular array element</p>
1246 <pre>
1247 CvScalar cvGet1D( const CvArr* arr, int idx0 );
1248 CvScalar cvGet2D( const CvArr* arr, int idx0, int idx1 );
1249 CvScalar cvGet3D( const CvArr* arr, int idx0, int idx1, int idx2 );
1250 CvScalar cvGetND( const CvArr* arr, const int* idx );
1251 </pre><p><dl>
1252 <dt>arr<dd>Input array.
1253 <dt>idx0<dd>The first zero-based component of the element index
1254 <dt>idx1<dd>The second zero-based component of the element index
1255 <dt>idx2<dd>The third zero-based component of the element index
1256 <dt>idx<dd>Array of the element indices
1257 </dl><p>
1258 The functions <code>cvGet*D</code> return the particular array element. In case of sparse array
1259 the functions return 0 if the requested node does not exist (no new node is created
1260 by the functions)</p>
1261
1262
1263 <hr><h3><a name="decl_cvGetReal*D">GetReal*D</a></h3>
1264 <p class="Blurb">Return the particular element of single-channel array</p>
1265 <pre>
1266 double cvGetReal1D( const CvArr* arr, int idx0 );
1267 double cvGetReal2D( const CvArr* arr, int idx0, int idx1 );
1268 double cvGetReal3D( const CvArr* arr, int idx0, int idx1, int idx2 );
1269 double cvGetRealND( const CvArr* arr, const int* idx );
1270 </pre><p><dl>
1271 <dt>arr<dd>Input array. Must have a single channel.
1272 <dt>idx0<dd>The first zero-based component of the element index
1273 <dt>idx1<dd>The second zero-based component of the element index
1274 <dt>idx2<dd>The third zero-based component of the element index
1275 <dt>idx<dd>Array of the element indices
1276 </dl><p>
1277 The functions <code>cvGetReal*D</code> return the particular element of single-channel array.
1278 If the array has multiple channels, runtime error is raised. Note that <a href="#decl_cvGet*D">cvGet*D</a> function
1279 can be used safely for both single-channel and multiple-channel arrays though they are
1280 a bit slower.</p><p>In case of sparse array
1281 the functions return 0 if the requested node does not exist (no new node is created
1282 by the functions)</p>
1283
1284
1285 <hr><h3><a name="decl_cvmGet">mGet</a></h3>
1286 <p class="Blurb">Return the particular element of single-channel floating-point matrix</p>
1287 <pre>
1288 double cvmGet( const CvMat* mat, int row, int col );
1289 </pre><p><dl>
1290 <dt>mat<dd>Input matrix.
1291 <dt>row<dd>The zero-based index of row.
1292 <dt>col<dd>The zero-based index of column.
1293 </dl><p>
1294 The function <code>cvmGet</code> is a fast replacement for <a href="#decl_cvGetReal2D">cvGetReal2D</a> in case of
1295 single-channel floating-point matrices. It is faster because it is inline,
1296 it does less checks for array type and array element type and it
1297 checks for the row and column ranges only in debug mode.</p>
1298
1299
1300 <hr><h3><a name="decl_cvSet*D">Set*D</a></h3>
1301 <p class="Blurb">Change the particular array element</p>
1302 <pre>
1303 void cvSet1D( CvArr* arr, int idx0, CvScalar value );
1304 void cvSet2D( CvArr* arr, int idx0, int idx1, CvScalar value );
1305 void cvSet3D( CvArr* arr, int idx0, int idx1, int idx2, CvScalar value );
1306 void cvSetND( CvArr* arr, const int* idx, CvScalar value );
1307 </pre><p><dl>
1308 <dt>arr<dd>Input array.
1309 <dt>idx0<dd>The first zero-based component of the element index
1310 <dt>idx1<dd>The second zero-based component of the element index
1311 <dt>idx2<dd>The third zero-based component of the element index
1312 <dt>idx<dd>Array of the element indices
1313 <dt>value<dd>The assigned value
1314 </dl><p>
1315 The functions <code>cvSet*D</code> assign the new value to the particular element of array.
1316 In case of sparse array the functions create the node if it does not exist yet</p>
1317
1318
1319 <hr><h3><a name="decl_cvSetReal*D">SetReal*D</a></h3>
1320 <p class="Blurb">Change the particular array element</p>
1321 <pre>
1322 void cvSetReal1D( CvArr* arr, int idx0, double value );
1323 void cvSetReal2D( CvArr* arr, int idx0, int idx1, double value );
1324 void cvSetReal3D( CvArr* arr, int idx0, int idx1, int idx2, double value );
1325 void cvSetRealND( CvArr* arr, const int* idx, double value );
1326 </pre><p><dl>
1327 <dt>arr<dd>Input array.
1328 <dt>idx0<dd>The first zero-based component of the element index
1329 <dt>idx1<dd>The second zero-based component of the element index
1330 <dt>idx2<dd>The third zero-based component of the element index
1331 <dt>idx<dd>Array of the element indices
1332 <dt>value<dd>The assigned value
1333 </dl><p>
1334 The functions <code>cvSetReal*D</code> assign the new value to the particular element of single-channel array.
1335 If the array has multiple channels, runtime error is raised. Note that <a href="#decl_cvSet*D">cvSet*D</a> function
1336 can be used safely for both single-channel and multiple-channel arrays though they are
1337 a bit slower.</p>
1338 <p>In case of sparse array the functions create the node if it does not exist yet</p>
1339
1340
1341 <hr><h3><a name="decl_cvmSet">mSet</a></h3>
1342 <p class="Blurb">Return the particular element of single-channel floating-point matrix</p>
1343 <pre>
1344 void cvmSet( CvMat* mat, int row, int col, double value );
1345 </pre><p><dl>
1346 <dt>mat<dd>The matrix.
1347 <dt>row<dd>The zero-based index of row.
1348 <dt>col<dd>The zero-based index of column.
1349 <dt>value<dd>The new value of the matrix element
1350 </dl><p>
1351 The function <code>cvmSet</code> is a fast replacement for <a href="#decl_cvSetReal2D">cvSetReal2D</a> in case of
1352 single-channel floating-point matrices. It is faster because it is inline,
1353 it does less checks for array type and array element type and it
1354 checks for the row and column ranges only in debug mode.</p>
1355
1356
1357 <hr><h3><a name="decl_cvClearND">ClearND</a></h3>
1358 <p class="Blurb">Clears the particular array element</p>
1359 <pre>
1360 void cvClearND( CvArr* arr, const int* idx );
1361 </pre><p><dl>
1362 <dt>arr<dd>Input array.
1363 <dt>idx<dd>Array of the element indices
1364 </dl><p>
1365 The function <a href="#decl_cvClearND">cvClearND</a> clears (sets to zero)
1366 the particular element of dense array or deletes the element of sparse array.
1367 If the element does not exists, the function does nothing.</p>
1368
1369
1370 <hr><h2><a name="cxcore_arrays_copying">Copying and Filling</a></h2>
1371
1372
1373 <hr><h3><a name="decl_cvCopy">Copy</a></h3>
1374 <p class="Blurb">Copies one array to another</p>
1375 <pre>
1376 void cvCopy( const CvArr* src, CvArr* dst, const CvArr* mask=NULL );
1377 </pre><p><dl>
1378 <dt>src<dd>The source array.
1379 <dt>dst<dd>The destination array.
1380 <dt>mask<dd>Operation mask, 8-bit single channel array; specifies elements of
1381 destination array to be changed.
1382 </dl><p>
1383 The function <code>cvCopy</code> copies selected elements from input array to output array:</p>
1384 <p>
1385 dst(I)=src(I) if mask(I)!=0.
1386 </p><p>If any of the passed arrays is of <code>IplImage</code> type, then its ROI and COI fields are
1387 used. Both arrays must have the same type, the same number of dimensions and the same size.
1388 The function can also copy sparse arrays (mask is not supported in this case).</p>
1389
1390
1391 <hr><h3><a name="decl_cvSet">Set</a></h3>
1392 <p class="Blurb">Sets every element of array to given value</p>
1393 <pre>
1394 void cvSet( CvArr* arr, CvScalar value, const CvArr* mask=NULL );
1395 </pre><p><dl>
1396 <dt>arr<dd>The destination array.
1397 <dt>value<dd>Fill value.
1398 <dt>mask<dd>Operation mask, 8-bit single channel array; specifies elements of
1399 destination array to be changed.
1400 </dl><p>
1401 The function <code>cvSet</code> copies scalar <code>value</code> to every selected element of the destination
1402 array:</p>
1403 <pre>arr(I)=value if mask(I)!=0</pre>
1404 <p>If array <code>arr</code> is of <code>IplImage</code> type, then is ROI used, but COI must not be
1405 set.</p>
1406
1407
1408 <hr><h3><a name="decl_cvSetZero">SetZero</a></h3>
1409 <p class="Blurb">Clears the array</p>
1410 <pre>
1411 void cvSetZero( CvArr* arr );
1412 #define cvZero cvSetZero
1413 </pre><p><dl>
1414 <dt>arr<dd>array to be cleared.
1415 </dl><p>
1416 The function <code>cvSetZero</code> clears the array. In case of dense arrays
1417 (CvMat, CvMatND or IplImage) cvZero(array) is equivalent to cvSet(array,cvScalarAll(0),0),
1418 in case of sparse arrays all the elements are removed.</p>
1419
1420
1421 <hr><h3><a name="decl_cvSetIdentity">SetIdentity</a></h3>
1422 <p class="Blurb">Initializes scaled identity matrix</p>
1423 <pre>
1424 void cvSetIdentity( CvArr* mat, CvScalar value=cvRealScalar(1) );
1425 </pre><p><dl>
1426 <dt>arr<dd>The matrix to initialize (not necessarily square).
1427 <dt>value<dd>The value to assign to the diagonal elements.
1428 </dl><p>
1429 The function <code>cvSetIdentity</code> initializes scaled identity matrix:</p>
1430 <pre>
1431 arr(i,j)=value if i=j,
1432        0 otherwise
1433 </pre>
1434
1435
1436 <hr><h3><a name="decl_cvRange">Range</a></h3>
1437 <p class="Blurb">Fills matrix with given range of numbers</p>
1438 <pre>
1439 void cvRange( CvArr* mat, double start, double end );
1440 </pre><p><dl>
1441 <dt>mat<dd>The matrix to initialize. It should be single-channel 32-bit, integer or floating-point.
1442 <dt>start<dd>The lower inclusive boundary of the range.
1443 <dt>end<dd>The upper exclusive boundary of the range.
1444 </dl><p>
1445 The function <code>cvRange</code> initializes the matrix as following:</p>
1446 <pre>
1447 arr(i,j)=(end-start)*(i*cols(arr)+j)/(cols(arr)*rows(arr))
1448 </pre>
1449 For example, the following code will initialize 1D vector with subsequent integer numbers.
1450 <pre>
1451 CvMat* A = cvCreateMat( 1, 10, CV_32S );
1452 cvRange( A, 0, A->cols ); // A will be initialized as [0,1,2,3,4,5,6,7,8,9]
1453 </pre>
1454
1455 <!-- *****************************************************************************************
1456      *****************************************************************************************
1457      ***************************************************************************************** -->
1458
1459 <hr><h2><a name="cxcore_arrays_permute">Transforms and Permutations</a></h2>
1460
1461 <hr><h3><a name="decl_cvReshape">Reshape</a></h3>
1462 <p class="Blurb">Changes shape of matrix/image without copying data</p>
1463 <pre>
1464 CvMat* cvReshape( const CvArr* arr, CvMat* header, int new_cn, int new_rows=0 );
1465 </pre><p><dl>
1466 <dt>arr<dd>Input array.
1467 <dt>header<dd>Output header to be filled.
1468 <dt>new_cn<dd>New number of channels. <code>new_cn = 0</code> means that number of channels remains unchanged.
1469 <dt>new_rows<dd>New number of rows. <code>new_rows = 0</code> means that number of rows remains unchanged unless
1470 it needs to be changed according to <code>new_cn</code> value.
1471 destination array to be changed.
1472 </dl><p>
1473 The function <code>cvReshape</code> initializes CvMat header so that it points to the same data as
1474 the original array but has different shape - different number of channels,
1475 different number of rows or both.</p><p>For example, the following code creates one image buffer and
1476 two image headers, first is for 320x240x3 image and the second is for 960x240x1 image:</p>
1477 <pre>
1478 IplImage* color_img = cvCreateImage( cvSize(320,240), IPL_DEPTH_8U, 3 );
1479 CvMat gray_mat_hdr;
1480 IplImage gray_img_hdr, *gray_img;
1481 cvReshape( color_img, &amp;gray_mat_hdr, 1 );
1482 gray_img = cvGetImage( &amp;gray_mat_hdr, &amp;gray_img_hdr );
1483 </pre>
1484 <p>And the next example converts 3x3 matrix to a single 1x9 vector</p>
1485 <pre>
1486 CvMat* mat = cvCreateMat( 3, 3, CV_32F );
1487 CvMat row_header, *row;
1488 row = cvReshape( mat, &amp;row_header, 0, 1 );
1489 </pre>
1490
1491
1492 <hr><h3><a name="decl_cvReshapeMatND">ReshapeMatND</a></h3>
1493 <p class="Blurb">Changes shape of multi-dimensional array w/o copying data</p>
1494 <pre>
1495 CvArr* cvReshapeMatND( const CvArr* arr,
1496                        int sizeof_header, CvArr* header,
1497                        int new_cn, int new_dims, int* new_sizes );
1498
1499 #define cvReshapeND( arr, header, new_cn, new_dims, new_sizes )   \
1500       cvReshapeMatND( (arr), sizeof(*(header)), (header),         \
1501                       (new_cn), (new_dims), (new_sizes))
1502
1503 </pre><p><dl>
1504 <dt>arr<dd>Input array.
1505 <dt>sizeof_header<dd>Size of output header to distinguish between IplImage, CvMat and CvMatND output headers.
1506 <dt>header<dd>Output header to be filled.
1507 <dt>new_cn<dd>New number of channels. <code>new_cn = 0</code> means that number of channels remains unchanged.
1508 <dt>new_dims<dd>New number of dimensions. <code>new_dims = 0</code> means that number of dimensions remains the same.
1509 <dt>new_sizes<dd>Array of new dimension sizes. Only <code>new_dims-1</code> values are used, because the total number of
1510 elements must remain the same. Thus, if <code>new_dims = 1</code>, <code>new_sizes</code> array is not used
1511 </dl><p>
1512 The function <code>cvReshapeMatND</code> is an advanced version of <a href="#decl_cvReshape">cvReshape</a> that can work
1513 with multi-dimensional arrays as well (though, it can work with ordinary images and matrices)
1514 and change the number of dimensions. Below are the two samples
1515 from the <a href="#decl_cvReshape">cvReshape</a> description rewritten using <a href="#decl_cvReshapeMatND">cvReshapeMatND</a>:</p>
1516 <pre>
1517 IplImage* color_img = cvCreateImage( cvSize(320,240), IPL_DEPTH_8U, 3 );
1518 IplImage gray_img_hdr, *gray_img;
1519 gray_img = (IplImage*)cvReshapeND( color_img, &amp;gray_img_hdr, 1, 0, 0 );
1520
1521 ...
1522
1523 /* second example is modified to convert 2x2x2 array to 8x1 vector */
1524 int size[] = { 2, 2, 2 };
1525 CvMatND* mat = cvCreateMatND( 3, size, CV_32F );
1526 CvMat row_header, *row;
1527 row = cvReshapeND( mat, &amp;row_header, 0, 1, 0 );
1528 </pre>
1529
1530
1531 <hr><h3><a name="decl_cvRepeat">Repeat</a></h3>
1532 <p class="Blurb">Fill destination array with tiled source array</p>
1533 <pre>
1534 void cvRepeat( const CvArr* src, CvArr* dst );
1535 </pre><p><dl>
1536 <dt>src<dd>Source array, image or matrix.
1537 <dt>dst<dd>Destination array, image or matrix.
1538 </dl><p>
1539 The function <code>cvRepeat</code> fills the destination array with source array tiled:</p>
1540 <pre>dst(i,j)=src(i mod rows(src), j mod cols(src))</pre>
1541 <p>
1542 So the destination array may be as larger as well as smaller than
1543 the source array.
1544 </p>
1545
1546
1547 <hr><h3><a name="decl_cvFlip">Flip</a></h3>
1548 <p class="Blurb">Flip a 2D array around vertical, horizontal or both axises</p>
1549 <pre>
1550 void  cvFlip( const CvArr* src, CvArr* dst=NULL, int flip_mode=0);
1551 #define cvMirror cvFlip
1552
1553 </pre><p><dl>
1554 <dt>src<dd>Source array.
1555 <dt>dst<dd>Destination array. If <code>dst = NULL</code> the flipping is done in-place.
1556 <dt>flip_mode<dd>Specifies how to flip the array.<br>
1557                  flip_mode = 0 means flipping around x-axis,
1558                  flip_mode > 0 (e.g. 1) means flipping around y-axis
1559                  and flip_mode &lt; 0 (e.g. -1) means flipping around both axises.
1560                  See also the discussion below for the formulas
1561 </dl><p>
1562 The function <code>cvFlip</code> flips the array in one of different 3 ways
1563 (row and column indices are 0-based):</p>
1564 <pre>dst(i,j)=src(rows(src)-i-1,j) if flip_mode = 0</pre>
1565 <pre>dst(i,j)=src(i,cols(src1)-j-1) if flip_mode > 0</pre>
1566 <pre>dst(i,j)=src(rows(src)-i-1,cols(src)-j-1) if flip_mode &lt; 0</pre>
1567 <p>The example scenario of the function use are:
1568 <ul>
1569 <li>
1570 vertical flipping of the image (flip_mode > 0) to switch between top-left
1571 and bottom-left image origin, which is typical operation in video processing under Win32 systems.</li>
1572 <li>
1573 horizontal flipping of the image with subsequent horizontal shift and absolute difference calculation
1574 to check for a vertical-axis symmetry (flip_mode > 0)</li>
1575 <li>
1576 simultaneous horizontal and vertical flipping of the image with subsequent shift and
1577 absolute difference calculation to check for a central symmetry (flip_mode &lt; 0)</li>
1578 <li>reversing the order of 1d point arrays(flip_mode > 0)</li>
1579 </ul></p>
1580
1581
1582 <hr><h3><a name="decl_cvSplit">Split</a></h3>
1583 <p class="Blurb">Divides multi-channel array into several single-channel arrays or extracts
1584 a single channel from the array</p>
1585 <pre>
1586 void cvSplit( const CvArr* src, CvArr* dst0, CvArr* dst1,
1587               CvArr* dst2, CvArr* dst3 );
1588 #define cvCvtPixToPlane cvSplit
1589 </pre><p><dl>
1590 <dt>src<dd>Source array.
1591 <dt>dst0...dst3<dd>Destination channels.
1592 </dl><p>
1593 The function <code>cvSplit</code> divides a multi-channel array into separate single-channel arrays.
1594 Two modes are available for the operation. If the source array has N channels then if
1595 the first N destination channels are not NULL, all they are extracted from the source array,
1596 otherwise if only a single destination channel of the first N is not NULL, this particular channel
1597 is extracted, otherwise an error is raised. Rest of destination channels (beyond the first N)
1598 must always be NULL.
1599 For IplImage <a href="#decl_cvCopy">cvCopy</a> with COI set can be also used to extract a single channel from the image.</p>
1600
1601
1602 <hr><h3><a name="decl_cvMerge">Merge</a></h3>
1603 <p class="Blurb">Composes multi-channel array from several single-channel arrays or inserts a
1604 single channel into the array</p>
1605 <pre>
1606 void cvMerge( const CvArr* src0, const CvArr* src1,
1607               const CvArr* src2, const CvArr* src3, CvArr* dst );
1608 #define cvCvtPlaneToPix cvMerge
1609 </pre><p><dl>
1610 <dt>src0... src3<dd>Input channels.
1611 <dt>dst<dd>Destination array.
1612 </dl><p>
1613 The function <code>cvMerge</code> is the opposite to the previous.
1614 If the destination array has N channels then if
1615 the first N input channels are not NULL, all they are copied to the destination array,
1616 otherwise if only a single source channel of the first N is not NULL, this particular channel is copied
1617 into the destination array, otherwise an error is raised. Rest of source channels (beyond the first N)
1618 must always be NULL.
1619 For IplImage <a href="#decl_cvCopy">cvCopy</a> with COI set can be also used to insert a single channel into the image.
1620 </p>
1621
1622
1623 <hr><h3><a name="decl_cvMixChannels">MixChannels</a></h3>
1624 <p class="Blurb">Copies several channels from input arrays to
1625    certain channels of output arrays</p>
1626 <pre>
1627 void cvMixChannels( const CvArr** src, int src_count,
1628                     CvArr** dst, int dst_count,
1629                     const int* from_to, int pair_count );
1630 </pre><p><dl>
1631 <dt>src<dd>The array of input arrays.
1632 <dt>src_count<dd>The number of input arrays.
1633 <dt>dst<dd>The array of output arrays.
1634 <dt>dst_count<dd>The number of output arrays.
1635 <dt>from_to<dd>The array of pairs of indices of the planes copied.
1636 <code>from_to[k*2]</code> is the 0-based index of the input plane,
1637 and <code>from_to[k*2+1]</code> is the index of the output plane, where the continuous numbering
1638 of the planes over all the input and over all the output arrays is used.
1639 When <code>from_to[k*2]</code> is negative, the corresponding output plane is filled with 0's.
1640 <dt>pair_count<dd>The number of pairs in <code>from_to</code>, or the number of the planes copied.
1641 </dl><p>
1642 The function <code>cvMixChannels</code> is a generalized form of <a href="#decl_cvSplit">cvSplit</a> and
1643 <a href="#decl_cvMerge">cvMerge</a> and some forms of <a href="opencvref_cv.htm#decl_cvCvtColor">cvCvtColor</a>.
1644 It can be used to change the order of the planes, add/remove alpha
1645 channel, extract or insert a single plane or multiple planes etc.
1646 Below is the example, how to split 4-channel RGBA image into 3-channel BGR (i.e. with R&B swapped) and
1647 separate alpha channel images:</p>
1648 <pre>
1649     CvMat* rgba = cvCreateMat( 100, 100, CV_8UC4 );
1650     CvMat* bgr = cvCreateMat( rgba->rows, rgba->cols, CV_8UC3 );
1651     CvMat* alpha = cvCreateMat( rgba->rows, rgba->cols, CV_8UC1 );
1652     CvArr* out[] = { bgr, alpha };
1653     int from_to[] = { 0, 2, 1, 1, 2, 0, 3, 3 };
1654     cvSet( rgba, cvScalar(1,2,3,4) );
1655     cvMixChannels( (const CvArr**)&rgba, 1, out, 2, from_to, 4 );
1656 </pre>
1657
1658
1659 <hr><h3><a name="decl_cvRandShuffle">RandShuffle</a></h3>
1660 <p class="Blurb">Randomly shuffles the array elements</p>
1661 <pre>
1662 void cvRandShuffle( CvArr* mat, CvRNG* rng, double iter_factor=1. );
1663 </pre><p><dl>
1664 <dt>mat<dd>The input/output matrix. It is shuffled in-place.
1665 <dt>rng<dd>The <a href="#cxcore_arrays_rng">Random Number Generator</a>
1666            used to shuffle the elements. When the pointer is NULL,
1667            a temporary RNG will be created and used.
1668 <dt>iter_factor<dd>The relative parameter that characterizes intensity of the shuffling performed.
1669                    See the description below.
1670 </dl><p>
1671 The function <code>cvRandShuffle</code> shuffles the matrix by swapping randomly chosen pairs
1672 of the matrix elements on each iteration (where each element may contain several components in case of multi-channel arrays).
1673 The number of iterations (i.e. pairs swapped) is <code>round(iter_factor*rows(mat)*cols(mat))</code>, so
1674 <code>iter_factor=0</code> means that no shuffling is done,
1675 <code>iter_factor=1</code> means that the function swaps
1676 <code>rows(mat)*cols(mat)</code> random pairs etc.
1677 </p>
1678
1679
1680 <hr><h2><a name="cxcore_arrays_arithm_logic">Arithmetic, Logic and Comparison</a></h2>
1681
1682
1683 <hr><h3><a name="decl_cvLUT">LUT</a></h3>
1684 <p class="Blurb">Performs look-up table transform of array</p>
1685 <pre>
1686 void cvLUT( const CvArr* src, CvArr* dst, const CvArr* lut );
1687 </pre><p><dl>
1688 <dt>src<dd>Source array of 8-bit elements.
1689 <dt>dst<dd>Destination array of arbitrary depth and of the same number of channels as the
1690 source array.
1691 <dt>lut<dd>Look-up table of 256 elements; should have the same depth as the
1692 destination array. In case of multi-channel source and destination arrays, the table
1693 should either have a single-channel (in this case the same table is used for all channels),
1694 or the same number of channels as the source/destination array.
1695 </dl><p>
1696 The function <code>cvLUT</code> fills the destination array with values
1697 from the look-up table. Indices of the entries are taken from the source array. That is, the
1698 function processes each element of <code>src</code> as following:</p>
1699 <pre>
1700 dst(I)=lut[src(I)+DELTA]
1701 </pre>
1702 where <code>DELTA=0</code> if <code>src</code> has depth <code>CV_8U</code>, and
1703 <code>DELTA=128</code> if <code>src</code> has depth <code>CV_8S</code>.
1704 </p>
1705
1706
1707 <hr><h3><a name="decl_cvConvertScale">ConvertScale</a></h3>
1708 <p class="Blurb">Converts one array to another with optional linear transformation</p>
1709 <pre>
1710 void cvConvertScale( const CvArr* src, CvArr* dst, double scale=1, double shift=0 );
1711
1712 #define cvCvtScale cvConvertScale
1713 #define cvScale  cvConvertScale
1714 #define cvConvert( src, dst )  cvConvertScale( (src), (dst), 1, 0 )
1715 </pre><p><dl>
1716 <dt>src<dd>Source array.
1717 <dt>dst<dd>Destination array.
1718 <dt>scale<dd>Scale factor.
1719 <dt>shift<dd>Value added to the scaled source array elements.
1720 </dl><p>
1721 The function <code>cvConvertScale</code> has several different purposes and thus has several synonyms.
1722 It copies one array to another with optional scaling, which is performed first, and/or optional type conversion, performed after:</p>
1723 <pre>dst(I)=src(I)*scale + (shift,shift,...)</pre>
1724 <p>All the channels of multi-channel arrays are processed independently.</p><p>
1725 The type conversion is done with rounding and saturation, that is if a result of scaling + conversion can not
1726 be represented exactly by a value of destination array element type, it is set to the nearest
1727 representable value on the real axis.</p>
1728 <p>In case of <code>scale=1, shift=0</code> no pre-scaling is done. This is a specially optimized case and it
1729 has the appropriate <a href="#decl_cvConvert">cvConvert</a> synonym. If source and destination array types have
1730 equal types, this is also a special case that can be used to scale and shift a matrix or an image and
1731 that fits to <a href="#decl_cvScale">cvScale</a> synonym.</p>
1732
1733
1734 <hr><h3><a name="decl_cvConvertScaleAbs">ConvertScaleAbs</a></h3>
1735 <p class="Blurb">Converts input array elements to 8-bit unsigned integer another with optional linear transformation</p>
1736 <pre>
1737 void cvConvertScaleAbs( const CvArr* src, CvArr* dst, double scale=1, double shift=0 );
1738 #define cvCvtScaleAbs cvConvertScaleAbs
1739
1740 </pre><p><dl>
1741 <dt>src<dd>Source array.
1742 <dt>dst<dd>Destination array (should have 8u depth).
1743 <dt>scale<dd>ScaleAbs factor.
1744 <dt>shift<dd>Value added to the scaled source array elements.
1745 </dl><p>
1746 The function <code>cvConvertScaleAbs</code> is similar to the previous one, but it stores absolute values
1747 of the conversion results:</p>
1748 <pre>dst(I)=abs(src(I)*scale + (shift,shift,...))</pre>
1749 <p>
1750 The function supports only destination arrays of 8u (8-bit unsigned integers) type, for
1751 other types the function can be emulated by combination of <a href="#decl_cvConvertScale">cvConvertScale</a> and <a href="#decl_cvAbsDiffS">cvAbs</a>
1752 functions.</p>
1753
1754
1755 <hr><h3><a name="decl_cvAdd">Add</a></h3>
1756 <p class="Blurb">Computes per-element sum of two arrays</p>
1757 <pre>
1758 void cvAdd( const CvArr* src1, const CvArr* src2, CvArr* dst, const CvArr* mask=NULL );
1759 </pre><p><dl>
1760
1761 <dt>src1<dd>The first source array.
1762 <dt>src2<dd>The second source array.
1763 <dt>dst<dd>The destination array.
1764 <dt>mask<dd>Operation mask, 8-bit single channel array; specifies elements of
1765 destination array to be changed.
1766 </dl><p>
1767 The function <code>cvAdd</code> adds one array to another one:</p>
1768 <pre>dst(I)=src1(I)+src2(I) if mask(I)!=0</pre>
1769 <p>All the arrays must have the same type, except the mask, and the same size (or ROI size)</p>
1770
1771
1772 </p><hr><h3><a name="decl_cvAddS">AddS</a></h3>
1773 <p class="Blurb">Computes sum of array and scalar</p>
1774 <pre>
1775 void cvAddS( const CvArr* src, CvScalar value, CvArr* dst, const CvArr* mask=NULL );
1776 </pre><p><dl>
1777 <dt>src<dd>The source array.
1778 <dt>value<dd>Added scalar.
1779 <dt>dst<dd>The destination array.
1780 <dt>mask<dd>Operation mask, 8-bit single channel array; specifies elements of
1781 destination array to be changed.
1782 </dl><p>
1783 The function <code>cvAddS</code> adds scalar <code>value</code> to every element in the source array <code>src1</code> and
1784 stores the result in <code>dst</code><p>
1785 <pre>dst(I)=src(I)+value if mask(I)!=0</pre>
1786 <p>All the arrays must have the same type, except the mask, and the same size (or ROI size)</p>
1787
1788
1789 <hr><h3><a name="decl_cvAddWeighted">AddWeighted</a></h3>
1790 <p class="Blurb">Computes weighted sum of two arrays</p>
1791 <pre>
1792 void  cvAddWeighted( const CvArr* src1, double alpha,
1793                      const CvArr* src2, double beta,
1794                      double gamma, CvArr* dst );
1795 </pre><p><dl>
1796 <dt>src1<dd>The first source array.
1797 <dt>alpha<dd>Weight of the first array elements.
1798 <dt>src2<dd>The second source array.
1799 <dt>beta<dd>Weight of the second array elements.
1800 <dt>dst<dd>The destination array.
1801 <dt>gamma<dd>Scalar, added to each sum.
1802 </dl><p>
1803 The function <code>cvAddWeighted</code> calculated weighted sum
1804 of two arrays as following:</p>
1805 <pre>dst(I)=src1(I)*alpha+src2(I)*beta+gamma</pre>
1806 <p>All the arrays must have the same type and the same size (or ROI size)</p>
1807
1808
1809 <hr><h3><a name="decl_cvSub">Sub</a></h3>
1810 <p class="Blurb">Computes per-element difference between two arrays</p>
1811 <pre>
1812 void cvSub( const CvArr* src1, const CvArr* src2, CvArr* dst, const CvArr* mask=NULL );
1813 </pre><p><dl>
1814 <dt>src1<dd>The first source array.
1815 <dt>src2<dd>The second source array.
1816 <dt>dst<dd>The destination array.
1817 <dt>mask<dd>Operation mask, 8-bit single channel array; specifies elements of
1818 destination array to be changed.
1819 </dl><p>
1820 The function <code>cvSub</code> subtracts one array from another one:</p>
1821 <pre>dst(I)=src1(I)-src2(I) if mask(I)!=0</pre>
1822 <p>All the arrays must have the same type, except the mask, and the same size (or ROI size)</p>
1823
1824
1825 </p><hr><h3><a name="decl_cvSubS">SubS</a></h3>
1826 <p class="Blurb">Computes difference between array and scalar</p>
1827 <pre>
1828 void cvSubS( const CvArr* src, CvScalar value, CvArr* dst, const CvArr* mask=NULL );
1829 </pre><p><dl>
1830 <dt>src<dd>The source array.
1831 <dt>value<dd>Subtracted scalar.
1832 <dt>dst<dd>The destination array.
1833 <dt>mask<dd>Operation mask, 8-bit single channel array; specifies elements of
1834 destination array to be changed.
1835 </dl><p>
1836 The function <code>cvSubS</code> subtracts a scalar from every element of the source array:<p>
1837 <pre>dst(I)=src(I)-value if mask(I)!=0</pre>
1838 <p>All the arrays must have the same type, except the mask, and the same size (or ROI size)</p>
1839
1840
1841 <hr><h3><a name="decl_cvSubRS">SubRS</a></h3>
1842 <p class="Blurb">Computes difference between scalar and array</p>
1843 <pre>
1844 void cvSubRS( const CvArr* src, CvScalar value, CvArr* dst, const CvArr* mask=NULL );
1845 </pre><p><dl>
1846 <dt>src<dd>The first source array.
1847 <dt>value<dd>Scalar to subtract from.
1848 <dt>dst<dd>The destination array.
1849 <dt>mask<dd>Operation mask, 8-bit single channel array; specifies elements of
1850 destination array to be changed.
1851 </dl><p>
1852 The function <code>cvSubRS</code> subtracts every element of source array from a scalar:</p>
1853 <pre>dst(I)=value-src(I) if mask(I)!=0</pre>
1854 <p>All the arrays must have the same type, except the mask, and the same size (or ROI size)</p>
1855
1856
1857 <hr><h3><a name="decl_cvMul">Mul</a></h3>
1858 <p class="Blurb">Calculates per-element product of two arrays</p>
1859 <pre>
1860 void cvMul( const CvArr* src1, const CvArr* src2, CvArr* dst, double scale=1 );
1861 </pre><p><dl>
1862 <dt>src1<dd>The first source array.
1863 <dt>src2<dd>The second source array.
1864 <dt>dst<dd>The destination array.
1865 <dt>scale<dd>Optional scale factor
1866 </dl><p>
1867 The function <code>cvMul</code> calculates per-element product of two arrays:</p>
1868 <pre>dst(I)=scale&bull;src1(I)&bull;src2(I)</pre>
1869 <p>All the arrays must have the same type, and the same size (or ROI size)</p>
1870
1871
1872 <hr><h3><a name="decl_cvDiv">Div</a></h3>
1873 <p class="Blurb">Performs per-element division of two arrays</p>
1874 <pre>
1875 void cvDiv( const CvArr* src1, const CvArr* src2, CvArr* dst, double scale=1 );
1876 </pre><p><dl>
1877 <dt>src1<dd>The first source array. If the pointer is NULL, the array is assumed to be all 1&#146;s.
1878 <dt>src2<dd>The second source array.
1879 <dt>dst<dd>The destination array.
1880 <dt>scale<dd>Optional scale factor
1881 </dl><p>
1882 The function <code>cvDiv</code> divides one array by another:</p>
1883 <pre>
1884 dst(I)=scale&bull;src1(I)/src2(I), if src1!=NULL
1885 dst(I)=scale/src2(I),      if src1=NULL
1886 </pre>
1887 <p>All the arrays must have the same type, and the same size (or ROI size)</p>
1888
1889
1890 <hr><h3><a name="decl_cvAnd">And</a></h3>
1891 <p class="Blurb">Calculates per-element bit-wise conjunction of two arrays</p>
1892 <pre>
1893 void cvAnd( const CvArr* src1, const CvArr* src2, CvArr* dst, const CvArr* mask=NULL );
1894 </pre><p><dl>
1895 <dt>src1<dd>The first source array.
1896 <dt>src2<dd>The second source array.
1897 <dt>dst<dd>The destination array.
1898 <dt>mask<dd>Operation mask, 8-bit single channel array; specifies elements of
1899 destination array to be changed.
1900 </dl><p>
1901 The function <code>cvAnd</code> calculates per-element bit-wise logical conjunction of two arrays:</p>
1902 <pre>dst(I)=src1(I)&amp;src2(I) if mask(I)!=0</pre>
1903 <p>In the case of floating-point arrays their bit representations are used for the
1904 operation. All the arrays must have the same type, except the mask, and the same size</p>
1905
1906
1907 <hr><h3><a name="decl_cvAndS">AndS</a></h3>
1908 <p class="Blurb">Calculates per-element bit-wise conjunction of array and scalar</p>
1909 <pre>
1910 void cvAndS( const CvArr* src, CvScalar value, CvArr* dst, const CvArr* mask=NULL );
1911 </pre><p><dl>
1912 <dt>src<dd>The source array.
1913 <dt>value<dd>Scalar to use in the operation.
1914 <dt>dst<dd>The destination array.
1915 <dt>mask<dd>Operation mask, 8-bit single channel array; specifies elements of
1916 destination array to be changed.
1917 </dl><p>
1918 The function AndS calculates per-element bit-wise conjunction of array and scalar:</p>
1919 <pre>dst(I)=src(I)&amp;value if mask(I)!=0</pre>
1920 <p>Prior to the actual operation the scalar is converted to the same type as
1921 the arrays. In the case of floating-point arrays their bit representations are used for the
1922 operation. All the arrays must have the same type, except the mask, and the same size</p>
1923
1924 <p>The following sample demonstrates how to calculate absolute value of floating-point array elements
1925 by clearing the most-significant bit:</p>
1926 <pre>
1927 float a[] = { -1, 2, -3, 4, -5, 6, -7, 8, -9 };
1928 CvMat A = cvMat( 3, 3, CV_32F, &amp;a );
1929 int i, abs_mask = 0x7fffffff;
1930 cvAndS( &amp;A, cvRealScalar(*(float*)&amp;abs_mask), &amp;A, 0 );
1931 for( i = 0; i &lt; 9; i++ )
1932     printf("%.1f ", a[i] );
1933 </pre>
1934 <p>The code should print:</p>
1935 <pre>1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0</pre>
1936
1937
1938 <hr><h3><a name="decl_cvOr">Or</a></h3>
1939 <p class="Blurb">Calculates per-element bit-wise disjunction of two arrays</p>
1940 <pre>
1941 void cvOr( const CvArr* src1, const CvArr* src2, CvArr* dst, const CvArr* mask=NULL );
1942 </pre><p><dl>
1943 <dt>src1<dd>The first source array.
1944 <dt>src2<dd>The second source array.
1945 <dt>dst<dd>The destination array.
1946 <dt>mask<dd>Operation mask, 8-bit single channel array; specifies elements of
1947 destination array to be changed.
1948 </dl><p>
1949 The function <code>cvOr</code> calculates per-element bit-wise disjunction of two arrays:</p>
1950 <pre>dst(I)=src1(I)|src2(I)</pre>
1951 <p>In the case of floating-point arrays their bit representations are used for the
1952 operation. All the arrays must have the same type, except the mask, and the same size</p>
1953
1954
1955 <hr><h3><a name="decl_cvOrS">OrS</a></h3>
1956 <p class="Blurb">Calculates per-element bit-wise disjunction of array and scalar</p>
1957 <pre>
1958 void cvOrS( const CvArr* src, CvScalar value, CvArr* dst, const CvArr* mask=NULL );
1959 </pre><p><dl>
1960 <dt>src1<dd>The source array.
1961 <dt>value<dd>Scalar to use in the operation.
1962 <dt>dst<dd>The destination array.
1963 <dt>mask<dd>Operation mask, 8-bit single channel array; specifies elements of
1964 destination array to be changed.
1965 </dl><p>
1966 The function OrS calculates per-element bit-wise disjunction of array and scalar:</p>
1967 <pre>dst(I)=src(I)|value if mask(I)!=0</pre>
1968 <p>Prior to the actual operation the scalar is converted to the same type as
1969 the arrays. In the case of floating-point arrays their bit representations are used for the
1970 operation. All the arrays must have the same type, except the mask, and the same size</p>
1971
1972
1973 <hr><h3><a name="decl_cvXor">Xor</a></h3>
1974 <p class="Blurb">Performs per-element bit-wise "exclusive or" operation on two arrays</p>
1975 <pre>
1976 void cvXor( const CvArr* src1, const CvArr* src2, CvArr* dst, const CvArr* mask=NULL );
1977 </pre><p><dl>
1978 <dt>src1<dd>The first source array.
1979 <dt>src2<dd>The second source array.
1980 <dt>dst<dd>The destination array.
1981 <dt>mask<dd>Operation mask, 8-bit single channel array; specifies elements of
1982 destination array to be changed.
1983 </dl><p>
1984 The function <code>cvXor</code> calculates per-element bit-wise logical conjunction of two arrays:</p>
1985 <pre>dst(I)=src1(I)^src2(I) if mask(I)!=0</pre>
1986 <p>In the case of floating-point arrays their bit representations are used for the
1987 operation. All the arrays must have the same type, except the mask, and the same size</p>
1988
1989
1990 <hr><h3><a name="decl_cvXorS">XorS</a></h3>
1991 <p class="Blurb">Performs per-element bit-wise "exclusive or" operation on array and scalar</p>
1992 <pre>
1993 void cvXorS( const CvArr* src, CvScalar value, CvArr* dst, const CvArr* mask=NULL );
1994 </pre><p><dl>
1995 <dt>src<dd>The source array.
1996 <dt>value<dd>Scalar to use in the operation.
1997 <dt>dst<dd>The destination array.
1998 <dt>mask<dd>Operation mask, 8-bit single channel array; specifies elements of
1999 destination array to be changed.
2000 </dl><p>
2001 The function XorS calculates per-element bit-wise conjunction of array and scalar:</p>
2002 <pre>dst(I)=src(I)^value if mask(I)!=0</pre>
2003 <p>Prior to the actual operation the scalar is converted to the same type as
2004 the arrays. In the case of floating-point arrays their bit representations are used for the
2005 operation. All the arrays must have the same type, except the mask, and the same size</p>
2006
2007 <p>The following sample demonstrates how to conjugate complex vector
2008 by switching the most-significant bit of imaging part:</p>
2009 <pre>
2010 float a[] = { 1, 0, 0, 1, -1, 0, 0, -1 }; /* 1, j, -1, -j */
2011 CvMat A = cvMat( 4, 1, CV_32FC2, &amp;a );
2012 int i, neg_mask = 0x80000000;
2013 cvXorS( &amp;A, cvScalar( 0, *(float*)&amp;neg_mask, 0, 0 ), &amp;A, 0 );
2014 for( i = 0; i &lt; 4; i++ )
2015     printf("(%.1f, %.1f) ", a[i*2], a[i*2+1] );
2016 </pre>
2017 <p>The code should print:</p>
2018 <pre>(1.0,0.0) (0.0,-1.0) (-1.0,0.0) (0.0,1.0)</pre>
2019
2020
2021 <hr><h3><a name="decl_cvNot">Not</a></h3>
2022 <p class="Blurb">Performs per-element bit-wise inversion of array elements</p>
2023 <pre>
2024 void cvNot( const CvArr* src, CvArr* dst );
2025 </pre><p><dl>
2026 <dt>src1<dd>The source array.
2027 <dt>dst<dd>The destination array.
2028 </dl><p>
2029 The function Not inverses every bit of every array element:</p>
2030 <pre>dst(I)=~src(I)</pre>
2031
2032
2033 <hr><h3><a name="decl_cvCmp">Cmp</a></h3>
2034 <p class="Blurb">Performs per-element comparison of two arrays</p>
2035 <pre>
2036 void cvCmp( const CvArr* src1, const CvArr* src2, CvArr* dst, int cmp_op );
2037 </pre><p><dl>
2038 <dt>src1<dd>The first source array.
2039 <dt>src2<dd>The second source array. Both source array must have a single channel.
2040 <dt>dst<dd>The destination array, must have 8u or 8s type.
2041 <dt>cmp_op<dd>The flag specifying the relation between the elements to be checked:<br>
2042               CV_CMP_EQ - src1(I) "equal to" src2(I)<br>
2043               CV_CMP_GT - src1(I) "greater than" src2(I)<br>
2044               CV_CMP_GE - src1(I) "greater or equal" src2(I)<br>
2045               CV_CMP_LT - src1(I) "less than" src2(I)<br>
2046               CV_CMP_LE - src1(I) "less or equal" src2(I)<br>
2047               CV_CMP_NE - src1(I) "not equal to" src2(I)<br>
2048 </dl><p>
2049 The function <code>cvCmp</code> compares the corresponding elements of two arrays and
2050 fills the destination mask array:</p>
2051 <pre>
2052 dst(I)=src1(I) op src2(I),
2053 </pre>
2054 <p>where <code>op</code> is '=', '&gt;', '&gt;=', '&lt;', '&lt;=' or '!='.</p>
2055 <p><code>dst(I)</code> is set to 0xff (all '1'-bits) if the particular relation between the elements
2056 is true and 0 otherwise.
2057 All the arrays must have the same type, except the destination, and the same size (or ROI size)</p>
2058
2059
2060 <hr><h3><a name="decl_cvCmpS">CmpS</a></h3>
2061 <p class="Blurb">Performs per-element comparison of array and scalar</p>
2062 <pre>
2063 void cvCmpS( const CvArr* src, double value, CvArr* dst, int cmp_op );
2064 </pre><p><dl>
2065 <dt>src<dd>The source array, must have a single channel.
2066 <dt>value<dd>The scalar value to compare each array element with.
2067 <dt>dst<dd>The destination array, must have 8u or 8s type.
2068 <dt>cmp_op<dd>The flag specifying the relation between the elements to be checked:<br>
2069               CV_CMP_EQ - src1(I) "equal to" value<br>
2070               CV_CMP_GT - src1(I) "greater than" value<br>
2071               CV_CMP_GE - src1(I) "greater or equal" value<br>
2072               CV_CMP_LT - src1(I) "less than" value<br>
2073               CV_CMP_LE - src1(I) "less or equal" value<br>
2074               CV_CMP_NE - src1(I) "not equal" value<br>
2075 </dl><p>
2076 The function <code>cvCmpS</code> compares the corresponding elements of array and scalar
2077 and fills the destination mask array:</p>
2078 <pre>
2079 dst(I)=src(I) op scalar,
2080 </pre>
2081 <p>where <code>op</code> is '=', '&gt;', '&gt;=', '&lt;', '&lt;=' or '!='.</p>
2082 <p><code>dst(I)</code> is set to 0xff (all '1'-bits) if the particular relation between the elements
2083 is true and 0 otherwise.
2084 All the arrays must have the same size (or ROI size)</p>
2085
2086
2087
2088 <hr><h3><a name="decl_cvInRange">InRange</a></h3>
2089 <p class="Blurb">Checks that array elements lie between elements of two other arrays</p>
2090 <pre>
2091 void cvInRange( const CvArr* src, const CvArr* lower, const CvArr* upper, CvArr* dst );
2092 </pre><p><dl>
2093 <dt>src<dd>The first source array.
2094 <dt>lower<dd>The inclusive lower boundary array.
2095 <dt>upper<dd>The exclusive upper boundary array.
2096 <dt>dst<dd>The destination array, must have 8u or 8s type.
2097 </dl><p>
2098 The function <code>cvInRange</code> does the range check for every element of the input array:</p>
2099 <pre>
2100 dst(I)=lower(I)<sub>0</sub> &lt;= src(I)<sub>0</sub> &lt; upper(I)<sub>0</sub>
2101 </pre>
2102 <p>for single-channel arrays,</p>
2103 <pre>
2104 dst(I)=lower(I)<sub>0</sub> &lt;= src(I)<sub>0</sub> &lt; upper(I)<sub>0</sub> &amp;&amp;
2105      lower(I)<sub>1</sub> &lt;= src(I)<sub>1</sub> &lt; upper(I)<sub>1</sub>
2106 </pre><p>for two-channel arrays etc.</p>
2107 <p><code>dst(I)</code> is set to 0xff (all '1'-bits) if <code>src(I)</code> is within the range and 0 otherwise.
2108 All the arrays must have the same type, except the destination, and the same size (or ROI size)</p>
2109
2110
2111 <hr><h3><a name="decl_cvInRangeS">InRangeS</a></h3>
2112 <p class="Blurb">Checks that array elements lie between two scalars</p>
2113 <pre>
2114 void cvInRangeS( const CvArr* src, CvScalar lower, CvScalar upper, CvArr* dst );
2115 </pre><p><dl>
2116 <dt>src<dd>The first source array.
2117 <dt>lower<dd>The inclusive lower boundary.
2118 <dt>upper<dd>The exclusive upper boundary.
2119 <dt>dst<dd>The destination array, must have 8u or 8s type.
2120 </dl><p>
2121 The function <code>cvInRangeS</code> does the range check for every element of the input array:</p>
2122 <pre>
2123 dst(I)=lower<sub>0</sub> &lt;= src(I)<sub>0</sub> &lt; upper<sub>0</sub>
2124 </pre>
2125 <p>for a single-channel array,</p>
2126 <pre>
2127 dst(I)=lower<sub>0</sub> &lt;= src(I)<sub>0</sub> &lt; upper<sub>0</sub> &amp;&amp;
2128      lower<sub>1</sub> &lt;= src(I)<sub>1</sub> &lt; upper<sub>1</sub>
2129 </pre><p>for a two-channel array etc.</p>
2130 <p>
2131 <p><code>dst(I)</code> is set to 0xff (all '1'-bits) if <code>src(I)</code> is within the range and 0 otherwise.
2132 All the arrays must have the same size (or ROI size)</p>
2133
2134
2135 <hr><h3><a name="decl_cvMax">Max</a></h3>
2136 <p class="Blurb">Finds per-element maximum of two arrays</p>
2137 <pre>
2138 void cvMax( const CvArr* src1, const CvArr* src2, CvArr* dst );
2139 </pre><p><dl>
2140 <dt>src1<dd>The first source array.
2141 <dt>src2<dd>The second source array.
2142 <dt>dst<dd>The destination array.
2143 </dl><p>
2144 The function <code>cvMax</code> calculates per-element maximum of two arrays:</p>
2145 <pre>dst(I)=max(src1(I), src2(I))</pre>
2146 <p>All the arrays must have a single channel, the same data type
2147 and the same size (or ROI size).</p>
2148
2149
2150 <hr><h3><a name="decl_cvMaxS">MaxS</a></h3>
2151 <p class="Blurb">Finds per-element maximum of array and scalar</p>
2152 <pre>
2153 void cvMaxS( const CvArr* src, double value, CvArr* dst );
2154 </pre><p><dl>
2155 <dt>src<dd>The first source array.
2156 <dt>value<dd>The scalar value.
2157 <dt>dst<dd>The destination array.
2158 </dl><p>
2159 The function <code>cvMaxS</code> calculates per-element maximum of array and scalar:</p>
2160 <pre>dst(I)=max(src(I), value)</pre>
2161 <p>All the arrays must have a single channel, the same data type
2162 and the same size (or ROI size).</p>
2163
2164
2165 <hr><h3><a name="decl_cvMin">Min</a></h3>
2166 <p class="Blurb">Finds per-element minimum of two arrays</p>
2167 <pre>
2168 void cvMin( const CvArr* src1, const CvArr* src2, CvArr* dst );
2169 </pre><p><dl>
2170 <dt>src1<dd>The first source array.
2171 <dt>src2<dd>The second source array.
2172 <dt>dst<dd>The destination array.
2173 </dl><p>
2174 The function <code>cvMin</code> calculates per-element minimum of two arrays:</p>
2175 <pre>
2176 dst(I)=min(src1(I),src2(I))
2177 </pre>
2178 <p>All the arrays must have a single channel, the same data type
2179 and the same size (or ROI size).</p>
2180
2181
2182
2183 <hr><h3><a name="decl_cvMinS">MinS</a></h3>
2184 <p class="Blurb">Finds per-element minimum of array and scalar</p>
2185 <pre>
2186 void cvMinS( const CvArr* src, double value, CvArr* dst );
2187 </pre><p><dl>
2188 <dt>src<dd>The first source array.
2189 <dt>value<dd>The scalar value.
2190 <dt>dst<dd>The destination array.
2191 </dl><p>
2192 The function <code>cvMinS</code> calculates minimum of array and scalar:</p>
2193 <pre>dst(I)=min(src(I), value)</pre>
2194 <p>All the arrays must have a single channel, the same data type
2195 and the same size (or ROI size).</p>
2196
2197
2198 <hr><h3><a name="decl_cvAbsDiff">AbsDiff</a></h3>
2199 <p class="Blurb">Calculates absolute difference between two arrays</p>
2200 <pre>
2201 void cvAbsDiff( const CvArr* src1, const CvArr* src2, CvArr* dst );
2202 </pre><p><dl>
2203 <dt>src1<dd>The first source array.
2204 <dt>src2<dd>The second source array.
2205 <dt>dst<dd>The destination array.
2206 </dl><p>
2207 The function <code>cvAbsDiff</code> calculates absolute difference between two arrays.</p>
2208 <pre>dst(I)<sub>c</sub> = abs(src1(I)<sub>c</sub> - src2(I)<sub>c</sub>).</pre>
2209 <p>All the arrays must have the same data type and the same size (or ROI size).</p>
2210
2211
2212 <hr><h3><a name="decl_cvAbsDiffS">AbsDiffS</a></h3>
2213 <p class="Blurb">Calculates absolute difference between array and scalar</p>
2214 <pre>
2215 void cvAbsDiffS( const CvArr* src, CvArr* dst, CvScalar value );
2216 #define cvAbs(src, dst) cvAbsDiffS(src, dst, cvScalarAll(0))
2217 </pre><p><dl>
2218 <dt>src<dd>The source array.
2219 <dt>dst<dd>The destination array.
2220 <dt>value<dd>The scalar.
2221 </dl><p>
2222 The function <code>cvAbsDiffS</code> calculates absolute difference between array and scalar.</p>
2223 <pre>dst(I)<sub>c</sub> = abs(src(I)<sub>c</sub> - value<sub>c</sub>).</pre>
2224 <p>All the arrays must have the same data type and the same size (or ROI size).</p>
2225
2226
2227 <hr><h2><a name="cxcore_arrays_stat">Statistics</a></h2>
2228
2229 <hr><h3><a name="decl_cvCountNonZero">CountNonZero</a></h3>
2230 <p class="Blurb">Counts non-zero array elements</p>
2231 <pre>
2232 int cvCountNonZero( const CvArr* arr );
2233 </pre><p><dl>
2234 <dt>arr<dd>The array, must be single-channel array or multi-channel image with COI set.
2235 </dl><p>
2236 The function <code>cvCountNonZero</code> returns the number of non-zero elements in src1:</p>
2237 <pre>
2238 result = sum<sub>I</sub> arr(I)!=0
2239 </pre>
2240 In case of <code>IplImage</code> both ROI and COI are supported.</p>
2241
2242
2243 <hr><h3><a name="decl_cvSum">Sum</a></h3>
2244 <p class="Blurb">Summarizes array elements</p>
2245 <pre>
2246 CvScalar cvSum( const CvArr* arr );
2247 </pre><p><dl>
2248 <dt>arr<dd>The array.
2249 </dl><p>
2250 The function <code>cvSum</code> calculates sum <code>S</code> of array elements, independently for each channel:</p>
2251 <pre>
2252 S<sub>c</sub> = sum<sub>I</sub> arr(I)<sub>c</sub>
2253 </pre>
2254 If the array is <code>IplImage</code> and COI is set, the function processes the selected channel only
2255 and stores the sum to the first scalar component (S<sub>0</sub>).</p>
2256
2257
2258 <hr><h3><a name="decl_cvAvg">Avg</a></h3>
2259 <p class="Blurb">Calculates average (mean) of array elements</p>
2260 <pre>
2261 CvScalar cvAvg( const CvArr* arr, const CvArr* mask=NULL );
2262 </pre><p><dl>
2263 <dt>arr<dd>The array.
2264 <dt>mask<dd>The optional operation mask.
2265 </dl><p>
2266 The function <code>cvAvg</code> calculates the average value <code>M</code> of array elements, independently for each channel:</p>
2267 <pre>
2268 N = sum<sub>I</sub> mask(I)!=0
2269
2270 M<sub>c</sub> = 1/N &bull; sum<sub>I,mask(I)!=0</sub> arr(I)<sub>c</sub>
2271 </pre>
2272 If the array is <code>IplImage</code> and COI is set, the function processes the selected channel only
2273 and stores the average to the first scalar component (S<sub>0</sub>).</p>
2274
2275
2276 <hr><h3><a name="decl_cvAvgSdv">AvgSdv</a></h3>
2277 <p class="Blurb">Calculates average (mean) of array elements</p>
2278 <pre>
2279 void cvAvgSdv( const CvArr* arr, CvScalar* mean, CvScalar* std_dev, const CvArr* mask=NULL );
2280 </pre><p><dl>
2281 <dt>arr<dd>The array.
2282 <dt>mean<dd>Pointer to the mean value, may be NULL if it is not needed.
2283 <dt>std_dev<dd>Pointer to the standard deviation.
2284 <dt>mask<dd>The optional operation mask.
2285 </dl><p>
2286 The function <code>cvAvgSdv</code> calculates the average value and
2287 standard deviation of array elements, independently for each channel:</p>
2288 <pre>
2289 N = sum<sub>I</sub> mask(I)!=0
2290
2291 mean<sub>c</sub> = 1/N &bull; sum<sub>I,mask(I)!=0</sub> arr(I)<sub>c</sub>
2292
2293 std_dev<sub>c</sub> = sqrt(1/N &bull; sum<sub>I,mask(I)!=0</sub> (arr(I)<sub>c</sub> - M<sub>c</sub>)<sup>2</sup>)
2294 </pre>
2295 If the array is <code>IplImage</code> and COI is set, the function processes the selected channel only
2296 and stores the average and standard deviation to the first components of output scalars (M<sub>0</sub>
2297 and S<sub>0</sub>).</p>
2298
2299
2300
2301 <hr><h3><a name="decl_cvMinMaxLoc">MinMaxLoc</a></h3>
2302 <p class="Blurb">Finds global minimum and maximum in array or subarray</p>
2303 <pre>
2304 void cvMinMaxLoc( const CvArr* arr, double* min_val, double* max_val,
2305                   CvPoint* min_loc=NULL, CvPoint* max_loc=NULL, const CvArr* mask=NULL );
2306 </pre><p><dl>
2307 <dt>arr<dd>The source array, single-channel or multi-channel with COI set.
2308 <dt>min_val<dd>Pointer to returned minimum value.
2309 <dt>max_val<dd>Pointer to returned maximum value.
2310 <dt>min_loc<dd>Pointer to returned minimum location.
2311 <dt>max_loc<dd>Pointer to returned maximum location.
2312 <dt>mask<dd>The optional mask that is used to select a subarray.
2313 </dl><p>
2314 The function <code>MinMaxLoc</code> finds minimum and maximum element values and their
2315 positions. The extremums are searched over the whole array, selected <code>ROI</code> (in case
2316 of <code>IplImage</code>) or, if <code>mask</code> is not <code>NULL</code>, in the specified array region.
2317 If the array has more than one channel, it must be <code>IplImage</code> with <code>COI</code> set.
2318 In case if multi-dimensional arrays <code>min_loc->x</code> and <code>max_loc->x</code> will contain raw (linear)
2319 positions of the extremums.</p>
2320
2321
2322 <hr><h3><a name="decl_cvNorm">Norm</a></h3>
2323 <p class="Blurb">Calculates absolute array norm, absolute difference norm or relative difference norm</p>
2324 <pre>
2325 double cvNorm( const CvArr* arr1, const CvArr* arr2=NULL, int norm_type=CV_L2, const CvArr* mask=NULL );
2326 </pre><p><dl>
2327 <dt>arr1<dd>The first source image.
2328 <dt>arr2<dd>The second source image. If it is NULL, the absolute norm of <code>arr1</code> is calculated, otherwise
2329          absolute or relative norm of <code>arr1</code>-<code>arr2</code> is calculated.
2330 <dt>normType<dd>Type of norm, see the discussion.
2331 <dt>mask<dd>The optional operation mask.
2332 </dl><p>
2333 The function <code>cvNorm</code> calculates the absolute norm of <code>arr1</code> if <code>arr2</code> is NULL:</p>
2334 <pre>
2335 norm = ||arr1||<sub>C</sub> = max<sub>I</sub> abs(arr1(I)),  if <code>normType</code> = CV_C
2336
2337 norm = ||arr1||<sub>L1</sub> = sum<sub>I</sub> abs(arr1(I)),  if <code>normType</code> = CV_L1
2338
2339 norm = ||arr1||<sub>L2</sub> = sqrt( sum<sub>I</sub> arr1(I)<sup>2</sup>),  if <code>normType</code> = CV_L2
2340
2341 </pre>
2342 <p>And the function calculates absolute or relative difference norm if <code>arr2</code> is not NULL:</p>
2343 <pre>
2344 norm = ||arr1-arr2||<sub>C</sub> = max<sub>I</sub> abs(arr1(I)-arr2(I)),  if <code>normType</code> = CV_C
2345
2346 norm = ||arr1-arr2||<sub>L1</sub> = sum<sub>I</sub> abs(arr1(I)-arr2(I)),  if <code>normType</code> = CV_L1
2347
2348 norm = ||arr1-arr2||<sub>L2</sub> = sqrt( sum<sub>I</sub> (arr1(I)-arr2(I))<sup>2</sup> ),  if <code>normType</code> = CV_L2
2349
2350 or
2351
2352 norm = ||arr1-arr2||<sub>C</sub>/||arr2||<sub>C</sub>, if <code>normType</code> = CV_RELATIVE_C
2353
2354 norm = ||arr1-arr2||<sub>L1</sub>/||arr2||<sub>L1</sub>, if <code>normType</code> = CV_RELATIVE_L1
2355
2356 norm = ||arr1-arr2||<sub>L2</sub>/||arr2||<sub>L2</sub>, if <code>normType</code> = CV_RELATIVE_L2
2357
2358 </pre>
2359 <p>
2360 The function<code> Norm</code> returns the calculated norm.
2361 The multiple-channel array are treated as single-channel, that is, the results for all channels
2362 are combined.
2363 </p>
2364
2365
2366 <hr><h3><a name="decl_cvReduce">Reduce</a></h3>
2367 <p class="Blurb">Reduces matrix to a vector</p>
2368 <pre>
2369 void cvReduce( const CvArr* src, CvArr* dst, int op=CV_REDUCE_SUM );
2370 </pre><p><dl>
2371 <dt>src<dd>The input matrix.
2372 <dt>dst<dd>The output single-row/single-column vector that accumulates
2373            somehow all the matrix rows/columns.
2374 <dt>dim<dd>The dimension index along which the matrix is reduce.
2375            0 means that the matrix is reduced to a single row,
2376            1 means that the matrix is reduced to a single column.
2377            -1 means that the dimension is chosen automatically by analysing the <code>dst</code> size.
2378 <dt>op<dd>The reduction operation. It can take of the following values:<br>
2379            <code>CV_REDUCE_SUM</code> - the output is the sum of all the matrix rows/columns.<br>
2380            <code>CV_REDUCE_AVG</code> - the output is the mean vector of all the matrix rows/columns.<br>
2381            <code>CV_REDUCE_MAX</code> - the output is the maximum (column/row-wise) of all the matrix rows/columns.<br>
2382            <code>CV_REDUCE_MIN</code> - the output is the minimum (column/row-wise) of all the matrix rows/columns.<br>
2383 </dl><p>
2384 The function <code>cvReduce</code> reduces matrix to a vector by treating the matrix rows/columns as a set
2385 of 1D vectors and performing the specified operation on the vectors until a single row/column is obtained.
2386 For example, the function can be used to compute horizontal and vertical projections of an raster image.
2387 In case of <code>CV_REDUCE_SUM</code> and <code>CV_REDUCE_AVG</code> the output may have a larger
2388 element bit-depth to preserve accuracy. And multi-channel arrays are also supported in these two reduction modes.
2389 </p>
2390
2391
2392 <!-- *****************************************************************************************
2393      *****************************************************************************************
2394      ***************************************************************************************** -->
2395
2396 <hr><h2><a name="cxcore_arrays_matrix">Linear Algebra</a></h2>
2397
2398 <hr><h3><a name="decl_cvDotProduct">DotProduct</a></h3>
2399 <p class="Blurb">Calculates dot product of two arrays in Euclidean metrics</p>
2400 <pre>
2401 double cvDotProduct( const CvArr* src1, const CvArr* src2 );
2402 </pre><p><dl>
2403 <dt>src1<dd>The first source array.
2404 <dt>src2<dd>The second source array.
2405 </dl><p>
2406 The function <code>cvDotProduct</code> calculates and returns the Euclidean dot product of two
2407 arrays.</p>
2408 <pre>src1&bull;src2 = sum<sub>I</sub>(src1(I)*src2(I))
2409 </pre>
2410 <p>In case of multiple channel arrays the results for all channels are
2411 accumulated. In particular, <code><a href="#decl_cvDotProduct">cvDotProduct</a>(a,a)</code>,
2412 where <code>a</code> is a complex vector, will return <code>||a||<sup>2</sup></code>.
2413 The function can process multi-dimensional arrays, row by row, layer by layer and so on.</p>
2414
2415
2416 <hr><h3><a name="decl_cvNormalize">Normalize</a></h3>
2417 <p class="Blurb">Normalizes array to a certain norm or value range</p>
2418 <pre>
2419 void cvNormalize( const CvArr* src, CvArr* dst,
2420                   double a=1, double b=0, int norm_type=CV_L2,
2421                   const CvArr* mask=NULL );
2422 </pre><p><dl>
2423 <dt>src<dd>The input array.
2424 <dt>dst<dd>The output array; in-place operation is supported.
2425 <dt>a<dd>The minimum/maximum value of the output array or the norm of output array.
2426 <dt>b<dd>The maximum/minimum value of the output array.
2427 <dt>norm_type<dd>The normalization type. It can take one of the following values:<br>
2428     <code>CV_C</code> - the C-norm (maximum of absolute values) of the array is normalized.<br>
2429     <code>CV_L1</code> - the L<sub>1</sub>-norm (sum of absolute values) of the array is normalized.<br>
2430     <code>CV_L2</code> - the (Euclidean) L<sub>2</sub>-norm of the array is normalized.<br>
2431     <code>CV_MINMAX</code> - the array values are scaled and shifted to the specified range.<br>
2432 <dt>mask<dd>The operation mask. Makes the function consider and normalize only certain array elements.
2433 </dl><p>
2434 The function <code>cvNormalize</code> normalizes the input array so that it's norm or value
2435 range takes the certain value(s).</p>
2436 <p>When <code>norm_type==CV_MINMAX</code>:
2437 <pre>
2438     dst(i,j)=(src(i,j)-min(src))*(b'-a')/(max(src)-min(src)) + a',  if mask(i,j)!=0
2439     dst(i,j)=src(i,j)  otherwise
2440 </pre>
2441 where <code>b'=MAX(a,b)</code>, <code>a'=MIN(a,b)</code>;<br>
2442 <code>min(src)</code> and <code>max(src)</code> are the global minimum and maximum, respectively,
2443 of the input array, computed over the whole array or the specified subset of it.
2444 <p>When <code>norm_type!=CV_MINMAX</code>:
2445 <pre>
2446     dst(i,j)=src(i,j)*a/<a href="#decl_cvNorm">cvNorm</a>(src,0,norm_type,mask), if mask(i,j)!=0
2447     dst(i,j)=src(i,j)  otherwise
2448 </pre>
2449 <p>Here is the short example:</p>
2450 <pre>
2451 float v[3] = { 1, 2, 3 };
2452 CvMat V = cvMat( 1, 3, CV_32F, v );
2453
2454 // make vector v unit-length;
2455 // equivalent to
2456 //   for(int i=0;i&lt;3;i++) v[i]/=sqrt(v[0]*v[0]+v[1]*v[1]+v[2]*v[2]);
2457 cvNormalize( &V, &V );
2458 </pre>
2459
2460 <hr><h3><a name="decl_cvCrossProduct">CrossProduct</a></h3>
2461 <p class="Blurb">Calculates cross product of two 3D vectors</p>
2462 <pre>
2463 void cvCrossProduct( const CvArr* src1, const CvArr* src2, CvArr* dst );
2464 </pre><p><dl>
2465 <dt>src1<dd>The first source vector.
2466 <dt>src2<dd>The second source vector.
2467 <dt>dst<dd>The destination vector.
2468 </dl><p>
2469 The function <code>cvCrossProduct</code> calculates the cross product of two 3D vectors:</p>
2470 <pre>dst = src1 &times; src2, (dst<sub>1</sub> = src1<sub>2</sub>src2<sub>3</sub> - src1<sub>3</sub>src2<sub>2</sub> , dst<sub>2</sub> = src1<sub>3</sub>src2<sub>1</sub> - src1<sub>1</sub>src2<sub>3</sub> , dst<sub>3</sub> = src1<sub>1</sub>src2<sub>2</sub> - src1<sub>2</sub>src2<sub>1</sub>).</pre>
2471
2472
2473 <hr><h3><a name="decl_cvScaleAdd">ScaleAdd</a></h3>
2474 <p class="Blurb">Calculates sum of scaled array and another array</p>
2475 <pre>
2476 void cvScaleAdd( const CvArr* src1, CvScalar scale, const CvArr* src2, CvArr* dst );
2477 #define cvMulAddS cvScaleAdd
2478 </pre><p><dl>
2479 <dt>src1<dd>The first source array.
2480 <dt>scale<dd>Scale factor for the first array.
2481 <dt>src2<dd>The second source array.
2482 <dt>dst<dd>The destination array
2483 </dl><p>
2484 The function <code>cvScaleAdd</code> calculates sum of scaled array and another array:</p>
2485 <pre>dst(I)=src1(I)*scale + src2(I)</pre>
2486 <p>All array parameters should have the same type and the same size.</p>
2487
2488
2489 <hr><h3><a name="decl_cvGEMM">GEMM</a></h3>
2490 <p class="Blurb">Performs generalized matrix multiplication</p>
2491 <pre>
2492 void  cvGEMM( const CvArr* src1, const CvArr* src2, double alpha,
2493               const CvArr* src3, double beta, CvArr* dst, int tABC=0 );
2494 #define cvMatMulAdd( src1, src2, src3, dst ) cvGEMM( src1, src2, 1, src3, 1, dst, 0 )
2495 #define cvMatMul( src1, src2, dst ) cvMatMulAdd( src1, src2, 0, dst )
2496 </pre><p><dl>
2497 <dt>src1<dd>The first source array.
2498 <dt>src2<dd>The second source array.
2499 <dt>src3<dd>The third source array (shift). Can be NULL, if there is no shift.
2500 <dt>dst<dd>The destination array.
2501 <dt>tABC<dd>The operation flags that can be 0 or combination of the following values:<br>
2502             CV_GEMM_A_T - transpose src1<br>
2503             CV_GEMM_B_T - transpose src2<br>
2504             CV_GEMM_C_T - transpose src3<br>
2505             for example, CV_GEMM_A_T+CV_GEMM_C_T corresponds to
2506             <pre>alpha*src1<sup>T</sup>*src2 + beta*src<sup>T</sup></pre>
2507 </dl><p>
2508 The function <code>cvGEMM</code> performs generalized matrix multiplication:</p>
2509 <pre>dst = alpha*op(src1)*op(src2) + beta*op(src3), where op(X) is X or X<sup>T</sup></pre>
2510 <p>
2511 All the matrices should have the same data type and the coordinated sizes.
2512 Real or complex floating-point matrices are supported</p>
2513
2514
2515 <hr><h3><a name="decl_cvTransform">Transform</a></h3>
2516 <p class="Blurb">Performs matrix transform of every array element</p>
2517 <pre>
2518 void cvTransform( const CvArr* src, CvArr* dst, const CvMat* transmat, const CvMat* shiftvec=NULL );
2519 </pre><p><dl>
2520 <dt>src<dd>The first source array.
2521 <dt>dst<dd>The destination array.
2522 <dt>transmat<dd>Transformation matrix.
2523 <dt>shiftvec<dd>Optional shift vector.
2524 </dl><p>
2525 The function <code>cvTransform</code> performs matrix transformation of every element of array <code>src</code>
2526 and stores the results in <code>dst</code>:</p>
2527 <pre>dst(I)=transmat*src(I) + shiftvec   or   dst(I)<sub>k</sub>=sum<sub>j</sub>(transmat(k,j)*src(I)<sub>j</sub>) + shiftvec(k)</pre>
2528 <p>That is every element of <code>N</code>-channel array <code>src</code> is considered as <code>N</code>-element vector, which is
2529 transformed using matrix <code>M</code>&times;<code>N</code> matrix <code>transmat</code> and shift vector <code>shiftvec</code>
2530 into an element of <code>M</code>-channel array <code>dst</code>.
2531 There is an option to embed <code>shiftvec</code> into <code>transmat</code>. In this case <code>transmat</code> should be
2532 <code>M</code>&times;<code>N+1</code> matrix and the right-most column is treated as the shift vector.</p>
2533 <p>
2534 Both source and destination arrays should have the same depth and the same size or selected ROI
2535 size. <code>transmat</code> and <code>shiftvec</code> should be real floating-point matrices.
2536 <p>The function may be used for geometrical transformation of <code>N</code>D point set,
2537 arbitrary linear color space transformation, shuffling the channels etc.
2538 </p>
2539
2540 <hr><h3><a name="decl_cvPerspectiveTransform">PerspectiveTransform</a></h3>
2541 <p class="Blurb">Performs perspective matrix transform of vector array</p>
2542 <pre>
2543 void cvPerspectiveTransform( const CvArr* src, CvArr* dst, const CvMat* mat );
2544 </pre><p><dl>
2545 <dt>src<dd>The source three-channel floating-point array.
2546 <dt>dst<dd>The destination three-channel floating-point array.
2547 <dt>mat<dd>3&times;3 or 4&times;4 transformation matrix.
2548 </dl><p>
2549 The function <code>cvPerspectiveTransform</code> transforms every element of <code>src</code>
2550 (by treating it as 2D or 3D vector) in the following way:</p>
2551 <pre>
2552 (x, y, z) -> (x&#146;/w, y&#146;/w, z&#146;/w) or
2553 (x, y) -> (x&#146;/w, y&#146;/w),
2554
2555 where
2556 (x&#146;, y&#146;, z&#146;, w&#146;) = mat4x4*(x, y, z, 1) or
2557 (x&#146;, y&#146;, w&#146;) = mat3x3*(x, y, 1)
2558
2559 and w = w&#146;   if w&#146;!=0,
2560         inf  otherwise
2561 </pre>
2562
2563
2564 <hr><h3><a name="decl_cvMulTransposed">MulTransposed</a></h3>
2565 <p class="Blurb">Calculates product of array and transposed array</p>
2566 <pre>
2567 void cvMulTransposed( const CvArr* src, CvArr* dst, int order, const CvArr* delta=NULL );
2568 </pre><p><dl>
2569 <dt>src<dd>The source matrix.
2570 <dt>dst<dd>The destination matrix.
2571 <dt>order<dd>Order of multipliers.
2572 <dt>delta<dd>An optional array, subtracted from <code>src</code> before multiplication.
2573 </dl><p>
2574 The function <code>cvMulTransposed</code> calculates the product of src and its transposition.</p>
2575 <p>The function evaluates</p>
2576 <pre>dst=(src-delta)*(src-delta)<sup>T</sup></pre>
2577 <p>if order=0, and
2578 <pre>dst=(src-delta)<sup>T</sup>*(src-delta)</pre>
2579 <p>otherwise.</p>
2580
2581
2582 <hr><h3><a name="decl_cvTrace">Trace</a></h3>
2583 <p class="Blurb">Returns trace of matrix</p>
2584 <pre>
2585 CvScalar cvTrace( const CvArr* mat );
2586 </pre><p><dl>
2587 <dt>mat<dd>The source matrix.
2588 </dl><p>
2589 The function <code>cvTrace</code> returns sum of diagonal elements of the matrix <code>src1</code>.
2590 <pre>
2591 tr(src1)=sum<sub>i</sub>mat(i,i)
2592 </pre>
2593
2594
2595 <hr><h3><a name="decl_cvTranspose">Transpose</a></h3>
2596 <p class="Blurb">Transposes matrix</p>
2597 <pre>
2598 void cvTranspose( const CvArr* src, CvArr* dst );
2599 #define cvT cvTranspose
2600 </pre><p><dl>
2601 <dt>src<dd>The source matrix.
2602 <dt>dst<dd>The destination matrix.
2603 </dl><p>
2604 The function <code>cvTranspose</code> transposes matrix <code>src1</code>:</p>
2605 <pre>
2606 dst(i,j)=src(j,i)
2607 </pre>
2608 <p>Note that no complex conjugation is done in case of complex matrix. Conjugation
2609 should be done separately: look at the sample code in <a href="#decl_cvXorS">cvXorS</a> for example</p>
2610
2611
2612 <hr><h3><a name="decl_cvDet">Det</a></h3>
2613 <p class="Blurb">Returns determinant of matrix</p>
2614 <pre>
2615 double cvDet( const CvArr* mat );
2616 </pre><p><dl>
2617 <dt>mat<dd>The source matrix.
2618 </dl><p>
2619 The function <code>cvDet</code> returns determinant of the square matrix <code>mat</code>.
2620 The direct method is used for small matrices and Gaussian elimination is used for larger matrices.
2621 For symmetric positive-determined matrices it is also possible to run <a href="#decl_cvSVD">SVD</a>
2622 with <code>U=V=NULL</code> and then calculate determinant as a product of the diagonal elements of <code>W</code></p>
2623
2624
2625 <hr><h3><a name="decl_cvInvert">Invert</a></h3>
2626 <p class="Blurb">Finds inverse or pseudo-inverse of matrix</p>
2627 <pre>
2628 double cvInvert( const CvArr* src, CvArr* dst, int method=CV_LU );
2629 #define cvInv cvInvert
2630 </pre><p><dl>
2631 <dt>src<dd>The source matrix.
2632 <dt>dst<dd>The destination matrix.
2633 <dt>method<dd>Inversion method:<br>
2634               CV_LU - Gaussian elimination with optimal pivot element chose<br>
2635               CV_SVD - Singular value decomposition (SVD) method<br>
2636               CV_SVD_SYM - SVD method for a symmetric positively-defined matrix<br>
2637 </dl><p>
2638 The function <code>cvInvert</code> inverts matrix <code>src1</code> and stores the result in <code>src2</code></p>
2639 <p>In case of <code>LU</code> method the function returns <code>src1</code> determinant (src1 must be square).
2640 If it is 0, the matrix is not inverted and <code>src2</code> is filled with zeros.</p>
2641 <p>In case of <code>SVD</code> methods the function returns the inverted condition number of <code>src1</code>
2642 (ratio of the smallest singular value to the largest singular value) and 0 if <code>src1</code> is all zeros.
2643 The SVD methods calculate a pseudo-inverse matrix if <code>src1</code> is singular</p>
2644
2645
2646 <hr><h3><a name="decl_cvSolve">Solve</a></h3>
2647 <p class="Blurb">Solves linear system or least-squares problem</p>
2648 <pre>
2649 int cvSolve( const CvArr* A, const CvArr* B, CvArr* X, int method=CV_LU );
2650 </pre><p><dl>
2651 <dt>A<dd>The source matrix.
2652 <dt>B<dd>The right-hand part of the linear system.
2653 <dt>X<dd>The output solution.
2654 <dt>method<dd>The solution (matrix inversion) method:<br>
2655               CV_LU - Gaussian elimination with optimal pivot element chose<br>
2656               CV_SVD - Singular value decomposition (SVD) method<br>
2657               CV_SVD_SYM - SVD method for a symmetric positively-defined matrix.
2658 </dl><p>
2659 The function <code>cvSolve</code> solves linear system or least-squares problem (the latter
2660 is possible with SVD methods):</p>
2661 <pre>
2662 dst = arg min<sub>X</sub>||A*X-B||
2663 </pre>
2664 <p>If <code>CV_LU</code> method is used, the function returns 1 if <code>src1</code> is non-singular and
2665 0 otherwise, in the latter case <code>dst</code> is not valid</p>
2666
2667
2668 <hr><h3><a name="decl_cvSVD">SVD</a></h3>
2669 <p class="Blurb">Performs singular value decomposition of real floating-point matrix</p>
2670 <pre>
2671 void cvSVD( CvArr* A, CvArr* W, CvArr* U=NULL, CvArr* V=NULL, int flags=0 );
2672 </pre><p><dl>
2673
2674 <dt>A<dd>Source <code>M</code>&times;<code>N</code> matrix.
2675 <dt>W<dd>Resulting singular value matrix (<code>M</code>&times;<code>N</code> or <code>N</code>&times;<code>N</code>) or
2676          vector (<code>N</code>&times;<code>1</code>).
2677 <dt>U<dd>Optional left orthogonal matrix (<code>M</code>&times;<code>M</code> or <code>M</code>&times;<code>N</code>).
2678          If CV_SVD_U_T is specified, the number of rows and columns in the sentence above should be swapped.
2679 <dt>V<dd>Optional right orthogonal matrix (<code>N</code>&times;<code>N</code>)
2680 <dt>flags<dd>Operation flags; can be 0 or combination of the following values:
2681 <ul>
2682 <li>  <code>CV_SVD_MODIFY_A</code> enables modification of matrix <code>src1</code> during the operation. It
2683   speeds up the processing.
2684 <li>  <code>CV_SVD_U_T</code> means that the transposed matrix <code>U</code> is returned.
2685       Specifying the flag speeds up the processing.
2686 <li>  <code>CV_SVD_V_T</code> means that the transposed matrix <code>V</code> is returned.
2687       Specifying the flag speeds up the processing.
2688 </ul>
2689 </dl><p>
2690 The function <code>cvSVD</code> decomposes matrix <code>A</code> into a product of a diagonal matrix and two
2691 orthogonal matrices:</p>
2692 <pre>
2693 A=U*W*V<sup>T</sup>
2694 </pre>
2695 <p>Where <code>W</code> is diagonal matrix of singular values that can be coded as a 1D
2696 vector of singular values and <code>U</code> and <code>V</code>. All the singular values are non-negative and sorted (together with <code>U</code> and
2697 and <code>V</code> columns) in descending order.</p>
2698 <p>SVD algorithm is numerically robust and its typical applications include:
2699 <ul>
2700 <li>accurate eigenvalue problem solution when matrix <code>A</code> is square, symmetric and positively
2701   defined matrix, for example, when it is a covariation matrix.
2702   <code>W</code> in this case will be a vector of eigenvalues, and <code>U</code>=<code>V</code> is matrix of
2703   eigenvectors (thus, only one of <code>U</code> or <code>V</code> needs to be calculated if
2704   the eigenvectors are required)</li>
2705 <li>accurate solution of poor-conditioned linear systems</li>
2706 <li>least-squares solution of overdetermined linear systems. This and previous is done by <a href="#decl_cvSolve">cvSolve</a>
2707     function with <code>CV_SVD</code> method</li>
2708 <li>accurate calculation of different matrix characteristics such as rank
2709    (number of non-zero singular values),
2710   condition number (ratio of the largest singular value to the smallest one),
2711   determinant (absolute value of determinant is equal to the product of singular values).
2712   All the things listed in this item do not require calculation of <code>U</code>
2713   and <code>V</code> matrices.</li>
2714 </ul></p>
2715
2716
2717
2718 <hr><h3><a name="decl_cvSVBkSb">SVBkSb</a></h3>
2719 <p class="Blurb">Performs singular value back substitution</p>
2720 <pre>
2721 void  cvSVBkSb( const CvArr* W, const CvArr* U, const CvArr* V,
2722                 const CvArr* B, CvArr* X, int flags );
2723 </pre><p><dl>
2724
2725 <dt>W<dd>Matrix or vector of singular values.
2726 <dt>U<dd>Left orthogonal matrix (transposed, perhaps)
2727 <dt>V<dd>Right orthogonal matrix (transposed, perhaps)
2728 <dt>B<dd>The matrix to multiply the pseudo-inverse of the original matrix <code>A</code> by.
2729          This is the optional parameter. If it is omitted then it is assumed to be
2730          an identity matrix of an appropriate size (So <code>X</code> will be the reconstructed
2731          pseudo-inverse of <code>A</code>).
2732 <dt>X<dd>The destination matrix: result of back substitution.
2733 <dt>flags<dd>Operation flags, should match exactly to the <code>flags</code> passed to <a href="#decl_cvSVD">cvSVD</a>.
2734 </dl><p>
2735 The function <code>cvSVBkSb</code> calculates back substitution for decomposed matrix <code>A</code> (see
2736 <a href="#decl_cvSVD">cvSVD</a> description) and matrix <code>B</code>:</p>
2737 <pre>
2738 X=V*W<sup>-1</sup>*U<sup>T</sup>*B
2739 </pre>
2740 <p>Where</p>
2741 <pre>
2742 W<sup>-1</sup>(i,i)=1/W(i,i) if W(i,i) > epsilon&bull;sum<sub>i</sub>W(i,i),
2743                     0        otherwise
2744 </pre>
2745 <p>And <code>epsilon</code> is a small number that depends on the matrix data type.
2746 </p>
2747 This function together with <a href="#decl_cvSVD">cvSVD</a> is used inside <a href="#decl_cvInvert">cvInvert</a> and <a href="#decl_cvSolve">cvSolve</a>,
2748 and the possible reason to use these (svd &amp; bksb) "low-level" function is to avoid
2749 temporary matrices allocation inside the high-level counterparts (inv &amp; solve).</p>
2750
2751
2752 <hr><h3><a name="decl_cvEigenVV">EigenVV</a></h3>
2753 <p class="Blurb">Computes eigenvalues and eigenvectors of symmetric matrix</p>
2754 <pre>
2755 void cvEigenVV( CvArr* mat, CvArr* evects, CvArr* evals, double eps=0 );
2756 </pre><p><dl>
2757 <dt>mat<dd>The input symmetric square matrix. It is modified during the processing.
2758 <dt>evects<dd>The output matrix of eigenvectors, stored as a subsequent rows.
2759 <dt>evals<dd>The output vector of eigenvalues, stored in the descending order (order of
2760 eigenvalues and eigenvectors is synchronized, of course).
2761 <dt>eps<dd>Accuracy of diagonalization (typically, DBL_EPSILON=&asymp;10<sup>-15</sup> is enough).
2762 </dl><p>
2763 The function <code>cvEigenVV</code> computes the eigenvalues and eigenvectors of the matrix <code>A</code>:</p>
2764 <pre>mat*evects(i,:)' = evals(i)*evects(i,:)' (in MATLAB notation)</pre>
2765 <p>The contents of matrix <code>A</code> is destroyed by the function.</p>
2766 <p>Currently the function is slower than <a href="#decl_cvSVD">cvSVD</a> yet less accurate,
2767 so if <code>A</code> is known to be positively-defined (for example, it is a covariation matrix),
2768 it is recommended to use <a href="#decl_cvSVD">cvSVD</a> to find eigenvalues and eigenvectors of <code>A</code>,
2769 especially if eigenvectors are not required. That is, instead of
2770 <pre>
2771 cvEigenVV(mat, eigenvals, eigenvects);
2772 </pre>
2773 call
2774 <pre>
2775 cvSVD(mat, eigenvals, eigenvects, 0, CV_SVD_U_T + CV_SVD_MODIFY_A);
2776 </pre>
2777 </p>
2778
2779
2780 <hr><h3><a name="decl_cvCalcCovarMatrix">CalcCovarMatrix</a></h3>
2781 <p class="Blurb">Calculates covariation matrix of the set of vectors</p>
2782 <pre>
2783 void cvCalcCovarMatrix( const CvArr** vects, int count, CvArr* cov_mat, CvArr* avg, int flags );
2784 </pre><p><dl>
2785 <dt>vects<dd>The input vectors. They all must have the same type and the same size.
2786              The vectors do not have to be 1D, they can be 2D (e.g. images) etc.
2787 <dt>count<dd>The number of input vectors.
2788 <dt>cov_mat<dd>The output covariation matrix that should be floating-point and square.
2789 <dt>avg<dd>The input or output (depending on the flags) array - the mean (average) vector of the input vectors.
2790 <dt>flags<dd>The operation flags, a combination of the following values:<br>
2791                  <code>CV_COVAR_SCRAMBLED</code> - the output covariation matrix is calculated as:<br>
2792                        <code>scale*[vects[0]-avg,vects[1]-avg,...]<sup>T</sup>*[vects[0]-avg,vects[1]-avg,...]</code>,<br>
2793                        that is, the covariation matrix is <code>count</code>&times;<code>count</code>. Such an unusual
2794                        covariation matrix is used for fast PCA of a set of very large vectors
2795                        (see, for example, Eigen Faces technique for face recognition). Eigenvalues of this
2796                        "scrambled" matrix will match to the eigenvalues of the true covariation matrix and
2797                        the "true" eigenvectors can be easily calculated from the eigenvectors of the "scrambled" covariation
2798                        matrix.<br>
2799                  <code>CV_COVAR_NORMAL</code> - the output covariation matrix is calculated as:<br>
2800                        <code>scale*[vects[0]-avg,vects[1]-avg,...]*[vects[0]-avg,vects[1]-avg,...]<sup>T</sup></code>,<br>
2801                        that is, <code>cov_mat</code> will be a usual covariation matrix with the same linear size as the total number of
2802                        elements in every input vector. One and only one of <code>CV_COVAR_SCRAMBLED</code> and <code>CV_COVAR_NORMAL</code> must be specified<br>
2803                  <code>CV_COVAR_USE_AVG</code> - if the flag is specified, the function does not calculate <code>avg</code> from
2804                        the input vectors, but, instead, uses the passed <code>avg</code> vector. This is useful if <code>avg</code>
2805                        has been already calculated somehow, or if the covariation matrix is calculated by parts - in this case,
2806                        <code>avg</code> is not a mean vector of the input sub-set of vectors, but rather the mean vector of
2807                        the whole set.<br>
2808                  <code>CV_COVAR_SCALE</code> - if the flag is specified, the covariation matrix is scaled by
2809                        the number of input vectors.
2810                  <code>CV_COVAR_ROWS</code> - Means that all the input vectors are stored as rows of a single matrix, <code>vects[0]</code>.
2811                        <code>count</code> is ignored in this case, and <code>avg</code> should be a single-row vector of an appropriate size.
2812                  <code>CV_COVAR_COLS</code> - Means that all the input vectors are stored as columns of a single matrix, <code>vects[0]</code>.
2813                        <code>count</code> is ignored in this case, and <code>avg</code> should be a single-column vector of an appropriate size.
2814 </dl><p>
2815 The function <code>cvCalcCovarMatrix</code> calculates the covariation matrix and, optionally,
2816 mean vector of the set of input vectors. The function can be used for PCA, for comparing vectors using Mahalanobis distance etc.
2817 </p>
2818
2819
2820 <hr><h3><a name="decl_cvMahalonobis">Mahalonobis</a></h3>
2821 <p class="Blurb">Calculates Mahalonobis distance between two vectors</p>
2822 <pre>
2823 double cvMahalanobis( const CvArr* vec1, const CvArr* vec2, CvArr* mat );
2824 </pre><p><dl>
2825 <dt>vec1<dd>The first 1D source vector.
2826 <dt>vec2<dd>The second 1D source vector.
2827 <dt>mat<dd>The inverse covariation matrix.
2828 </dl><p>
2829 The function <code>cvMahalonobis</code> calculates the weighted distance between two vectors
2830 and returns it:</p>
2831 <pre>
2832 d(vec1,vec2)=sqrt( sum<sub>i,j</sub> {mat(i,j)*(vec1(i)-vec2(i))*(vec1(j)-vec2(j))} )
2833 </pre>
2834 <p>The covariation matrix may be calculated using <a href="#decl_cvCalcCovarMatrix">cvCalcCovarMatrix</a> function and further
2835 inverted using <a href="#decl_cvInvert">cvInvert</a> function (CV_SVD method is the preferred one, because the matrix
2836 might be singular).</p>
2837
2838
2839 <hr><h3><a name="decl_cvCalcPCA">CalcPCA</a></h3>
2840 <p class="Blurb">Performs Principal Component Analysis of a vector set</p>
2841 <pre>
2842 void cvCalcPCA( const CvArr* data, CvArr* avg,
2843                 CvArr* eigenvalues, CvArr* eigenvectors, int flags );
2844 </pre><p><dl>
2845 <dt>data<dd>The input data; each vector is either a single row (<code>CV_PCA_DATA_AS_ROW</code>)
2846             or a single column (<code>CV_PCA_DATA_AS_COL</code>).
2847 <dt>avg<dd>The mean (average) vector, computed inside the function or provided by user.
2848 <dt>eigenvalues<dd>The output eigenvalues of covariation matrix.
2849 <dt>eigenvectors<dd>The output eigenvectors of covariation matrix (i.e. principal components);
2850                     one vector per row.
2851 <dt>flags<dd>The operation flags, a combination of the following values:<br>
2852              <code>CV_PCA_DATA_AS_ROW</code> - the vectors are stored as rows
2853              (i.e. all the components of a certain vector are stored continuously)<br>
2854              <code>CV_PCA_DATA_AS_COL</code> - the vectors are stored as columns
2855              (i.e. values of a certain vector component are stored continuously)<br>
2856              (the above two flags are mutually exclusive)<br>
2857              <code>CV_PCA_USE_AVG</code> - use pre-computed average vector<br>
2858 </dl><p>
2859 The function <code>cvCalcPCA</code> performs PCA analysis of the vector set.
2860 First, it uses <a href="#decl_cvCalcCovarMatrix">cvCalcCovarMatrix</a> to compute covariation matrix
2861 and then it finds its eigenvalues and eigenvectors. The output number of eigenvalues/eigenvectors
2862 should be less than or equal to <code>MIN(rows(data),cols(data))</code>.
2863
2864
2865 <hr><h3><a name="decl_cvProjectPCA">ProjectPCA</a></h3>
2866 <p class="Blurb">Projects vectors to the specified subspace</p>
2867 <pre>
2868 void cvProjectPCA( const CvArr* data, const CvArr* avg,
2869                    const CvArr* eigenvectors, CvArr* result )
2870 </pre><p><dl>
2871 <dt>data<dd>The input data; each vector is either a single row
2872             or a single column.
2873 <dt>avg<dd>The mean (average) vector. If it is a single-row vector,
2874            it means that the input vectors are stored as rows of <code>data</code>;
2875            otherwise, it should be a single-column vector,
2876            then the vectors are stored as columns of <code>data</code>.
2877 <dt>eigenvectors<dd>The eigenvectors (principal components); one vector per row.
2878 <dt>result<dd>The output matrix of decomposition coefficients. The number of rows must be
2879               the same as the number of vectors, the number of columns must
2880               be less than or equal to the number of rows in <code>eigenvectors</code>.
2881               That it is less, the input vectors are projected into subspace
2882               of the first <code>cols(result)</code> principal components.
2883 </dl><p>
2884 The function <code>cvProjectPCA</code> projects input vectors to the subspace represented by the
2885 orthonormal basis (<code>eigenvectors</code>). Before computing the dot products, <code>avg</code>
2886 vector is subtracted from the input vectors:</p>
2887 <pre>
2888 result(i,:)=(data(i,:)-avg)*eigenvectors' // for CV_PCA_DATA_AS_ROW layout.
2889 </pre>
2890
2891
2892 <hr><h3><a name="decl_cvBackProjectPCA">BackProjectPCA</a></h3>
2893 <p class="Blurb">Reconstructs the original vectors from the projection coefficients</p>
2894 <pre>
2895 void cvBackProjectPCA( const CvArr* proj, const CvArr* avg,
2896                        const CvArr* eigenvects, CvArr* result );
2897 </pre><p><dl>
2898 <dt>proj<dd>The input data; in the same format as <code>result</code> in
2899             <a href="#decl_cvProjectPCA">cvProjectPCA</a>.
2900 <dt>avg<dd>The mean (average) vector. If it is a single-row vector,
2901            it means that the output vectors are stored as rows of <code>result</code>;
2902            otherwise, it should be a single-column vector,
2903            then the vectors are stored as columns of <code>result</code>.
2904 <dt>eigenvectors<dd>The eigenvectors (principal components); one vector per row.
2905 <dt>result<dd>The output matrix of reconstructed vectors.
2906 </dl><p>
2907 The function <code>cvBackProjectPCA</code> reconstructs the vectors from the projection coefficients:</p>
2908 <pre>
2909 result(i,:)=proj(i,:)*eigenvectors + avg // for CV_PCA_DATA_AS_ROW layout.
2910 </pre>
2911
2912
2913 <hr><h2><a name="cxcore_arrays_math">Math Functions</a></h2>
2914
2915 <hr><h3><a name="decl_cvRound">Round, Floor, Ceil</a></h3>
2916 <p class="Blurb">Converts floating-point number to integer</p>
2917 <pre>
2918 int cvRound( double value );
2919 int cvFloor( double value );
2920 int cvCeil( double value );
2921 </pre><p><dl>
2922 <dt>value<dd>The input floating-point value
2923 </dl><p>
2924 The functions <code>cvRound, cvFloor</code> and <code>cvCeil</code> convert input floating-point number to
2925 integer using one of the rounding modes. <code>cvRound</code> returns the nearest integer value to
2926 the argument.
2927 <code>cvFloor</code> returns the maximum integer value that is not larger than the argument.
2928 <code>cvCeil</code> returns the minimum integer value that is not smaller than the argument.
2929 On some architectures the functions work <em>much</em> faster than the standard cast operations in C.
2930 If absolute value of the argument is greater than 2<sup>31</sup>, the result is not determined.
2931 Special values (&plusmn;Inf, NaN) are not handled.
2932 </p>
2933
2934
2935 <hr><h3><a name="decl_cvSqrt">Sqrt</a></h3>
2936 <p class="Blurb">Calculates square root</p>
2937 <pre>
2938 float cvSqrt( float value );
2939 </pre><p><dl>
2940 <dt>value<dd>The input floating-point value
2941 </dl><p>
2942 The function <code>cvSqrt</code> calculates square root of the argument.
2943 If the argument is negative, the result is not determined.
2944 </p>
2945
2946
2947 <hr><h3><a name="decl_cvInvSqrt">InvSqrt</a></h3>
2948 <p class="Blurb">Calculates inverse square root</p>
2949 <pre>
2950 float cvInvSqrt( float value );
2951 </pre><p><dl>
2952 <dt>value<dd>The input floating-point value
2953 </dl><p>
2954 The function <code>cvInvSqrt</code> calculates inverse square root of the argument, and
2955 normally it is faster than <code>1./sqrt(value)</code>. If the argument is zero or negative, the result is
2956 not determined. Special values (&plusmn;Inf, NaN) are not handled.
2957 </p>
2958
2959
2960 <hr><h3><a name="decl_cvCbrt">Cbrt</a></h3>
2961 <p class="Blurb">Calculates cubic root</p>
2962 <pre>
2963 float cvCbrt( float value );
2964 </pre><p><dl>
2965 <dt>value<dd>The input floating-point value
2966 </dl><p>
2967 The function <code>cvCbrt</code> calculates cubic root of the argument, and
2968 normally it is faster than <code>pow(value,1./3)</code>. Besides, negative arguments are handled properly.
2969 Special values (&plusmn;Inf, NaN) are not handled.
2970 </p>
2971
2972
2973 <hr><h3><a name="decl_cvFastArctan">FastArctan</a></h3>
2974 <p class="Blurb">Calculates angle of 2D vector</p>
2975 <pre>
2976 float cvFastArctan( float y, float x );
2977 </pre><p><dl>
2978 <dt>x<dd>x-coordinate of 2D vector
2979 <dt>y<dd>y-coordinate of 2D vector
2980 </dl><p>
2981 The function <code>cvFastArctan</code> calculates full-range angle of input 2D vector.
2982 The angle is measured in degrees and varies from 0&deg; to 360&deg;. The accuracy is ~0.1&deg;
2983 </p>
2984
2985
2986 <hr><h3><a name="decl_cvIsNaN">IsNaN</a></h3>
2987 <p class="Blurb">Determines if the argument is Not A Number</p>
2988 <pre>
2989 int cvIsNaN( double value );
2990 </pre><p><dl>
2991 <dt>value<dd>The input floating-point value
2992 </dl><p>
2993 The function <code>cvIsNaN</code> returns 1 if the argument is Not A Number (as defined
2994 by IEEE754 standard), 0 otherwise.
2995 </p>
2996
2997 <hr><h3><a name="decl_cvIsInf">IsInf</a></h3>
2998 <p class="Blurb">Determines if the argument is Infinity</p>
2999 <pre>
3000 int cvIsInf( double value );
3001 </pre><p><dl>
3002 <dt>value<dd>The input floating-point value
3003 </dl><p>
3004 The function <code>cvIsInf</code> returns 1 if the argument is &plusmn;Infinity (as defined
3005 by IEEE754 standard), 0 otherwise.
3006 </p>
3007
3008
3009 <hr><h3><a name="decl_cvCartToPolar">CartToPolar</a></h3>
3010 <p class="Blurb">Calculates magnitude and/or angle of 2d vectors</p>
3011 <pre>
3012 void cvCartToPolar( const CvArr* x, const CvArr* y, CvArr* magnitude,
3013                     CvArr* angle=NULL, int angle_in_degrees=0 );
3014 </pre><p><dl>
3015 <dt>x<dd>The array of x-coordinates
3016 <dt>y<dd>The array of y-coordinates
3017 <dt>magnitude<dd>The destination array of magnitudes, may be set to NULL if it is not needed
3018 <dt>angle<dd>The destination array of angles, may be set to NULL if it is not needed.
3019         The angles are measured in radians (0..2&pi;) or in degrees (0..360&deg;).
3020 <dt>angle_in_degrees<dd>The flag indicating whether the angles are measured in radians,
3021                         which is default mode, or in degrees.
3022 </dl><p>
3023 The function <code>cvCartToPolar</code> calculates either magnitude, angle,
3024 or both of every 2d vector <code>(x(I),y(I))</code>:</p>
3025 <pre>
3026 magnitude(I)=sqrt( x(I)<sup>2</sup>+y(I)<sup>2</sup> ),
3027 angle(I)=atan( y(I)/x(I) )
3028 </pre>
3029 <p>The angles are calculated with &asymp;0.1&deg; accuracy. For (0,0) point the angle
3030 is set to 0.</p>
3031
3032
3033 <hr><h3><a name="decl_cvPolarToCart">PolarToCart</a></h3>
3034 <p class="Blurb">Calculates Cartesian coordinates of 2d vectors represented in polar form</p>
3035 <pre>
3036 void cvPolarToCart( const CvArr* magnitude, const CvArr* angle,
3037                     CvArr* x, CvArr* y, int angle_in_degrees=0 );
3038 </pre><p><dl>
3039 <dt>magnitude<dd>The array of magnitudes. If it is NULL, the magnitudes are assumed all 1&#146;s.
3040 <dt>angle<dd>The array of angles, whether in radians or degrees.
3041 <dt>x<dd>The destination array of x-coordinates, may be set to NULL if it is not needed.
3042 <dt>y<dd>The destination array of y-coordinates, may be set to NULL if it is not needed.
3043 <dt>angle_in_degrees<dd>The flag indicating whether the angles are measured in radians,
3044                         which is default mode, or in degrees.
3045 </dl><p>
3046 The function <code>cvPolarToCart</code> calculates either x-coordinate, y-coordinate
3047 or both of every vector <code>magnitude(I)*exp(angle(I)*j), j=sqrt(-1)</code>:</p>
3048 <pre>
3049 x(I)=magnitude(I)*cos(angle(I)),
3050 y(I)=magnitude(I)*sin(angle(I))
3051 </pre>
3052
3053
3054 <hr><h3><a name="decl_cvPow">Pow</a></h3>
3055 <p class="Blurb">Raises every array element to power</p>
3056 <pre>
3057 void cvPow( const CvArr* src, CvArr* dst, double power );
3058 </pre><p><dl>
3059 <dt>src<dd>The source array.
3060 <dt>dst<dd>The destination array, should be the same type as the source.
3061 <dt>power<dd>The exponent of power.
3062 </dl><p>
3063 The function <code>cvPow</code> raises every element of input array to <code>p</code>:</p>
3064 <pre>
3065 dst(I)=src(I)<sup>p</sup>, if <code>p</code> is integer
3066 dst(I)=abs(src(I))<sup>p</sup>, otherwise
3067 </pre>
3068 <p>That is, for non-integer power exponent the absolute values of input
3069 array elements are used. However, it is possible to get true values
3070 for negative values using some extra operations, as the following sample,
3071 computing cube root of array elements, shows:</p>
3072 <pre>
3073 CvSize size = cvGetSize(src);
3074 CvMat* mask = cvCreateMat( size.height, size.width, CV_8UC1 );
3075 cvCmpS( src, 0, mask, CV_CMP_LT ); /* find negative elements */
3076 cvPow( src, dst, 1./3 );
3077 cvSubRS( dst, cvScalarAll(0), dst, mask ); /* negate the results of negative inputs */
3078 cvReleaseMat( &mask );
3079 </pre>
3080 <p>For some values of <code>power</code>, such as integer values, 0.5 and -0.5,
3081 specialized faster algorithms are used.</p>
3082
3083
3084 <hr><h3><a name="decl_cvExp">Exp</a></h3>
3085 <p class="Blurb">Calculates exponent of every array element</p>
3086 <pre>
3087 void cvExp( const CvArr* src, CvArr* dst );
3088 </pre><p><dl>
3089 <dt>src<dd>The source array.
3090 <dt>dst<dd>The destination array, it should have <code>double</code> type or
3091 the same type as the source.
3092 </dl><p>
3093 The function <code>cvExp</code> calculates exponent of every element of input array:</p>
3094 <pre>
3095 dst(I)=exp(src(I))
3096 </pre>
3097 <p>Maximum relative error is &asymp;7e-6. Currently,
3098 the function converts denormalized values to zeros on output.</p>
3099
3100
3101 <hr><h3><a name="decl_cvLog">Log</a></h3>
3102 <p class="Blurb">Calculates natural logarithm of every array element absolute value</p>
3103 <pre>
3104 void cvLog( const CvArr* src, CvArr* dst );
3105 </pre><p><dl>
3106 <dt>src<dd>The source array.
3107 <dt>dst<dd>The destination array, it should have <code>double</code> type or
3108 the same type as the source.
3109 </dl><p>
3110 The function <code>cvLog</code> calculates natural logarithm
3111 of absolute value of every element of input array:</p>
3112 <pre>
3113 dst(I)=log(abs(src(I))), src(I)!=0
3114 dst(I)=C,  src(I)=0
3115 </pre>
3116 Where <code>C</code> is large negative number (&asymp;-700 in the current implementation)</p>
3117
3118
3119 <hr><h3><a name="decl_cvSolveCubic">SolveCubic</a></h3>
3120 <p class="Blurb">Finds real roots of a cubic equation</p>
3121 <pre>
3122 int cvSolveCubic( const CvMat* coeffs, CvMat* roots );
3123 </pre><p><dl>
3124 <dt>coeffs<dd>The equation coefficients, array of 3 or 4 elements.
3125 <dt>roots<dd>The output array of real roots. Should have 3 elements.
3126 </dl><p>
3127 The function <code>cvSolveCubic</code> finds real roots of a cubic equation:</p>
3128 <pre>
3129 coeffs[0]*x<sup>3</sup> + coeffs[1]*x<sup>2</sup> + coeffs[2]*x + coeffs[3] = 0
3130 (if coeffs is 4-element vector)
3131
3132 or
3133
3134 x<sup>3</sup> + coeffs[0]*x<sup>2</sup> + coeffs[1]*x + coeffs[2] = 0
3135 (if coeffs is 3-element vector)
3136 </pre>
3137
3138 <p>The function returns the number of real roots found. The roots are stored
3139 to <code>root</code> array, which is padded with zeros if there is only one root.</p>
3140
3141 <hr><h2><a name="cxcore_arrays_rng">Random Number Generation</a></h2>
3142
3143 <hr><h3><a name="decl_cvRNG">RNG</a></h3>
3144 <p class="Blurb">Initializes random number generator state</p>
3145 <pre>
3146 CvRNG cvRNG( int64 seed=-1 );
3147 </pre><p><dl>
3148 <dt>seed<dd>64-bit value used to initiate a random sequence.
3149 </dl><p>
3150 The function <code>cvRNG</code> initializes random number generator
3151 and returns the state. Pointer to the state can be then passed to <a href="#decl_cvRandInt">cvRandInt</a>,
3152 <a href="#decl_cvRandReal">cvRandReal</a> and <a href="#decl_cvRandArr">cvRandArr</a> functions.
3153 In the current implementation a multiply-with-carry generator is used.</p>
3154
3155
3156 <hr><h3><a name="decl_cvRandArr">RandArr</a></h3>
3157 <p class="Blurb">Fills array with random numbers and updates the RNG state</p>
3158 <pre>
3159 void cvRandArr( CvRNG* rng, CvArr* arr, int dist_type, CvScalar param1, CvScalar param2 );
3160 </pre><p><dl>
3161 <dt>rng<dd>RNG state initialized by <a href="#decl_cvRNG">cvRNG</a>.
3162 <dt>arr<dd>The destination array.
3163 <dt>dist_type<dd>Distribution type:<br>
3164                      CV_RAND_UNI - uniform distribution<br>
3165                      CV_RAND_NORMAL - normal or Gaussian distribution<br>
3166 <dt>param1<dd>The first parameter of distribution. In case of uniform distribution it is
3167               the inclusive lower boundary of random numbers range. In case of
3168               normal distribution it is the mean value of random numbers.
3169 <dt>param2<dd>The second parameter of distribution. In case of uniform distribution it is
3170               the exclusive upper boundary of random numbers range. In case of
3171               normal distribution it is the standard deviation of random numbers.
3172 </dl><p>
3173 The function <code>cvRandArr</code> fills the destination array with
3174 uniformly or normally distributed random numbers. In the sample below
3175 the function is used to add a few normally distributed
3176 floating-point numbers to random locations within a 2d array</p>
3177 <pre>
3178 /* let noisy_screen be the floating-point 2d array that is to be "crapped" */
3179 CvRNG rng_state = cvRNG(0xffffffff);
3180 int i, pointCount = 1000;
3181 /* allocate the array of coordinates of points */
3182 CvMat* locations = cvCreateMat( pointCount, 1, CV_32SC2 );
3183 /* arr of random point values */
3184 CvMat* values = cvCreateMat( pointCount, 1, CV_32FC1 );
3185 CvSize size = cvGetSize( noisy_screen );
3186
3187 cvRandInit( &rng_state,
3188             0, 1, /* use dummy parameters now and adjust them further */
3189             0xffffffff /* just use a fixed seed here */,
3190             CV_RAND_UNI /* specify uniform type */ );
3191
3192 /* initialize the locations */
3193 cvRandArr( &rng_state, locations, CV_RAND_UNI, cvScalar(0,0,0,0), cvScalar(size.width,size.height,0,0) );
3194
3195 /* modify RNG to make it produce normally distributed values */
3196 rng_state.disttype = CV_RAND_NORMAL;
3197 cvRandSetRange( &rng_state,
3198                 30 /* deviation */,
3199                 100 /* average point brightness */,
3200                 -1 /* initialize all the dimensions */ );
3201 /* generate values */
3202 cvRandArr( &rng_state, values, CV_RAND_NORMAL,
3203            cvRealScalar(100), // average intensity
3204            cvRealScalar(30) // deviation of the intensity
3205            );
3206
3207 /* set the points */
3208 for( i = 0; i &lt; pointCount; i++ )
3209 {
3210     CvPoint pt = *(CvPoint*)cvPtr1D( locations, i, 0 );
3211     float value = *(float*)cvPtr1D( values, i, 0 );
3212     *((float*)cvPtr2D( noisy_screen, pt.y, pt.x, 0 )) += value;
3213 }
3214
3215 /* not to forget to release the temporary arrays */
3216 cvReleaseMat( &locations );
3217 cvReleaseMat( &values );
3218
3219 /* RNG state does not need to be deallocated */
3220 </pre>
3221
3222
3223 <hr><h3><a name="decl_cvRandInt">RandInt</a></h3>
3224 <p class="Blurb">Returns 32-bit unsigned integer and updates RNG</p>
3225 <pre>
3226 unsigned cvRandInt( CvRNG* rng );
3227 </pre><p><dl>
3228 <dt>rng<dd>RNG state initialized by <code>RandInit</code> and, optionally,
3229 customized by <code>RandSetRange</code> (though, the latter function does not
3230 affect on the discussed function outcome).
3231 </dl><p>
3232 The function <code>cvRandInt</code> returns uniformly-distributed random
3233 32-bit unsigned integer and updates RNG state. It is similar to rand() function from C runtime library,
3234 but it always generates 32-bit number whereas rand() returns a number in between 0
3235 and <code>RAND_MAX</code> which is 2**16 or 2**32, depending on the platform.</p><p>
3236 The function is useful for generating scalar random numbers, such as points, patch sizes,
3237 table indices etc, where integer numbers of a certain range can be generated using
3238 modulo operation and floating-point numbers can be generated by scaling to
3239 0..1 of any other specific range. Here is the example from the previous function discussion
3240 rewritten using <a href="#decl_cvRandInt">cvRandInt</a>:</p>
3241 <pre>
3242 /* the input and the task is the same as in the previous sample. */
3243 CvRNG rng_state = cvRNG(0xffffffff);
3244 int i, pointCount = 1000;
3245 /* ... - no arrays are allocated here */
3246 CvSize size = cvGetSize( noisy_screen );
3247 /* make a buffer for normally distributed numbers to reduce call overhead */
3248 #define bufferSize 16
3249 float normalValueBuffer[bufferSize];
3250 CvMat normalValueMat = cvMat( bufferSize, 1, CV_32F, normalValueBuffer );
3251 int valuesLeft = 0;
3252
3253 for( i = 0; i &lt; pointCount; i++ )
3254 {
3255     CvPoint pt;
3256     /* generate random point */
3257     pt.x = cvRandInt( &rng_state ) % size.width;
3258     pt.y = cvRandInt( &rng_state ) % size.height;
3259
3260     if( valuesLeft &lt;= 0 )
3261     {
3262         /* fulfill the buffer with normally distributed numbers if the buffer is empty */
3263         cvRandArr( &rng_state, &normalValueMat, CV_RAND_NORMAL, cvRealScalar(100), cvRealScalar(30) );
3264         valuesLeft = bufferSize;
3265     }
3266     *((float*)cvPtr2D( noisy_screen, pt.y, pt.x, 0 ) = normalValueBuffer[--valuesLeft];
3267 }
3268
3269 /* there is no need to deallocate normalValueMat because we have
3270 both the matrix header and the data on stack. It is a common and efficient
3271 practice of working with small, fixed-size matrices */
3272 </pre>
3273
3274
3275 <hr><h3><a name="decl_cvRandReal">RandReal</a></h3>
3276 <p class="Blurb">Returns floating-point random number and updates RNG</p>
3277 <pre>
3278 double cvRandReal( CvRNG* rng );
3279 </pre><p><dl>
3280 <dt>rng<dd>RNG state initialized by <a href="#decl_cvRNG">cvRNG</a>.
3281 </dl><p>
3282 The function <code>cvRandReal</code> returns uniformly-distributed random
3283 floating-point number from 0..1 range (1 is not included).</p>
3284
3285
3286 <hr><h2><a name="cxcore_arrays_dxt">Discrete Transforms</a></h2>
3287
3288 <hr><h3><a name="decl_cvDFT">DFT</a></h3>
3289 <p class="Blurb">Performs forward or inverse Discrete Fourier transform of 1D or 2D floating-point array</p>
3290 <pre>
3291 #define CV_DXT_FORWARD  0
3292 #define CV_DXT_INVERSE  1
3293 #define CV_DXT_SCALE    2
3294 #define CV_DXT_ROWS     4
3295 #define CV_DXT_INV_SCALE (CV_DXT_SCALE|CV_DXT_INVERSE)
3296 #define CV_DXT_INVERSE_SCALE CV_DXT_INV_SCALE
3297
3298 void cvDFT( const CvArr* src, CvArr* dst, int flags, int nonzero_rows=0 );
3299 </pre><p><dl>
3300 <dt>src<dd>Source array, real or complex.
3301 <dt>dst<dd>Destination array of the same size and same type as the source.
3302 <dt>flags<dd>Transformation flags, a combination of the following values:<br>
3303               <code>CV_DXT_FORWARD</code> - do forward 1D or 2D transform. The result is not scaled.<br>
3304               <code>CV_DXT_INVERSE</code> - do inverse 1D or 2D transform. The result is not scaled.
3305                                <code>CV_DXT_FORWARD</code> and <code>CV_DXT_INVERSE</code> are mutually exclusive,
3306                                of course.<br>
3307               <code>CV_DXT_SCALE</code> - scale the result: divide it by the number of array elements.
3308                                           Usually, it is combined with <code>CV_DXT_INVERSE</code>, and one
3309                                           may use a shortcut <code>CV_DXT_INV_SCALE</code>.<br>
3310               <code>CV_DXT_ROWS</code> - do forward or inverse transform of every individual row of the input
3311                                          matrix. This flag allows user to transform multiple vectors simultaneously and
3312                                          can be used to decrease the overhead (which is sometimes several times
3313                                          larger than the processing itself), to do 3D and higher-dimensional
3314                                          transforms etc.
3315 <dt>nonzero_rows<dd>Number of nonzero rows to in the source array (in case of forward 2d transform),
3316                     or a number of rows of interest in the destination array (in case of inverse 2d transform).
3317                     If the value is negative, zero, or greater than the total number of rows, it is ignored.
3318                     The parameter can be used to speed up 2d convolution/correlation when computing them via DFT.
3319                     See the sample below.
3320 </dl><p>
3321 The function <code>cvDFT</code> performs forward or inverse transform of
3322 1D or 2D floating-point array:
3323 <pre>
3324 Forward Fourier transform of 1D vector of N elements:
3325 y = F<sup>(N)</sup>&bull;x, where F<sup>(N)</sup><sub>jk</sub>=exp(-i&bull;2Pi&bull;j&bull;k/N), i=sqrt(-1)
3326
3327 Inverse Fourier transform of 1D vector of N elements:
3328 x'= (F<sup>(N)</sup>)<sup>-1</sup>&bull;y = conj(F<sup>(N)</sup>)&bull;y
3329 x = (1/N)&bull;x
3330
3331 Forward Fourier transform of 2D vector of M&times;N elements:
3332 Y = F<sup>(M)</sup>&bull;X&bull;F<sup>(N)</sup>
3333
3334 Inverse Fourier transform of 2D vector of M&times;N elements:
3335 X'= conj(F<sup>(M)</sup>)&bull;Y&bull;conj(F<sup>(N)</sup>)
3336 X = (1/(M&bull;N))&bull;X'
3337 </pre>
3338
3339 <p>In case of real (single-channel) data, the packed format, borrowed from IPL, is used to
3340 to represent a result of forward Fourier transform or input for inverse Fourier transform:
3341
3342 <pre>
3343 Re Y<sub>0,0</sub>      Re Y<sub>0,1</sub>    Im Y<sub>0,1</sub>    Re Y<sub>0,2</sub>     Im Y<sub>0,2</sub>  ...  Re Y<sub>0,N/2-1</sub>   Im Y<sub>0,N/2-1</sub>  Re Y<sub>0,N/2</sub>
3344 Re Y<sub>1,0</sub>      Re Y<sub>1,1</sub>    Im Y<sub>1,1</sub>    Re Y<sub>1,2</sub>     Im Y<sub>1,2</sub>  ...  Re Y<sub>1,N/2-1</sub>   Im Y<sub>1,N/2-1</sub>  Re Y<sub>1,N/2</sub>
3345 Im Y<sub>1,0</sub>      Re Y<sub>2,1</sub>    Im Y<sub>2,1</sub>    Re Y<sub>2,2</sub>     Im Y<sub>2,2</sub>  ...  Re Y<sub>2,N/2-1</sub>   Im Y<sub>2,N/2-1</sub>  Im Y<sub>2,N/2</sub>
3346 ............................................................................................
3347 Re Y<sub>M/2-1,0</sub>   Re Y<sub>M-3,1</sub>   Im Y<sub>M-3,1</sub>  Re Y<sub>M-3,2</sub>   Im Y<sub>M-3,2</sub> ...  Re Y<sub>M-3,N/2-1</sub>  Im Y<sub>M-3,N/2-1</sub> Re Y<sub>M-3,N/2</sub>
3348 Im Y<sub>M/2-1,0</sub>   Re Y<sub>M-2,1</sub>   Im Y<sub>M-2,1</sub>  Re Y<sub>M-2,2</sub>   Im Y<sub>M-2,2</sub> ...  Re Y<sub>M-2,N/2-1</sub>  Im Y<sub>M-2,N/2-1</sub> Im Y<sub>M-2,N/2</sub>
3349 Re Y<sub>M/2,0</sub>    Re Y<sub>M-1,1</sub>   Im Y<sub>M-1,1</sub>  Re Y<sub>M-1,2</sub>   Im Y<sub>M-1,2</sub>  ... Re Y<sub>M-1,N/2-1</sub>  Im Y<sub>M-1,N/2-1</sub> Im Y<sub>M-1,N/2</sub>
3350 </pre>
3351
3352 <p>Note: the last column is present if <code>N</code> is even, the last row is present if <code>M</code> is even.</p>
3353 <p>In case of 1D real transform the result looks like the first row of the above matrix</p>
3354
3355 <font color=blue size=4>Computing 2D Convolution using DFT</font></p>
3356 <pre>
3357    CvMat* A = cvCreateMat( M1, N1, CV_32F );
3358    CvMat* B = cvCreateMat( M2, N2, A->type );
3359
3360    // it is also possible to have only abs(M2-M1)+1&times;abs(N2-N1)+1
3361    // part of the full convolution result
3362    CvMat* conv = cvCreateMat( A->rows + B->rows - 1, A->cols + B->cols - 1, A->type );
3363
3364    // initialize A and B
3365    ...
3366
3367    int dft_M = cvGetOptimalDFTSize( A->rows + B->rows - 1 );
3368    int dft_N = cvGetOptimalDFTSize( A->cols + B->cols - 1 );
3369
3370    CvMat* dft_A = cvCreateMat( dft_M, dft_N, A->type );
3371    CvMat* dft_B = cvCreateMat( dft_M, dft_N, B->type );
3372    CvMat tmp;
3373
3374    // copy A to dft_A and pad dft_A with zeros
3375    cvGetSubRect( dft_A, &tmp, cvRect(0,0,A->cols,A->rows));
3376    cvCopy( A, &tmp );
3377    cvGetSubRect( dft_A, &tmp, cvRect(A->cols,0,dft_A->cols - A->cols,A->rows));
3378    cvZero( &tmp );
3379    // no need to pad bottom part of dft_A with zeros because of
3380    // use nonzero_rows parameter in cvDFT() call below
3381
3382    cvDFT( dft_A, dft_A, CV_DXT_FORWARD, A->rows );
3383
3384    // repeat the same with the second array
3385    cvGetSubRect( dft_B, &tmp, cvRect(0,0,B->cols,B->rows));
3386    cvCopy( B, &tmp );
3387    cvGetSubRect( dft_B, &tmp, cvRect(B->cols,0,dft_B->cols - B->cols,B->rows));
3388    cvZero( &tmp );
3389    // no need to pad bottom part of dft_B with zeros because of
3390    // use nonzero_rows parameter in cvDFT() call below
3391
3392    cvDFT( dft_B, dft_B, CV_DXT_FORWARD, B->rows );
3393
3394    cvMulSpectrums( dft_A, dft_B, dft_A, 0 /* or CV_DXT_MUL_CONJ to get correlation
3395                                              rather than convolution */ );
3396
3397    cvDFT( dft_A, dft_A, CV_DXT_INV_SCALE, conv->rows ); // calculate only the top part
3398    cvGetSubRect( dft_A, &tmp, cvRect(0,0,conv->cols,conv->rows) );
3399
3400    cvCopy( &tmp, conv );
3401 </pre></p>
3402
3403
3404 <hr><h3><a name="decl_cvGetOptimalDFTSize">GetOptimalDFTSize</a></h3>
3405 <p class="Blurb">Returns optimal DFT size for given vector size</p>
3406 <pre>
3407 int cvGetOptimalDFTSize( int size0 );
3408 </pre><p><dl>
3409 <dt>size0<dd>Vector size.
3410 </dl><p>
3411 The function <code>cvGetOptimalDFTSize</code> returns the minimum
3412 number <code>N</code> that is greater to equal to <code>size0</code>, such that DFT of a vector
3413 of size <code>N</code> can be computed fast. In the current implementation
3414 <code>N=2<sup>p</sup>&times;3<sup>q</sup>&times;5<sup>r</sup></code> for some <code>p, q, r</code>.
3415 </p>
3416 <p>The function returns a negative number if <code>size0</code> is too large (very close to <code>INT_MAX</code>)</p>
3417
3418
3419 <hr><h3><a name="decl_cvMulSpectrums">MulSpectrums</a></h3>
3420 <p class="Blurb">Performs per-element multiplication of two Fourier spectrums</p>
3421 <pre>
3422 void cvMulSpectrums( const CvArr* src1, const CvArr* src2, CvArr* dst, int flags );
3423 </pre><p><dl>
3424 <dt>src1<dd>The first source array.
3425 <dt>src2<dd>The second source array.
3426 <dt>dst<dd>The destination array of the same type and the same size of the sources.
3427 <dt>flags<dd>A combination of the following values:<br>
3428               <code>CV_DXT_ROWS</code> - treat each row of the arrays as a separate spectrum
3429                                          (see <a href="#decl_cvDFT">cvDFT</a> parameters description).<br>
3430               <code>CV_DXT_MUL_CONJ</code> - conjugate the second source array before the multiplication.<br>
3431 </dl><p>
3432 The function <code>cvMulSpectrums</code> performs per-element multiplication
3433 of the two CCS-packed or complex matrices that are results of real or complex Fourier transform.
3434 </p><p>
3435 The function, together with <a href="#decl_cvDFT">cvDFT</a>, may be used to calculate convolution
3436 of two arrays fast.
3437 </p>
3438
3439 <hr><h3><a name="decl_cvDCT">DCT</a></h3>
3440 <p class="Blurb">Performs forward or inverse Discrete Cosine transform of 1D or 2D floating-point array</p>
3441 <pre>
3442 #define CV_DXT_FORWARD  0
3443 #define CV_DXT_INVERSE  1
3444 #define CV_DXT_ROWS     4
3445
3446 void cvDCT( const CvArr* src, CvArr* dst, int flags );
3447 </pre><p><dl>
3448 <dt>src<dd>Source array, real 1D or 2D array.
3449 <dt>dst<dd>Destination array of the same size and same type as the source.
3450 <dt>flags<dd>Transformation flags, a combination of the following values:<br>
3451               <code>CV_DXT_FORWARD</code> - do forward 1D or 2D transform.<br>
3452               <code>CV_DXT_INVERSE</code> - do inverse 1D or 2D transform.<br>
3453               <code>CV_DXT_ROWS</code> - do forward or inverse transform of every individual row of the input
3454                                          matrix. This flag allows user to transform multiple vectors simultaneously and
3455                                          can be used to decrease the overhead (which is sometimes several times
3456                                          larger than the processing itself), to do 3D and higher-dimensional
3457                                          transforms etc.
3458 </dl><p>
3459 The function <code>cvDCT</code> performs forward or inverse transform of
3460 1D or 2D floating-point array:
3461 <pre>
3462 Forward Cosine transform of 1D vector of N elements:
3463 y = C<sup>(N)</sup>&bull;x, where C<sup>(N)</sup><sub>jk</sub>=sqrt((j==0?1:2)/N)&bull;cos(Pi&bull;(2k+1)&bull;j/N)
3464
3465 Inverse Cosine transform of 1D vector of N elements:
3466 x = (C<sup>(N)</sup>)<sup>-1</sup>&bull;y = (C<sup>(N)</sup>)<sup>T</sup>&bull;y
3467
3468 Forward Cosine transform of 2D vector of M&times;N elements:
3469 Y = (C<sup>(M)</sup>)&bull;X&bull;(C<sup>(N)</sup>)<sup>T</sup>
3470
3471 Inverse Cosine transform of 2D vector of M&times;N elements:
3472 X = (C<sup>(M)</sup>)<sup>T</sup>&bull;Y&bull;C<sup>(N)</sup>
3473 </pre>
3474
3475
3476 <hr><h1><a name="cxcore_ds">Dynamic Structures</a></h1>
3477
3478 <hr><h2><a name="cxcore_ds_storages">Memory Storages</a></h2>
3479
3480 <hr><h3><a name="decl_CvMemStorage">CvMemStorage</a></h3>
3481 <p class="Blurb">Growing memory storage</p>
3482 <pre>
3483 typedef struct CvMemStorage
3484 {
3485     struct CvMemBlock* bottom;/* first allocated block */
3486     struct CvMemBlock* top; /* the current memory block - top of the stack */
3487     struct CvMemStorage* parent; /* borrows new blocks from */
3488     int block_size; /* block size */
3489     int free_space; /* free space in the <code>top</code> block (in bytes) */
3490 } CvMemStorage;
3491 </pre>
3492 <p>
3493 Memory storage is a low-level structure used to store dynamically growing data structures such as
3494 sequences, contours, graphs, subdivisions etc. It is organized as a list of memory blocks of
3495 equal size - <code>bottom</code> field is the beginning of the list of blocks</code>
3496 and <code>top</code> is the currently used block, but not necessarily the last block of the list. All blocks
3497 between <code>bottom</code> and <code>top</code>, not including the latter, are considered fully occupied;
3498 and all blocks between <code>top</code> and the last block, not including <code>top</code>,
3499 are considered free and <code>top</code> block itself is partly occupied - <code>free_space</code>
3500 contains the number of free bytes left in the end of <code>top</code>.
3501 </p><p>New memory buffer that may be allocated explicitly by <a href="#decl_cvMemStorageAlloc">cvMemStorageAlloc</a> function
3502 or implicitly by
3503 higher-level functions, such as <a href="#decl_cvSeqPush">cvSeqPush</a>, <a href="#decl_cvGraphAddEdge">cvGraphAddEdge</a> etc., <code>always</code>
3504 starts in the end of the current block if it fits there. After allocation <code>free_space</code>
3505 is decremented by the size of the allocated buffer plus some padding to keep the proper alignment.
3506 When the allocated buffer does not fit into the available part of <code>top</code>, the next storage
3507 block from the list is taken as <code>top</code> and <code>free_space</code> is reset to the
3508 whole block size prior to the allocation.</p><p>
3509 If there is no more free blocks, a new block is allocated (or borrowed from parent, see
3510 <a href="#decl_cvCreateChildMemStorage">cvCreateChildMemStorage</a>) and added to the end of list. Thus, the storage behaves as a stack
3511 with <code>bottom</code> indicating bottom of the stack and the pair (<code>top</code>, <code>free_space</code>)
3512 indicating top of the stack. The stack top may be saved via <a href="#decl_cvSaveMemStoragePos">cvSaveMemStoragePos</a>,
3513 restored via <a href="#decl_cvRestoreMemStoragePos">cvRestoreMemStoragePos</a> or reset via <a href="#decl_cvClearStorage">cvClearStorage</a>.
3514 </p>
3515
3516
3517 <hr><h3><a name="decl_CvMemBlock">CvMemBlock</a></h3>
3518 <p class="Blurb">Memory storage block</p>
3519 <pre>
3520 typedef struct CvMemBlock
3521 {
3522     struct CvMemBlock* prev;
3523     struct CvMemBlock* next;
3524 } CvMemBlock;
3525 </pre>
3526 <p>
3527 The structure <a href="#decl_CvMemBlock">CvMemBlock</a> represents a single block of memory storage.
3528 Actual data of the memory blocks follows the header, that is, the <code>i-th</code> byte of
3529 the memory block can be retrieved with the expression <code>((char*)(mem_block_ptr+1))[i]</code>.
3530 However, normally there is no need to access the storage structure fields directly.
3531 </p>
3532
3533
3534 <hr><h3><a name="decl_CvMemStoragePos">CvMemStoragePos</a></h3>
3535 <p class="Blurb">Memory storage position</p>
3536 <pre>
3537 typedef struct CvMemStoragePos
3538 {
3539     CvMemBlock* top;
3540     int free_space;
3541 } CvMemStoragePos;
3542 </pre>
3543 <p>
3544 The structure described below stores the position of the stack top that can be
3545 saved via <a href="#decl_cvSaveMemStoragePos">cvSaveMemStoragePos</a> and restored via <a href="#decl_cvRestoreMemStoragePos">cvRestoreMemStoragePos</a>.</p>
3546
3547
3548 <hr><h3><a name="decl_cvCreateMemStorage">CreateMemStorage</a></h3>
3549 <p class="Blurb">Creates memory storage</p>
3550 <pre>
3551 CvMemStorage* cvCreateMemStorage( int block_size=0 );
3552 </pre><p><dl>
3553 <dt>block_size<dd>Size of the storage blocks in bytes. If it is 0, the block size is set to default value
3554 - currently it is &asymp;64K.
3555 </dl><p>
3556 The function <code>cvCreateMemStorage</code> creates a memory storage and returns pointer
3557 to it. Initially the storage is empty. All fields of the header, except the <code>block_size</code>,
3558 are set to 0.</p>
3559
3560
3561 <hr><h3><a name="decl_cvCreateChildMemStorage">CreateChildMemStorage</a></h3>
3562 <p class="Blurb">Creates child memory storage</p>
3563 <pre>
3564 CvMemStorage* cvCreateChildMemStorage( CvMemStorage* parent );
3565 </pre><p><dl>
3566 <dt>parent<dd>Parent memory storage.
3567 </dl><p>
3568 The function <code>cvCreateChildMemStorage</code> creates a child memory storage that is similar
3569 to simple memory storage except for the differences in the memory
3570 allocation/deallocation mechanism. When a child storage needs a new block to
3571 add to the block list, it tries to get this block from the parent. The first
3572 unoccupied parent block available is taken and excluded from the parent block
3573 list. If no blocks are available, the parent either allocates a block or borrows
3574 one from its own parent, if any. In other words, the chain, or a more complex
3575 structure, of memory storages where every storage is a child/parent of another
3576 is possible. When a child storage is released or even cleared, it returns all
3577 blocks to the parent. In other aspects, the child storage is the same as the simple storage.</p>
3578 <p>
3579 The children storages are useful in the following situation.
3580 Imagine that user needs to process dynamical data resided in some storage and
3581 put the result back to the same storage. With the simplest approach, when temporary
3582 data is resided in the same storage as the input and output data, the storage
3583 will look as following after processing:</p>
3584 <p>
3585 <font color=blue>Dynamic data processing without using child storage</font>
3586 </p>
3587 <p>
3588 <img align="center" src="pics/memstorage1.png" >
3589 </p>
3590 <p>
3591 That is, garbage appears in the middle of the storage.
3592 However, if one creates a child memory storage in the beginning of the processing,
3593 writes temporary data there and releases the child storage in the end, no garbage will
3594 appear in the source/destination storage:</p>
3595 <p><font color=blue>Dynamic data processing using a child storage</font>
3596 </p><p>
3597 <img align="center" src="pics/memstorage2.png" >
3598 </p>
3599
3600
3601 <hr><h3><a name="decl_cvReleaseMemStorage">ReleaseMemStorage</a></h3>
3602 <p class="Blurb">Releases memory storage</p>
3603 <pre>
3604 void cvReleaseMemStorage( CvMemStorage** storage );
3605 </pre><p><dl>
3606 <dt>storage<dd>Pointer to the released storage.
3607 </dl><p>
3608 The function <code>cvReleaseMemStorage</code> deallocates all storage memory blocks or returns
3609 them to the parent, if any. Then it deallocates the storage header and clears
3610 the pointer to the storage. All children of the storage must be released before
3611 the parent is released.</p>
3612
3613
3614 <hr><h3><a name="decl_cvClearMemStorage">ClearMemStorage</a></h3>
3615 <p class="Blurb">Clears memory storage</p>
3616 <pre>
3617 void cvClearMemStorage( CvMemStorage* storage );
3618 </pre><p><dl>
3619 <dt>storage<dd>Memory storage.
3620 </dl><p>
3621 The function <code>cvClearMemStorage</code> resets the top (free space boundary) of the storage
3622 to the very beginning. This function does not deallocate any memory. If the
3623 storage has a parent, the function returns all blocks to the parent.</p>
3624
3625
3626 <hr><h3><a name="decl_cvMemStorageAlloc">MemStorageAlloc</a></h3>
3627 <p class="Blurb">Allocates memory buffer in the storage</p>
3628 <pre>
3629 void* cvMemStorageAlloc( CvMemStorage* storage, size_t size );
3630 </pre><p><dl>
3631 <dt>storage<dd>Memory storage.
3632 <dt>size<dd>Buffer size.
3633 </dl><p>
3634 The function <code>cvMemStorageAlloc</code> allocates memory buffer in the storage. The buffer size
3635 must not exceed the storage block size, otherwise runtime error is raised. The buffer address is
3636 aligned by <code>CV_STRUCT_ALIGN</code> (=<code>sizeof(double)</code> for the moment) bytes.
3637 </p>
3638
3639
3640 <hr><h3><a name="decl_cvMemStorageAllocString">MemStorageAllocString</a></h3>
3641 <p class="Blurb">Allocates text string in the storage</p>
3642 <pre>
3643 typedef struct CvString
3644 {
3645     int len;
3646     char* ptr;
3647 }
3648 CvString;
3649
3650 CvString cvMemStorageAllocString( CvMemStorage* storage, const char* ptr, int len=-1 );
3651 </pre><p><dl>
3652 <dt>storage<dd>Memory storage.
3653 <dt>ptr<dd>The string.
3654 <dt>len<dd>Length of the string (not counting the ending '\0'). If the parameter is negative,
3655            the function computes the length.
3656 </dl><p>
3657 The function <code>cvMemStorageAllocString</code> creates copy of the
3658 string in the memory storage. It returns the structure that contains user-passed or computed length
3659 of the string and pointer to the copied string.
3660 </p>
3661
3662
3663 <hr><h3><a name="decl_cvSaveMemStoragePos">SaveMemStoragePos</a></h3>
3664 <p class="Blurb">Saves memory storage position</p>
3665 <pre>
3666 void cvSaveMemStoragePos( const CvMemStorage* storage, CvMemStoragePos* pos );
3667 </pre><p><dl>
3668 <dt>storage<dd>Memory storage.
3669 <dt>pos<dd>The output position of the storage top.
3670 </dl><p>
3671 The function <code>cvSaveMemStoragePos</code> saves the current position of the storage top to
3672 the parameter <code>pos</code>. The function <code>cvRestoreMemStoragePos</code> can further retrieve
3673 this position.</p>
3674
3675
3676 <hr><h3><a name="decl_cvRestoreMemStoragePos">RestoreMemStoragePos</a></h3>
3677 <p class="Blurb">Restores memory storage position</p>
3678 <pre>
3679 void cvRestoreMemStoragePos( CvMemStorage* storage, CvMemStoragePos* pos );
3680 </pre><p><dl>
3681 <dt>storage<dd>Memory storage.
3682 <dt>pos<dd>New storage top position.
3683 </dl><p>
3684 The function <code>cvRestoreMemStoragePos</code> restores the position of the storage top from
3685 the parameter <code>pos</code>. This function and The function <code>cvClearMemStorage</code> are the
3686 only methods to release memory occupied in memory blocks.
3687 Note again that there is no way to free memory in the middle of the occupied part of the storage.
3688 </p>
3689
3690
3691 <hr><h2><a name="cxcore_ds_sequences">Sequences</a></h2>
3692
3693 <hr><h3><a name="decl_CvSeq">CvSeq</a></h3>
3694 <p class="Blurb">Growable sequence of elements</p>
3695 <pre>
3696 #define CV_SEQUENCE_FIELDS() \
3697     int flags; /* miscellaneous flags */ \
3698     int header_size; /* size of sequence header */ \
3699     struct CvSeq* h_prev; /* previous sequence */ \
3700     struct CvSeq* h_next; /* next sequence */ \
3701     struct CvSeq* v_prev; /* 2nd previous sequence */ \
3702     struct CvSeq* v_next; /* 2nd next sequence */ \
3703     int total; /* total number of elements */ \
3704     int elem_size;/* size of sequence element in bytes */ \
3705     char* block_max;/* maximal bound of the last block */ \
3706     char* ptr; /* current write pointer */ \
3707     int delta_elems; /* how many elements allocated when the sequence grows (sequence granularity) */ \
3708     CvMemStorage* storage; /* where the seq is stored */ \
3709     CvSeqBlock* free_blocks; /* free blocks list */ \
3710     CvSeqBlock* first; /* pointer to the first sequence block */
3711
3712
3713 typedef struct CvSeq
3714 {
3715     CV_SEQUENCE_FIELDS()
3716 } CvSeq;
3717 </pre>
3718 <p>
3719 The structure <a href="#decl_CvSeq">CvSeq</a> is a base for all of OpenCV dynamic data structures.</p>
3720 <p>Such an unusual definition via a helper macro simplifies the extension of the structure
3721 <a href="#decl_CvSeq">CvSeq</a> with additional parameters.
3722 To extend <a href="#decl_CvSeq">CvSeq</a> the user may define a new structure and
3723 put user-defined fields after all <a href="#decl_CvSeq">CvSeq</a> fields that are included via the macro
3724 <code>CV_SEQUENCE_FIELDS()</code>.</p>
3725 <p>There are two types of sequences - dense and sparse. Base type for dense sequences is <a href="#decl_CvSeq">CvSeq</a>
3726 and such sequences are used to represent growable 1d arrays - vectors, stacks, queues, deques.
3727 They have no gaps in the middle - if an element is removed from the middle or inserted into the middle
3728 of the sequence the elements from the closer end are shifted.
3729 Sparse sequences have <a href="#decl_CvSet">CvSet</a> base
3730 class and they are discussed later in more details. They are sequences of nodes each of those may be
3731 either occupied or free as indicated by the node flag. Such sequences are used for unordered data
3732 structures such as sets of elements, graphs, hash tables etc.</p>
3733
3734 <p>The field <code>header_size</code> contains the actual size of the
3735 sequence header and should be greater or equal to <code>sizeof(CvSeq)</code>.</p><p>The fields
3736 <code>h_prev, h_next, v_prev, v_next</code> can be used to create hierarchical structures
3737 from separate sequences. The fields <code>h_prev</code> and <code>h_next</code> point to the previous and
3738 the next sequences on the same hierarchical level while the fields <code>v_prev</code> and
3739 <code>v_next</code> point to the previous and the next sequence in the vertical direction,
3740 that is, parent and its first child. But these are just names and the pointers
3741 can be used in a different way.</p><p>The field <code>first</code> points to the first sequence
3742 block, whose structure is described below.</p>
3743 <p>The field <code>total</code> contains the actual number of dense sequence elements and
3744 number of allocated nodes in sparse sequence.</p>
3745 <p>The field <code>flags</code>contain the particular dynamic type
3746 signature (<code>CV_SEQ_MAGIC_VAL</code> for dense sequences and <code>CV_SET_MAGIC_VAL</code> for sparse sequences)
3747 in the highest 16 bits and miscellaneous information about the sequence.
3748 The lowest <code>CV_SEQ_ELTYPE_BITS</code> bits contain the ID of the
3749 element type. Most of sequence processing functions do not use element type
3750 but element size stored in <code>elem_size</code>.
3751 If sequence contains the numeric data of one of <a href="#decl_CvMat">CvMat</a> type
3752 then the element type matches to the corresponding <a href="#decl_CvMat">CvMat</a> element type, e.g.
3753 CV_32SC2 may be used for sequence of 2D points, CV_32FC1 for sequences of floating-point values etc.
3754 <code>CV_SEQ_ELTYPE(seq_header_ptr)</code> macro retrieves the type of sequence elements.
3755 Processing function that work with numerical sequences check that <code>elem_size</code> is equal
3756 to the calculated from the type element size.
3757 Besides <a href="#decl_CvMat">CvMat</a> compatible types, there are few extra element types defined
3758 in <a href="#decl_cvtypes.h">cvtypes.h</a> header:</p>
3759 <p><font color=blue>Standard Types of Sequence Elements</font></p>
3760 <pre>
3761     #define CV_SEQ_ELTYPE_POINT          CV_32SC2  /* (x,y) */
3762     #define CV_SEQ_ELTYPE_CODE           CV_8UC1   /* freeman code: 0..7 */
3763     #define CV_SEQ_ELTYPE_GENERIC        0 /* unspecified type of sequence elements */
3764     #define CV_SEQ_ELTYPE_PTR            CV_USRTYPE1 /* =6 */
3765     #define CV_SEQ_ELTYPE_PPOINT         CV_SEQ_ELTYPE_PTR  /* &elem: pointer to element of other sequence */
3766     #define CV_SEQ_ELTYPE_INDEX          CV_32SC1  /* #elem: index of element of some other sequence */
3767     #define CV_SEQ_ELTYPE_GRAPH_EDGE     CV_SEQ_ELTYPE_GENERIC  /* &next_o, &next_d, &vtx_o, &vtx_d */
3768     #define CV_SEQ_ELTYPE_GRAPH_VERTEX   CV_SEQ_ELTYPE_GENERIC  /* first_edge, &(x,y) */
3769     #define CV_SEQ_ELTYPE_TRIAN_ATR      CV_SEQ_ELTYPE_GENERIC  /* vertex of the binary tree   */
3770     #define CV_SEQ_ELTYPE_CONNECTED_COMP CV_SEQ_ELTYPE_GENERIC  /* connected component  */
3771     #define CV_SEQ_ELTYPE_POINT3D        CV_32FC3  /* (x,y,z)  */
3772 </pre>
3773 <p>
3774 The next <code>CV_SEQ_KIND_BITS</code> bits specify the kind of the sequence:</p>
3775 <p><font color=blue>Standard Kinds of Sequences</font></p>
3776 <pre>
3777     /* generic (unspecified) kind of sequence */
3778     #define CV_SEQ_KIND_GENERIC     (0 &lt;&lt; CV_SEQ_ELTYPE_BITS)
3779
3780     /* dense sequence subtypes */
3781     #define CV_SEQ_KIND_CURVE       (1 &lt;&lt; CV_SEQ_ELTYPE_BITS)
3782     #define CV_SEQ_KIND_BIN_TREE    (2 &lt;&lt; CV_SEQ_ELTYPE_BITS)
3783
3784     /* sparse sequence (or set) subtypes */
3785     #define CV_SEQ_KIND_GRAPH       (3 &lt;&lt; CV_SEQ_ELTYPE_BITS)
3786     #define CV_SEQ_KIND_SUBDIV2D    (4 &lt;&lt; CV_SEQ_ELTYPE_BITS)
3787 </pre>
3788 <p>
3789 The remaining bits are used to identify different features specific to certain
3790 sequence kinds and element types. For example, curves made of points (
3791 <code>CV_SEQ_KIND_CURVE|CV_SEQ_ELTYPE_POINT</code> ), together with the flag
3792 <code>CV_SEQ_FLAG_CLOSED</code> belong to the type <code>CV_SEQ_POLYGON</code> or, if other flags are
3793 used, to its subtype. Many contour processing functions check the type of the input
3794 sequence and report an error if they do not support this type. The file
3795 <a href="#decl_cvtypes.h">cvtypes.h</a> stores the complete list of all supported predefined sequence types
3796 and helper macros designed to get the sequence type of other properties.
3797 Below follows the definition of the building block of sequences.</p>
3798
3799
3800 <hr><h3><a name="decl_CvSeqBlock">CvSeqBlock</a></h3>
3801 <p class="Blurb">Continuous sequence block</p>
3802 <pre>
3803 typedef struct CvSeqBlock
3804 {
3805     struct CvSeqBlock* prev; /* previous sequence block */
3806     struct CvSeqBlock* next; /* next sequence block */
3807     int start_index; /* index of the first element in the block +
3808     sequence->first->start_index */
3809     int count; /* number of elements in the block */
3810     char* data; /* pointer to the first element of the block */
3811 } CvSeqBlock;
3812 </pre>
3813 <p>
3814 Sequence blocks make up a circular double-linked list, so the pointers <code>prev</code> and
3815 <code>next</code> are never <code>NULL</code> and point to the previous and the next sequence blocks
3816 within the sequence. It means that <code>next</code> of the last block is the first block and
3817 <code>prev</code> of the first block is the last block. The fields <code>start_index</code> and <code>count</code> help
3818 to track the block location within the sequence. For example, if the sequence
3819 consists of 10 elements and splits into three blocks of 3, 5, and 2 elements,
3820 and the first block has the parameter <code>start_index = 2</code>, then pairs <code>(start_index, count)</code>
3821 for the sequence blocks are <code>(2,3), (5, 5)</code>, and <code>(10, 2)</code>
3822 correspondingly. The parameter <code>start_index</code> of the first block is usually <code>0</code>
3823 unless some elements have been inserted at the beginning of the sequence.
3824 </p>
3825
3826
3827 <hr><h3><a name="decl_CvSlice">CvSlice</a></h3>
3828 <p class="Blurb">A sequence slice</p>
3829 <pre>
3830 typedef struct CvSlice
3831 {
3832     int start_index;
3833     int end_index;
3834 } CvSlice;
3835
3836 inline CvSlice cvSlice( int start, int end );
3837 #define CV_WHOLE_SEQ_END_INDEX 0x3fffffff
3838 #define CV_WHOLE_SEQ  cvSlice(0, CV_WHOLE_SEQ_END_INDEX)
3839
3840 /* calculates the sequence slice length */
3841 int cvSliceLength( CvSlice slice, const CvSeq* seq );
3842 </pre>
3843 <p>
3844 Some of functions that operate on sequences take <code>CvSlice slice</code> parameter that is
3845 often set to the whole sequence (CV_WHOLE_SEQ) by default. Either of the <code>start_index</code>
3846 and <code>end_index</code> may be negative or exceed the sequence length, <code>start_index</code>
3847 is inclusive, <code>end_index</code> is exclusive boundary. If they are equal, the slice is considered
3848 empty (i.e. contains no elements). Because sequences are treated as circular structures,
3849 the slice may select a few elements in the end of a sequence followed by a few elements in the beginning
3850 of the sequence, for example, <code>cvSlice(-2, 3)</code> in case of 10-element sequence will select 5-element slice,
3851 containing pre-last (8th), last (9th), the very first (0th), second (1th) and third (2nd) elements.
3852 The functions normalize the slice argument in the following way: first, <a href="#decl_CvSlice">cvSliceLength</a>
3853 is called to determine the length of the slice, then, <code>start_index</code> of the slice is
3854 normalized similarly to the argument of <a href="#decl_cvGetSeqElem">cvGetSeqElem</a>
3855 (i.e. negative indices are allowed).
3856 The actual slice to process starts at the normalized <code>start_index</code>
3857 and lasts <a href="#decl_CvSlice">cvSliceLength</a> elements
3858 (again, assuming the sequence is a circular structure).
3859 </p>
3860
3861 <p>If a function does not take slice argument, but you want to process only a part of the sequence,
3862 the sub-sequence may be extracted using <a href="#decl_cvSeqSlice">cvSeqSlice</a> function,
3863 or stored as into a continuous buffer with <a href="#decl_cvCvtSeqToArray">cvCvtSeqToArray</a>
3864 (optionally, followed by <a href="#decl_cvMakeSeqHeaderForArray">cvMakeSeqHeaderForArray</a>.
3865 </p>
3866
3867
3868 <hr><h3><a name="decl_cvCreateSeq">CreateSeq</a></h3>
3869 <p class="Blurb">Creates sequence</p>
3870 <pre>
3871 CvSeq* cvCreateSeq( int seq_flags, int header_size,
3872                     int elem_size, CvMemStorage* storage );
3873 </pre><p><dl>
3874 <dt>seq_flags<dd>Flags of the created sequence. If the sequence is not passed to any
3875 function working with a specific type of sequences, the sequence value may be
3876 set to 0, otherwise the appropriate type must be selected from the list of
3877 predefined sequence types.
3878 <dt>header_size<dd>Size of the sequence header; must be greater or equal to
3879 <code>sizeof(CvSeq)</code>. If a specific type or its extension is indicated, this type must
3880 fit the base type header.
3881 <dt>elem_size<dd>Size of the sequence elements in bytes. The size must be consistent
3882 with the sequence type. For example, for a sequence of points to be created, the
3883 element type <code>CV_SEQ_ELTYPE_POINT</code> should be specified and the parameter <code>elem_size</code>
3884 must be equal to <code>sizeof(CvPoint)</code>.
3885 <dt>storage<dd>Sequence location.
3886 </dl><p>
3887 The function <code>cvCreateSeq</code> creates a sequence and returns the pointer to it. The
3888 function allocates the sequence header in the storage block as one continuous
3889 chunk and sets the structure fields <code>flags</code>, <code>elem_size</code>, <code>header_size</code> and <code>storage</code> to
3890 passed values, sets <code>delta_elems</code> to the default value (that may be reassigned using
3891 <a href="#decl_cvSetSeqBlockSize">cvSetSeqBlockSize</a> function), and clears other header fields,
3892 including the space after the first <code>sizeof(CvSeq)</code> bytes.</p>
3893
3894
3895 <hr><h3><a name="decl_cvSetSeqBlockSize">SetSeqBlockSize</a></h3>
3896 <p class="Blurb">Sets up sequence block size</p>
3897 <pre>
3898 void cvSetSeqBlockSize( CvSeq* seq, int delta_elems );
3899 </pre><p><dl>
3900 <dt>seq<dd>Sequence.
3901 <dt>delta_elems<dd>Desirable sequence block size in elements.
3902 </dl><p>
3903 The function <code>cvSetSeqBlockSize</code> affects memory allocation granularity.
3904 When the free space in the sequence buffers has run out, the function allocates the space
3905 for <code>delta_elems</code> sequence elements. If this block immediately follows the one
3906 previously allocated, the two blocks are concatenated, otherwise, a new sequence
3907 block is created. Therefore, the bigger the parameter is, the lower the possible sequence
3908 fragmentation, but the more space in the storage is wasted. When the
3909 sequence is created, the parameter <code>delta_elems</code> is set to the default value &asymp;1K.
3910 The function can be called any time after the sequence is created and affects
3911 future allocations. The function can modify the passed value of the parameter to
3912 meet the memory storage constraints.
3913 </p>
3914
3915
3916 <hr><h3><a name="decl_cvSeqPush">SeqPush</a></h3>
3917 <p class="Blurb">Adds element to sequence end</p>
3918 <pre>
3919 char* cvSeqPush( CvSeq* seq, void* element=NULL );
3920 </pre><p><dl>
3921 <dt>seq<dd>Sequence.
3922 <dt>element<dd>Added element.
3923 </dl><p>
3924 The function <code>cvSeqPush</code> adds an element to the end of sequence and returns pointer
3925 to the allocated element. If the input <code>element</code> is NULL,
3926 the function simply allocates a space for one more element.</p>
3927 <p>The following code demonstrates how to create a new sequence using this function:</p>
3928 <pre>
3929 CvMemStorage* storage = cvCreateMemStorage(0);
3930 CvSeq* seq = cvCreateSeq( CV_32SC1, /* sequence of integer elements */
3931                           sizeof(CvSeq), /* header size - no extra fields */
3932                           sizeof(int), /* element size */
3933                           storage /* the container storage */ );
3934 int i;
3935 for( i = 0; i &lt; 100; i++ )
3936 {
3937     int* added = (int*)cvSeqPush( seq, &i );
3938     printf( "%d is added\n", *added );
3939 }
3940
3941 ...
3942 /* release memory storage in the end */
3943 cvReleaseMemStorage( &storage );
3944 </pre>
3945 <p>
3946 The function <code>cvSeqPush</code> has O(1) complexity, but there is a faster method for
3947 writing large sequences (see <a href="#decl_cvStartWriteSeq">cvStartWriteSeq</a> and related functions).
3948 </p>
3949
3950 <hr><h3><a name="decl_cvSeqPop">SeqPop</a></h3>
3951 <p class="Blurb">Removes element from sequence end</p>
3952 <pre>
3953 void cvSeqPop( CvSeq* seq, void* element=NULL );
3954 </pre><p><dl>
3955 <dt>seq<dd>Sequence.
3956 <dt>element<dd>Optional parameter. If the pointer is not zero, the function copies the
3957 removed element to this location.
3958 </dl><p>
3959 The function <code>cvSeqPop</code> removes an element from the sequence. The function reports
3960 an error if the sequence is already empty. The function has O(1) complexity. </p>
3961
3962
3963 <hr><h3><a name="decl_cvSeqPushFront">SeqPushFront</a></h3>
3964 <p class="Blurb">Adds element to sequence beginning</p>
3965 <pre>
3966 char* cvSeqPushFront( CvSeq* seq, void* element=NULL );
3967 </pre><p><dl>
3968 <dt>seq<dd>Sequence.
3969 <dt>element<dd>Added element.
3970 </dl><p>
3971 The function <code>cvSeqPushFront</code> is similar to <a href="#decl_cvSeqPush">cvSeqPush</a> but it adds the new element
3972 to the beginning of the sequence. The function has O(1) complexity.
3973 </p>
3974
3975
3976 <hr><h3><a name="decl_cvSeqPopFront">SeqPopFront</a></h3>
3977 <p class="Blurb">Removes element from sequence beginning</p>
3978 <pre>
3979 void cvSeqPopFront( CvSeq* seq, void* element=NULL );
3980 </pre><p><dl>
3981 <dt>seq<dd>Sequence.
3982 <dt>element<dd>Optional parameter. If the pointer is not zero, the function copies the
3983 removed element to this location.
3984 </dl><p>
3985 The function <code>cvSeqPopFront</code> removes an element from the beginning of the sequence.
3986 The function reports an error if the sequence is already empty. The function has O(1) complexity. </p>
3987
3988
3989 <hr><h3><a name="decl_cvSeqPushMulti">SeqPushMulti</a></h3>
3990 <p class="Blurb">Pushes several elements to the either end of sequence</p>
3991 <pre>
3992 void cvSeqPushMulti( CvSeq* seq, void* elements, int count, int in_front=0 );
3993 </pre><p><dl>
3994 <dt>seq<dd>Sequence.
3995 <dt>elements<dd>Added elements.
3996 <dt>count<dd>Number of elements to push.
3997 <dt>in_front<dd>The flags specifying the modified sequence end:<br>
3998                 CV_BACK (=0) - the elements are added to the end of sequence<br>
3999                 CV_FRONT(!=0) - the elements are added to the beginning of sequence<br>
4000 </dl><p>
4001 The function <code>cvSeqPushMulti</code> adds several elements to either end of the sequence.
4002 The elements are added to the sequence in the same order as they are arranged in the
4003 input array but they can fall into different sequence blocks.</p>
4004
4005
4006 <hr><h3><a name="decl_cvSeqPopMulti">SeqPopMulti</a></h3>
4007 <p class="Blurb">Removes several elements from the either end of sequence</p>
4008 <pre>
4009 void cvSeqPopMulti( CvSeq* seq, void* elements, int count, int in_front=0 );
4010 </pre><p><dl>
4011 <dt>seq<dd>Sequence.
4012 <dt>elements<dd>Removed elements.
4013 <dt>count<dd>Number of elements to pop.
4014 <dt>in_front<dd>The flags specifying the modified sequence end:<br>
4015                 CV_BACK (=0) - the elements are removed from the end of sequence<br>
4016                 CV_FRONT(!=0) - the elements are removed from the beginning of sequence<br>
4017 </dl><p>
4018 The function <code>cvSeqPopMulti</code> removes several elements from either end of the sequence.
4019 If the number of the elements to be removed exceeds the total number of elements
4020 in the sequence, the function removes as many elements as possible.</p>
4021
4022
4023 <hr><h3><a name="decl_cvSeqInsert">SeqInsert</a></h3>
4024 <p class="Blurb">Inserts element in sequence middle</p>
4025 <pre>
4026 char* cvSeqInsert( CvSeq* seq, int before_index, void* element=NULL );
4027 </pre><p><dl>
4028 <dt>seq<dd>Sequence.
4029 <dt>before_index<dd>Index before which the element is inserted. Inserting before 0 (the minimal allowed value
4030 of the parameter) is equal to <a href="#decl_cvSeqPushFront">cvSeqPushFront</a> and inserting before <code>seq->total</code> (the maximal
4031 allowed value of the parameter) is equal to <a href="#decl_cvSeqPush">cvSeqPush</a>.
4032 <dt>element<dd>Inserted element.
4033 </dl><p>
4034 The function <code>cvSeqInsert</code> shifts the sequence elements from the inserted position
4035 to the nearest end of the sequence and copies the <code>element</code> content there if
4036 the pointer is not NULL. The function returns pointer to the inserted element.</p>
4037
4038
4039 <hr><h3><a name="decl_cvSeqRemove">SeqRemove</a></h3>
4040 <p class="Blurb">Removes element from sequence middle</p>
4041 <pre>
4042 void cvSeqRemove( CvSeq* seq, int index );
4043 </pre><p><dl>
4044 <dt>seq<dd>Sequence.
4045 <dt>index<dd>Index of removed element.
4046 </dl><p>
4047 The function <code>cvSeqRemove</code> removes elements with the given index. If the index is
4048 out of range the function reports an error.
4049 An attempt to remove an element from an empty sequence is a
4050 partial case of this situation. The function removes an element by shifting the
4051 sequence elements between the nearest end of the sequence and the <code>index</code>-th position, not
4052 counting the latter.</p>
4053
4054
4055 <hr><h3><a name="decl_cvClearSeq">ClearSeq</a></h3>
4056 <p class="Blurb">Clears sequence</p>
4057 <pre>
4058 void cvClearSeq( CvSeq* seq );
4059 </pre><p><dl>
4060 <dt>seq<dd>Sequence.
4061 </dl><p>
4062 The function <code>cvClearSeq</code> removes all elements from the sequence. The function does not return the
4063 memory to the storage, but this memory is reused later when new elements are added
4064 to the sequence. This function time complexity is <code>O(1)</code>.
4065
4066
4067 <hr><h3><a name="decl_cvGetSeqElem">GetSeqElem</a></h3>
4068 <p class="Blurb">Returns pointer to sequence element by its index</p>
4069 <pre>
4070 char* cvGetSeqElem( const CvSeq* seq, int index );
4071 #define CV_GET_SEQ_ELEM( TYPE, seq, index )  (TYPE*)cvGetSeqElem( (CvSeq*)(seq), (index) )
4072 </pre><p><dl>
4073 <dt>seq<dd>Sequence.
4074 <dt>index<dd>Index of element.
4075 </dl><p>
4076 The function <code>cvGetSeqElem</code> finds the element with the given index in the sequence
4077 and returns the pointer to it. If the element is not found,
4078 the function returns 0. The function supports negative indices, where -1 stands
4079 for the last sequence element, -2 stands for the one before last, etc. If the
4080 sequence is most likely to consist of a single sequence block or the desired
4081 element is likely to be located in the first block, then the macro
4082 <code>CV_GET_SEQ_ELEM( elemType, seq, index )</code> should be used, where the parameter
4083 <code>elemType</code> is the type of sequence elements ( <a href="#decl_CvPoint">CvPoint</a> for example), the parameter
4084 <code>seq</code> is a sequence, and the parameter <code>index</code> is the index of the desired element.
4085 The macro checks first whether the desired element belongs to the first block of
4086 the sequence and returns it if it does, otherwise the macro calls the main
4087 function <code>GetSeqElem</code>. Negative indices always cause the <a href="#decl_cvGetSeqElem">cvGetSeqElem</a> call.
4088 The function has O(1) time complexity assuming that number of blocks is much smaller than the
4089 number of elements.</p>
4090
4091
4092 <hr><h3><a name="decl_cvSeqElemIdx">SeqElemIdx</a></h3>
4093 <p class="Blurb">Returns index of concrete sequence element</p>
4094 <pre>
4095 int cvSeqElemIdx( const CvSeq* seq, const void* element, CvSeqBlock** block=NULL );
4096 </pre><p><dl>
4097 <dt>seq<dd>Sequence.
4098 <dt>element<dd>Pointer to the element within the sequence.
4099 <dt>block<dd>Optional argument. If the pointer is not <code>NULL</code>, the address of the
4100 sequence block that contains the element is stored in this location.
4101 </dl><p>
4102 The function <code>cvSeqElemIdx</code> returns the index of a sequence element or a negative
4103 number if the element is not found.</p>
4104
4105
4106 <hr><h3><a name="decl_cvCvtSeqToArray">CvtSeqToArray</a></h3>
4107 <p class="Blurb">Copies sequence to one continuous block of memory</p>
4108 <pre>
4109 void* cvCvtSeqToArray( const CvSeq* seq, void* elements, CvSlice slice=CV_WHOLE_SEQ );
4110 </pre><p><dl>
4111 <dt>seq<dd>Sequence.
4112 <dt>elements<dd>Pointer to the destination array that must be large enough.
4113     It should be a pointer to data, not a matrix header.
4114 <dt>slice<dd>The sequence part to copy to the array.
4115 </dl><p>
4116 The function <code>cvCvtSeqToArray</code> copies the entire sequence or subsequence to the
4117 specified buffer and returns the pointer to the buffer.</p>
4118
4119
4120 <hr><h3><a name="decl_cvMakeSeqHeaderForArray">MakeSeqHeaderForArray</a></h3>
4121 <p class="Blurb">Constructs sequence from array</p>
4122 <pre>
4123 CvSeq* cvMakeSeqHeaderForArray( int seq_type, int header_size, int elem_size,
4124                                 void* elements, int total,
4125                                 CvSeq* seq, CvSeqBlock* block );
4126 </pre><p><dl>
4127 <dt>seq_type<dd>Type of the created sequence.
4128 <dt>header_size<dd>Size of the header of the sequence. Parameter sequence must point to
4129 the structure of that size or greater size.
4130 <dt>elem_size<dd>Size of the sequence element.
4131 <dt>elements<dd>Elements that will form a sequence.
4132 <dt>total<dd>Total number of elements in the sequence. The number of array elements
4133 must be equal to the value of this parameter.
4134 <dt>seq<dd>Pointer to the local variable that is used as the sequence header.
4135 <dt>block<dd>Pointer to the local variable that is the header of the single sequence
4136 block.
4137 </dl><p>
4138 The function <code>cvMakeSeqHeaderForArray</code> initializes sequence header for array.
4139 The sequence header as well as the sequence block are allocated by the user (for example, on stack).
4140 No data is copied by the function. The resultant sequence will consists of a single block and have
4141 NULL storage pointer, thus, it is possible to read its elements, but the attempts to
4142 add elements to the sequence will raise an error in most cases.</p>
4143
4144
4145 <hr><h3><a name="decl_cvSeqSlice">SeqSlice</a></h3>
4146 <p class="Blurb">Makes separate header for the sequence slice</p>
4147 <pre>
4148 CvSeq* cvSeqSlice( const CvSeq* seq, CvSlice slice,
4149                    CvMemStorage* storage=NULL, int copy_data=0 );
4150 </pre><p><dl>
4151 <dt>seq<dd>Sequence.
4152 <dt>slice<dd>The part of the sequence to extract.
4153 <dt>storage<dd>The destination storage to keep the new sequence header and the copied data if any.
4154                If it is NULL, the function uses the storage containing the input sequence.
4155 <dt>copy_data<dd>The flag that indicates whether to copy the elements of the extracted slice
4156                  (<code>copy_data</code>!=0) or not (<code>copy_data</code>=0)
4157 </dl><p>
4158 The function <code>cvSeqSlice</code> creates a sequence
4159 that represents the specified slice of the input sequence. The new sequence either shares the elements
4160 with the original sequence or has own copy of the elements.
4161 So if one needs to process a part of sequence but the processing function does not have a slice parameter,
4162 the required sub-sequence may be extracted using this function.
4163 </p>
4164
4165
4166 <hr><h3><a name="decl_cvCloneSeq">CloneSeq</a></h3>
4167 <p class="Blurb">Creates a copy of sequence</p>
4168 <pre>
4169 CvSeq* cvCloneSeq( const CvSeq* seq, CvMemStorage* storage=NULL );
4170 </pre><p><dl>
4171 <dt>seq<dd>Sequence.
4172 <dt>storage<dd>The destination storage to keep the new sequence header and the copied data if any.
4173                If it is NULL, the function uses the storage containing the input sequence.
4174 </dl><p>
4175 The function <code>cvCloneSeq</code> makes a complete copy of the input sequence and returns it.
4176 The call <code><a href="#decl_cvCloneSeq">cvCloneSeq</a>( seq, storage )</code> is equivalent to
4177 <code><a href="#decl_cvSeqSlice">cvSeqSlice</a>( seq, CV_WHOLE_SEQ, storage, 1 )</code>
4178 </p>
4179
4180
4181 <hr><h3><a name="decl_cvSeqRemoveSlice">SeqRemoveSlice</a></h3>
4182 <p class="Blurb">Removes sequence slice</p>
4183 <pre>
4184 void cvSeqRemoveSlice( CvSeq* seq, CvSlice slice );
4185 </pre><p><dl>
4186 <dt>seq<dd>Sequence.
4187 <dt>slice<dd>The part of the sequence to remove.
4188 </dl><p>
4189 The function <code>cvSeqRemoveSlice</code> removes slice from the sequence.</p>
4190
4191
4192 <hr><h3><a name="decl_cvSeqInsertSlice">SeqInsertSlice</a></h3>
4193 <p class="Blurb">Inserts array in the middle of sequence</p>
4194 <pre>
4195 void cvSeqInsertSlice( CvSeq* seq, int before_index, const CvArr* from_arr );
4196 </pre><p><dl>
4197 <dt>seq<dd>Sequence.
4198 <dt>slice<dd>The part of the sequence to remove.
4199 <dt>from_arr<dd>The array to take elements from.
4200 </dl><p>
4201 The function <code>cvSeqInsertSlice</code> inserts all <code>from_arr</code>
4202 array elements at the specified position of the sequence. The array <code>from_arr</code>
4203 can be a matrix or another sequence.</p>
4204
4205
4206 <hr><h3><a name="decl_cvSeqInvert">SeqInvert</a></h3>
4207 <p class="Blurb">Reverses the order of sequence elements</p>
4208 <pre>
4209 void cvSeqInvert( CvSeq* seq );
4210 </pre><p><dl>
4211 <dt>seq<dd>Sequence.
4212 </dl><p>
4213 The function <code>cvSeqInvert</code> reverses the sequence in-place - makes the first element go last,
4214 the last element go first etc.</p>
4215
4216
4217 <hr><h3><a name="decl_cvSeqSort">SeqSort</a></h3>
4218 <p class="Blurb">Sorts sequence element using the specified comparison function</p>
4219 <pre>
4220 /* a &lt; b ? -1 : a > b ? 1 : 0 */
4221 typedef int (CV_CDECL* CvCmpFunc)(const void* a, const void* b, void* userdata);
4222
4223 void cvSeqSort( CvSeq* seq, CvCmpFunc func, void* userdata=NULL );
4224 </pre><p><dl>
4225 <dt>seq<dd>The sequence to sort
4226 <dt>func<dd>The comparison function that returns negative, zero or positive value depending
4227             on the elements relation (see the above declaration and the example below) -
4228             similar function is used by <code>qsort</code> from C runtime except that in the latter
4229             <code>userdata</code> is not used
4230 <dt>userdata<dd>The user parameter passed to the comparison function;
4231                 helps to avoid global variables in some cases.
4232 </dl><p>
4233 The function <code>cvSeqSort</code> sorts the sequence in-place using the specified criteria.
4234 Below is the example of the function use:</p>
4235 <pre>
4236 /* Sort 2d points in top-to-bottom left-to-right order */
4237 static int cmp_func( const void* _a, const void* _b, void* userdata )
4238 {
4239     CvPoint* a = (CvPoint*)_a;
4240     CvPoint* b = (CvPoint*)_b;
4241     int y_diff = a->y - b->y;
4242     int x_diff = a->x - b->x;
4243     return y_diff ? y_diff : x_diff;
4244 }
4245
4246 ...
4247
4248 CvMemStorage* storage = cvCreateMemStorage(0);
4249 CvSeq* seq = cvCreateSeq( CV_32SC2, sizeof(CvSeq), sizeof(CvPoint), storage );
4250 int i;
4251
4252 for( i = 0; i &lt; 10; i++ )
4253 {
4254     CvPoint pt;
4255     pt.x = rand() % 1000;
4256     pt.y = rand() % 1000;
4257     cvSeqPush( seq, &pt );
4258 }
4259
4260 cvSeqSort( seq, cmp_func, 0 /* userdata is not used here */ );
4261
4262 /* print out the sorted sequence */
4263 for( i = 0; i &lt; seq->total; i++ )
4264 {
4265     CvPoint* pt = (CvPoint*)cvSeqElem( seq, i );
4266     printf( "(%d,%d)\n", pt->x, pt->y );
4267 }
4268
4269 cvReleaseMemStorage( &storage );
4270 </pre>
4271
4272
4273
4274 <hr><h3><a name="decl_cvSeqSearch">SeqSearch</a></h3>
4275 <p class="Blurb">Searches element in sequence</p>
4276 <pre>
4277 /* a &lt; b ? -1 : a > b ? 1 : 0 */
4278 typedef int (CV_CDECL* CvCmpFunc)(const void* a, const void* b, void* userdata);
4279
4280 char* cvSeqSearch( CvSeq* seq, const void* elem, CvCmpFunc func,
4281                    int is_sorted, int* elem_idx, void* userdata=NULL );
4282 </pre><p><dl>
4283 <dt>seq<dd>The sequence
4284 <dt>elem<dd>The element to look for
4285 <dt>func<dd>The comparison function that returns negative, zero or positive value depending
4286             on the elements relation (see also <a href="#decl_cvSeqSort">cvSeqSort</a>).
4287 <dt>is_sorted<dd>Whether the sequence is sorted or not.
4288 <dt>elem_idx<dd>Output parameter; index of the found element.
4289 <dt>userdata<dd>The user parameter passed to the comparison function;
4290                 helps to avoid global variables in some cases.
4291 </dl><p>
4292 The function <code>cvSeqSearch</code> searches the element in the sequence.
4293 If the sequence is sorted, binary O(log(N)) search is used, otherwise, a simple linear search is used.
4294 If the element is not found, the function returns NULL pointer and the index is set to the number of
4295 sequence elements if the linear search is used, and to the smallest index <code>i, seq(i)&gt;elem</code>.
4296 </p>
4297
4298
4299 <hr><h3><a name="decl_cvStartAppendToSeq">StartAppendToSeq</a></h3>
4300 <p class="Blurb">Initializes process of writing data to sequence</p>
4301 <pre>
4302 void cvStartAppendToSeq( CvSeq* seq, CvSeqWriter* writer );
4303 </pre><p><dl>
4304 <dt>seq<dd>Pointer to the sequence.
4305 <dt>writer<dd>Writer state; initialized by the function.
4306 </dl><p>
4307 The function <code>cvStartAppendToSeq</code> initializes the process of writing data to the sequence.
4308 Written elements are added to the end of the sequence by <code>CV_WRITE_SEQ_ELEM( written_elem, writer )</code> macro.
4309 Note that during the writing process other operations on the sequence may yield incorrect result or
4310 even corrupt the sequence (see description of <a href="#decl_cvFlushSeqWriter">cvFlushSeqWriter</a> that helps to avoid
4311 some of these problems).</p>
4312
4313
4314 <hr><h3><a name="decl_cvStartWriteSeq">StartWriteSeq</a></h3>
4315 <p class="Blurb">Creates new sequence and initializes writer for it</p>
4316 <pre>
4317 void cvStartWriteSeq( int seq_flags, int header_size, int elem_size,
4318                       CvMemStorage* storage, CvSeqWriter* writer );
4319 </pre><p><dl>
4320 <dt>seq_flags<dd>Flags of the created sequence. If the sequence is not passed to any
4321 function working with a specific type of sequences, the sequence value may be
4322 equal to 0, otherwise the appropriate type must be selected from the list of
4323 predefined sequence types.
4324 <dt>header_size<dd>Size of the sequence header. The parameter value may not be less than
4325 <code>sizeof(CvSeq)</code>. If a certain type or extension is specified, it must fit the
4326 base type header.
4327 <dt>elem_size<dd>Size of the sequence elements in bytes; must be consistent with the
4328 sequence type. For example, if the sequence of points is created (element type
4329 <code>CV_SEQ_ELTYPE_POINT</code> ), then the parameter elem_size must be equal to
4330 <code>sizeof(CvPoint)</code>.
4331 <dt>storage<dd>Sequence location.
4332 <dt>writer<dd>Writer state; initialized by the function.
4333 </dl><p>
4334 The function <code>cvStartWriteSeq</code> is a composition of <a href="#decl_cvCreateSeq">cvCreateSeq</a> and <a href="#decl_cvStartAppendToSeq">cvStartAppendToSeq</a>.
4335 The pointer to the created sequence is stored at <code>writer->seq</code> and is also returned
4336 by <a href="#decl_cvEndWriteSeq">cvEndWriteSeq</a> function that should be called in the end.</p>
4337
4338
4339 <hr><h3><a name="decl_cvEndWriteSeq">EndWriteSeq</a></h3>
4340 <p class="Blurb">Finishes process of writing sequence</p>
4341 <pre>
4342 CvSeq* cvEndWriteSeq( CvSeqWriter* writer );
4343 </pre><p><dl>
4344 <dt>writer<dd>Writer state
4345 </dl><p>
4346 The function <code>cvEndWriteSeq</code> finishes the writing process and returns the pointer to
4347 the written sequence. The function also truncates the last incomplete sequence block to
4348 return the remaining part of the block to the memory storage. After that the sequence
4349 can be read and modified safely.</p>
4350
4351
4352 <hr><h3><a name="decl_cvFlushSeqWriter">FlushSeqWriter</a></h3>
4353 <p class="Blurb">Updates sequence headers from the writer state</p>
4354 <pre>
4355 void cvFlushSeqWriter( CvSeqWriter* writer );
4356 </pre><p><dl>
4357 <dt>writer<dd>Writer state
4358 </dl><p>
4359 The function <code>cvFlushSeqWriter</code> is intended to enable the user to read sequence
4360 elements, whenever required, during the writing process, e.g., in order to check
4361 specific conditions. The function updates the sequence headers to make reading
4362 from the sequence possible. The writer is not closed, however, so that the
4363 writing process can be continued any time. If some algorithm requires often flushes,
4364 consider using <a href="#decl_cvSeqPush">cvSeqPush</a> instead.</p>
4365
4366
4367 <hr><h3><a name="decl_cvStartReadSeq">StartReadSeq</a></h3>
4368 <p class="Blurb">Initializes process of sequential reading from sequence</p>
4369 <pre>
4370 void cvStartReadSeq( const CvSeq* seq, CvSeqReader* reader, int reverse=0 );
4371 </pre><p><dl>
4372 <dt>seq<dd>Sequence.
4373 <dt>reader<dd>Reader state; initialized by the function.
4374 <dt>reverse<dd>Determines the direction of the sequence traversal. If <code>reverse</code> is 0,
4375 the reader is positioned at the first sequence element, otherwise it is positioned at the last
4376 element.
4377 </dl><p>
4378 The function <code>cvStartReadSeq</code> initializes the reader state. After that all the
4379 sequence elements from the first down to the last one can be read by subsequent
4380 calls of the macro <code>CV_READ_SEQ_ELEM( read_elem, reader )</code> in case of forward reading
4381 and by using <code>CV_REV_READ_SEQ_ELEM( read_elem, reader )</code> in case of reversed reading.
4382 Both macros put the sequence element to <code>read_elem</code> and move the
4383 reading pointer toward the next element.
4384 A circular structure of sequence blocks is used for the reading process, that
4385 is, after the last element has been read by the macro <code>CV_READ_SEQ_ELEM</code>, the
4386 first element is read when the macro is called again. The same applies to
4387 <code>CV_REV_READ_SEQ_ELEM </code>. There is no function to finish the reading process,
4388 since it neither changes the sequence nor creates any temporary buffers. The reader
4389 field <code>ptr</code> points to the current element of the sequence that is to be read
4390 next. The code below demonstrates how to use sequence writer and reader.</p>
4391 <pre>
4392 CvMemStorage* storage = cvCreateMemStorage(0);
4393 CvSeq* seq = cvCreateSeq( CV_32SC1, sizeof(CvSeq), sizeof(int), storage );
4394 CvSeqWriter writer;
4395 CvSeqReader reader;
4396 int i;
4397
4398 cvStartAppendToSeq( seq, &writer );
4399 for( i = 0; i &lt; 10; i++ )
4400 {
4401     int val = rand()%100;
4402     CV_WRITE_SEQ_ELEM( val, writer );
4403     printf("%d is written\n", val );
4404 }
4405 cvEndWriteSeq( &writer );
4406
4407 cvStartReadSeq( seq, &reader, 0 );
4408 for( i = 0; i &lt; seq->total; i++ )
4409 {
4410     int val;
4411 #if 1
4412     CV_READ_SEQ_ELEM( val, reader );
4413     printf("%d is read\n", val );
4414 #else /* alternative way, that is preferable if sequence elements are large,
4415          or their size/type is unknown at compile time */
4416     printf("%d is read\n", *(int*)reader.ptr );
4417     CV_NEXT_SEQ_ELEM( seq->elem_size, reader );
4418 #endif
4419 }
4420 ...
4421
4422 cvReleaseStorage( &storage );
4423 </pre>
4424
4425
4426 <hr><h3><a name="decl_cvGetSeqReaderPos">GetSeqReaderPos</a></h3>
4427 <p class="Blurb">Returns the current reader position</p>
4428 <pre>
4429 int cvGetSeqReaderPos( CvSeqReader* reader );
4430 </pre><p><dl>
4431 <dt>reader<dd>Reader state.
4432 </dl><p>
4433 The function <code>cvGetSeqReaderPos</code> returns the current reader position
4434 (within 0 ... <code>reader->seq->total</code> - 1).</p>
4435
4436
4437 <hr><h3><a name="decl_cvSetSeqReaderPos">SetSeqReaderPos</a></h3>
4438 <p class="Blurb">Moves the reader to specified position</p>
4439 <pre>
4440 void cvSetSeqReaderPos( CvSeqReader* reader, int index, int is_relative=0 );
4441 </pre><p><dl>
4442
4443 <dt>reader<dd>Reader state.
4444 <dt>index<dd>The destination position. If the positioning mode is used (see the next parameter)
4445              the actual position will be <code>index</code> mod <code>reader->seq->total</code>.
4446 <dt>is_relative<dd>If it is not zero, then <code>index</code> is a relative to the current position.
4447 </dl><p>
4448 The function <code>cvSetSeqReaderPos</code> moves the read position to the absolute position or
4449 relative to the current position.
4450 </p>
4451
4452
4453 <hr><h2><a name="cxcore_ds_sets">Sets</a></h2>
4454
4455 <hr><h3><a name="decl_CvSet">CvSet</a></h3>
4456 <p class="Blurb">Collection of nodes</p>
4457 <pre>
4458     typedef struct CvSetElem
4459     {
4460         int flags; /* it is negative if the node is free and zero or positive otherwise */
4461         struct CvSetElem* next_free; /* if the node is free, the field is a
4462                                         pointer to next free node */
4463     }
4464     CvSetElem;
4465
4466     #define CV_SET_FIELDS()    \
4467         CV_SEQUENCE_FIELDS()   /* inherits from <a href="#decl_CvSeq">CvSeq</a> */ \
4468         struct CvSetElem* free_elems; /* list of free nodes */
4469
4470     typedef struct CvSet
4471     {
4472         CV_SET_FIELDS()
4473     } CvSet;
4474 </pre>
4475 <p>
4476 The structure <a href="#decl_CvSet">CvSet</a> is a base for OpenCV sparse data structures.</p>
4477 <p>As follows from the above declaration <a href="#decl_CvSet">CvSet</a> inherits from <a href="#decl_CvSeq">CvSeq</a>
4478 and it adds <code>free_elems</code> field it to, which is a list of free nodes.
4479 Every set node, whether free or not, is the element of the underlying sequence.
4480 While there is no restrictions on elements of dense sequences, the set (and derived structures)
4481 elements must start with integer field and be able to fit CvSetElem structure, because
4482 these two fields (integer followed by the pointer) are required for organization of node set with
4483 the list of free nodes. If a node is free, <code>flags</code> field is negative (the most-significant
4484 bit, or MSB, of the field is set), and <code>next_free</code>
4485 points to the next free node (the first free node is referenced by <code>free_elems</code> field of
4486 <a href="#decl_CvSet">CvSet</a>). And if a node is occupied, <code>flags</code> field is positive and contains the node index
4487 that may be retrieved using (set_elem->flags & CV_SET_ELEM_IDX_MASK) expression,
4488 the rest of the node content is determined by the user. In particular, the occupied nodes
4489 are not linked as the free nodes are, so the second field can be used for such a link as well as
4490 for some different purpose. The macro <code>CV_IS_SET_ELEM(set_elem_ptr)</code>
4491 can be used to determined whether the specified node is occupied or not.</p>
4492 <p>
4493 Initially the set and the list are empty. When a new node is requested from the set,
4494 it is taken from the list of free nodes, which is updated then. If the list appears to be empty,
4495 a new sequence block is allocated and all the nodes within the block are joined in the list of free
4496 nodes. Thus, <code>total</code> field of the set is the total number of nodes both occupied and free.
4497 When an occupied node is released, it is added to the list of free nodes. The node released last
4498 will be occupied first.</p>
4499 <p>In OpenCV <a href="#decl_CvSet">CvSet</a> is used for representing graphs (<a href="#decl_CvGraph">CvGraph</a>),
4500 sparse multi-dimensional arrays (<a href="#decl_CvSparseMat">CvSparseMat</a>), planar subdivisions (<a href="#decl_CvSubdiv2D">CvSubdiv2D</a>) etc.</p>
4501
4502
4503 <hr><h3><a name="decl_cvCreateSet">CreateSet</a></h3>
4504 <p class="Blurb">Creates empty set</p>
4505 <pre>
4506 CvSet* cvCreateSet( int set_flags, int header_size,
4507                     int elem_size, CvMemStorage* storage );
4508 </pre><p><dl>
4509 <dt>set_flags<dd>Type of the created set.
4510 <dt>header_size<dd>Set header size; may not be less than <code>sizeof(CvSet)</code>.
4511 <dt>elem_size<dd>Set element size; may not be less than <a href="#decl_CvSetElem">CvSetElem</a>.
4512 <dt>storage<dd>Container for the set.
4513 </dl><p>
4514 The function <code>cvCreateSet</code> creates an empty set with a specified header size and element size, and
4515 returns the pointer to the set. The function is just a thin layer on top of <a href="#decl_cvCreateSeq">cvCreateSeq</a>.</p>
4516
4517
4518 <hr><h3><a name="decl_cvSetAdd">SetAdd</a></h3>
4519 <p class="Blurb">Occupies a node in the set</p>
4520 <pre>
4521 int cvSetAdd( CvSet* set_header, CvSetElem* elem=NULL, CvSetElem** inserted_elem=NULL );
4522 </pre><p><dl>
4523 <dt>set_header<dd>Set.
4524 <dt>elem<dd>Optional input argument, inserted element. If not NULL, the function
4525 copies the data to the allocated node (The MSB of the first integer field is cleared after copying).
4526 <dt>inserted_elem<dd>Optional output argument; the pointer to the allocated cell.
4527 </dl><p>
4528 The function <code>cvSetAdd</code> allocates a new node, optionally copies input element data
4529 to it, and returns the pointer and the index to the node. The index value is
4530 taken from the lower bits of <code>flags</code> field of the node. The function has O(1) complexity,
4531 however there exists a faster function for allocating set nodes (see <a href="#decl_cvSetNew">cvSetNew</a>).
4532 </p>
4533
4534
4535 <hr><h3><a name="decl_cvSetRemove">SetRemove</a></h3>
4536 <p class="Blurb">Removes element from set</p>
4537 <pre>
4538 void cvSetRemove( CvSet* set_header, int index );
4539 </pre><p><dl>
4540 <dt>set_header<dd>Set.
4541 <dt>index<dd>Index of the removed element.
4542 </dl><p>
4543 The function <code>cvSetRemove</code> removes an element with a specified index from the set.
4544 If the node at the specified location is not occupied the function does nothing.
4545 The function has O(1) complexity, however, <a href="#decl_cvSetRemoveByPtr">cvSetRemoveByPtr</a> provides yet
4546 faster way to remove a set element if it is located already.</p>
4547
4548
4549 <hr><h3><a name="decl_cvSetNew">SetNew</a></h3>
4550 <p class="Blurb">Adds element to set (fast variant)</p>
4551 <pre>
4552 CvSetElem* cvSetNew( CvSet* set_header );
4553 </pre><p><dl>
4554 <dt>set_header<dd>Set.
4555 </dl><p>
4556 The function <code>cvSetNew</code> is inline light-weight variant of <a href="#decl_cvSetAdd">cvSetAdd</a>.
4557 It occupies a new node and returns pointer to it rather than index.</p>
4558
4559
4560 <hr><h3><a name="decl_cvSetRemoveByPtr">SetRemoveByPtr</a></h3>
4561 <p class="Blurb">Removes set element given its pointer</p>
4562 <pre>
4563 void cvSetRemoveByPtr( CvSet* set_header, void* elem );
4564 </pre><p><dl>
4565 <dt>set_header<dd>Set.
4566 <dt>elem<dd>Removed element.
4567 </dl><p>
4568 The function <code>cvSetRemoveByPtr</code> is inline light-weight variant of <a href="#decl_cvSetRemove">cvSetRemove</a>
4569 that takes element pointer.
4570 The function does not check whether the node is occupied or not - the user should take care of it.</p>
4571
4572
4573 <hr><h3><a name="decl_cvGetSetElem">GetSetElem</a></h3>
4574 <p class="Blurb">Finds set element by its index</p>
4575 <pre>
4576 CvSetElem* cvGetSetElem( const CvSet* set_header, int index );
4577 </pre><p><dl>
4578 <dt>set_header<dd>Set.
4579 <dt>index<dd>Index of the set element within a sequence.
4580 </dl><p>
4581 The function <code>cvGetSetElem</code> finds a set element by index. The function returns the
4582 pointer to it or 0 if the index is invalid or the corresponding node is free.
4583 The function supports negative indices as it uses <a href="#decl_cvGetSeqElem">cvGetSeqElem</a> to locate the node.</p>
4584 </p>
4585
4586
4587 <hr><h3><a name="decl_cvClearSet">ClearSet</a></h3>
4588 <p class="Blurb">Clears set</p>
4589 <pre>
4590 void cvClearSet( CvSet* set_header );
4591 </pre><p><dl>
4592 <dt>set_header<dd>Cleared set.
4593 </dl><p>
4594 The function <code>cvClearSet</code> removes all elements from set. It has O(1) time complexity.</p>
4595
4596
4597 <hr><h2><a name="cxcore_ds_graphs">Graphs</a></h2>
4598
4599 <hr><h3><a name="decl_CvGraph">CvGraph</a></h3>
4600 <p class="Blurb">Oriented or undirected weighted graph</p>
4601 <pre>
4602     #define CV_GRAPH_VERTEX_FIELDS()    \
4603         int flags; /* vertex flags */   \
4604         struct CvGraphEdge* first; /* the first incident edge */
4605
4606     typedef struct CvGraphVtx
4607     {
4608         CV_GRAPH_VERTEX_FIELDS()
4609     }
4610     CvGraphVtx;
4611
4612     #define CV_GRAPH_EDGE_FIELDS()      \
4613         int flags; /* edge flags */     \
4614         float weight; /* edge weight */ \
4615         struct CvGraphEdge* next[2]; /* the next edges in the incidence lists for staring (0) */ \
4616                                      /* and ending (1) vertices */ \
4617         struct CvGraphVtx* vtx[2]; /* the starting (0) and ending (1) vertices */
4618
4619     typedef struct CvGraphEdge
4620     {
4621         CV_GRAPH_EDGE_FIELDS()
4622     }
4623     CvGraphEdge;
4624
4625     #define  CV_GRAPH_FIELDS()                  \
4626         CV_SET_FIELDS() /* set of vertices */   \
4627         CvSet* edges;   /* set of edges */
4628
4629     typedef struct CvGraph
4630     {
4631         CV_GRAPH_FIELDS()
4632     }
4633     CvGraph;
4634
4635 </pre>
4636 <p>
4637 The structure <a href="#decl_CvGraph">CvGraph</a> is a base for graphs used in OpenCV.</p>
4638 <p>Graph structure inherits from <a href="#decl_CvSet">CvSet</a> - this part describes common graph properties and
4639 the graph vertices, and contains another set as a member - this part describes the graph edges.</p>
4640 <p>The vertex, edge and the graph header structures are declared using the same technique as other
4641 extendible OpenCV structures - via macros, that simplifies extension and customization of the structures.
4642 While the vertex and edge structures do not inherit from <a href="#decl_CvSetElem">CvSetElem</a> explicitly, they satisfy
4643 both conditions on the set elements - have an integer field in the beginning and fit CvSetElem structure.
4644 The <code>flags</code> fields are used as for indicating occupied vertices and edges as well as
4645 for other purposes, for example, for graph traversal (see <a href="#decl_cvCreateGraphScanner">cvCreateGraphScanner</a> et al.), so
4646 it is better not to use them directly.</p>
4647 <p>The graph is represented as a set of edges each of whose has the list of incident edges. The incidence
4648 lists for different vertices are interleaved to avoid information duplication as much as possible.</p>
4649 <p>The graph may be oriented or undirected. In the latter case there is no distinction between edge
4650 connecting vertex A with vertex B and the edge connecting vertex B with vertex A - only one of them
4651 can exist in the graph at the same moment and it represents both &lt;A, B&gt; and &lt;B, A&gt; edges..</p>
4652
4653
4654
4655 <hr><h3><a name="decl_cvCreateGraph">CreateGraph</a></h3>
4656 <p class="Blurb">Creates empty graph</p>
4657 <pre>
4658 CvGraph* cvCreateGraph( int graph_flags, int header_size, int vtx_size,
4659                         int edge_size, CvMemStorage* storage );
4660 </pre><p><dl>
4661 <dt>graph_flags<dd>Type of the created graph. Usually, it is either <code>CV_SEQ_KIND_GRAPH</code>
4662 for generic undirected graphs and <code>CV_SEQ_KIND_GRAPH | CV_GRAPH_FLAG_ORIENTED</code> for generic oriented graphs.
4663 <dt>header_size<dd>Graph header size; may not be less than <code>sizeof(CvGraph).</code>
4664 <dt>vtx_size<dd>Graph vertex size; the custom vertex structure must start with <a href="#decl_CvGraphVtx">CvGraphVtx</a>
4665                   (use <code>CV_GRAPH_VERTEX_FIELDS()</code>)
4666 <dt>edge_size<dd>Graph edge size; the custom edge structure must start with <a href="#decl_CvGraphEdge">CvGraphEdge</a>
4667                 (use <code>CV_GRAPH_EDGE_FIELDS()</code>)
4668 <dt>storage<dd>The graph container.
4669 </dl><p>
4670 The function <code>cvCreateGraph</code> creates an empty graph and returns pointer to it.</p>
4671
4672
4673 <hr><h3><a name="decl_cvGraphAddVtx">GraphAddVtx</a></h3>
4674 <p class="Blurb">Adds vertex to graph</p>
4675 <pre>
4676 int cvGraphAddVtx( CvGraph* graph, const CvGraphVtx* vtx=NULL,
4677                    CvGraphVtx** inserted_vtx=NULL );
4678 </pre><p><dl>
4679 <dt>graph<dd>Graph.
4680 <dt>vtx<dd>Optional input argument used to initialize the added vertex (only user-defined fields
4681 beyond <code>sizeof(CvGraphVtx)</code> are copied).
4682 <dt>inserted_vertex<dd>Optional output argument. If not <code>NULL</code>, the address of the new
4683 vertex is written there.
4684 </dl><p>
4685 The function <code>cvGraphAddVtx</code> adds a vertex to the graph and returns the vertex
4686 index.</p>
4687
4688
4689 <hr><h3><a name="decl_cvGraphRemoveVtx">GraphRemoveVtx</a></h3>
4690 <p class="Blurb">Removes vertex from graph</p>
4691 <pre>
4692 int cvGraphRemoveVtx( CvGraph* graph, int index );
4693 </pre><p><dl>
4694 <dt>graph<dd>Graph.
4695 <dt>vtx_idx<dd>Index of the removed vertex.
4696 </dl><p>
4697 The function <code>cvGraphRemoveAddVtx</code> removes a vertex from the graph together with all
4698 the edges incident to it. The function reports an error, if the input vertex does
4699 not belong to the graph. The return value is number of edges deleted,
4700 or -1 if the vertex does not belong to the graph.</p>
4701
4702
4703 <hr><h3><a name="decl_cvGraphRemoveVtxByPtr">GraphRemoveVtxByPtr</a></h3>
4704 <p class="Blurb">Removes vertex from graph</p>
4705 <pre>
4706 int cvGraphRemoveVtxByPtr( CvGraph* graph, CvGraphVtx* vtx );
4707 </pre><p><dl>
4708 <dt>graph<dd>Graph.
4709 <dt>vtx<dd>Pointer to the removed vertex.
4710 </dl><p>
4711 The function <code>cvGraphRemoveVtxByPtr</code> removes a vertex from the graph together with
4712 all the edges incident to it. The function reports an error, if the vertex does not belong to the graph.
4713 The return value is number of edges deleted, or -1 if the vertex does not belong to the graph.</p>
4714
4715
4716 <hr><h3><a name="decl_cvGetGraphVtx">GetGraphVtx</a></h3>
4717 <p class="Blurb">Finds graph vertex by index</p>
4718 <pre>
4719 CvGraphVtx* cvGetGraphVtx( CvGraph* graph, int vtx_idx );
4720 </pre><p><dl>
4721 <dt>graph<dd>Graph.
4722 <dt>vtx_idx<dd>Index of the vertex.
4723 </dl><p>
4724 The function <code>cvGetGraphVtx</code> finds the graph vertex by index and returns the pointer
4725 to it or NULL if the vertex does not belong to the graph.</p>
4726
4727
4728 <hr><h3><a name="decl_cvGraphVtxIdx">GraphVtxIdx</a></h3>
4729 <p class="Blurb">Returns index of graph vertex</p>
4730 <pre>
4731 int cvGraphVtxIdx( CvGraph* graph, CvGraphVtx* vtx );
4732 </pre><p><dl>
4733 <dt>graph<dd>Graph.
4734 <dt>vtx<dd>Pointer to the graph vertex.
4735 </dl><p>
4736 The function <code>cvGraphVtxIdx</code> returns index of the graph vertex.</p>
4737
4738
4739 <hr><h3><a name="decl_cvGraphAddEdge">GraphAddEdge</a></h3>
4740 <p class="Blurb">Adds edge to graph</p>
4741 <pre>
4742 int cvGraphAddEdge( CvGraph* graph, int start_idx, int end_idx,
4743                     const CvGraphEdge* edge=NULL, CvGraphEdge** inserted_edge=NULL );
4744 </pre><p><dl>
4745 <dt>graph<dd>Graph.
4746 <dt>start_idx<dd>Index of the starting vertex of the edge.
4747 <dt>end_idx<dd>Index of the ending vertex of the edge. For undirected graph the order of the vertex
4748 parameters does not matter.
4749 <dt>edge<dd>Optional input parameter, initialization data for the edge.
4750 <dt>inserted_edge<dd>Optional output parameter to contain the address of the inserted
4751 edge.
4752 </dl><p>
4753 The function <code>cvGraphAddEdge</code> connects two specified vertices.
4754 The function returns 1 if the edge has been added successfully, 0 if the edge connecting
4755 the two vertices exists already and -1 if either of the vertices was not found, the starting and
4756 the ending vertex are the same or there is some other critical situation. In the latter case
4757 (i.e. when the result is negative) the function also reports an error by default.</p>
4758
4759
4760 <hr><h3><a name="decl_cvGraphAddEdgeByPtr">GraphAddEdgeByPtr</a></h3>
4761 <p class="Blurb">Adds edge to graph</p>
4762 <pre>
4763 int cvGraphAddEdgeByPtr( CvGraph* graph, CvGraphVtx* start_vtx, CvGraphVtx* end_vtx,
4764                          const CvGraphEdge* edge=NULL, CvGraphEdge** inserted_edge=NULL );
4765 </pre><p><dl>
4766 <dt>graph<dd>Graph.
4767 <dt>start_vtx<dd>Pointer to the starting vertex of the edge.
4768 <dt>end_vtx<dd>Pointer to the ending vertex of the edge. For undirected graph the order of the vertex
4769 parameters does not matter.
4770 <dt>edge<dd>Optional input parameter, initialization data for the edge.
4771 <dt>inserted_edge<dd>Optional output parameter to contain the address of the inserted
4772 edge within the edge set.
4773 </dl><p>
4774 The function <code>cvGraphAddEdge</code> connects two specified vertices.
4775 The function returns 1 if the edge has been added successfully, 0 if the edge connecting
4776 the two vertices exists already and -1 if either of the vertices was not found, the starting and
4777 the ending vertex are the same or there is some other critical situation. In the latter case
4778 (i.e. when the result is negative) the function also reports an error by default.</p>
4779
4780
4781 <hr><h3><a name="decl_cvGraphRemoveEdge">GraphRemoveEdge</a></h3>
4782 <p class="Blurb">Removes edge from graph</p>
4783 <pre>
4784 void cvGraphRemoveEdge( CvGraph* graph, int start_idx, int end_idx );
4785 </pre><p><dl>
4786 <dt>graph<dd>Graph.
4787 <dt>start_idx<dd>Index of the starting vertex of the edge.
4788 <dt>end_idx<dd>Index of the ending vertex of the edge. For undirected graph the order of the vertex
4789 parameters does not matter.
4790 </dl><p>
4791 The function <code>cvGraphRemoveEdge</code> removes the edge connecting two specified vertices.
4792 If the vertices are not connected [in that order], the function does nothing.
4793 </p>
4794
4795
4796 <hr><h3><a name="decl_cvGraphRemoveEdgeByPtr">GraphRemoveEdgeByPtr</a></h3>
4797 <p class="Blurb">Removes edge from graph</p>
4798 <pre>
4799 void cvGraphRemoveEdgeByPtr( CvGraph* graph, CvGraphVtx* start_vtx, CvGraphVtx* end_vtx );
4800 </pre><p><dl>
4801 <dt>graph<dd>Graph.
4802 <dt>start_vtx<dd>Pointer to the starting vertex of the edge.
4803 <dt>end_vtx<dd>Pointer to the ending vertex of the edge. For undirected graph the order of the vertex
4804 parameters does not matter.
4805 </dl><p>
4806 The function <code>cvGraphRemoveEdgeByPtr</code> removes the edge connecting two specified vertices.
4807 If the vertices are not connected [in that order], the function does nothing.</p>
4808
4809
4810 <hr><h3><a name="decl_cvFindGraphEdge">FindGraphEdge</a></h3>
4811 <p class="Blurb">Finds edge in graph</p>
4812 <pre>
4813 CvGraphEdge* cvFindGraphEdge( const CvGraph* graph, int start_idx, int end_idx );
4814 #define cvGraphFindEdge cvFindGraphEdge
4815 </pre><p><dl>
4816 <dt>graph<dd>Graph.
4817 <dt>start_idx<dd>Index of the starting vertex of the edge.
4818 <dt>end_idx<dd>Index of the ending vertex of the edge. For undirected graph the order of the vertex
4819 parameters does not matter.
4820 </dl><p>
4821 The function <code>cvFindGraphEdge</code> finds the graph edge connecting two specified vertices
4822 and returns pointer to it or NULL if the edge does not exists.</p>
4823
4824
4825 <hr><h3><a name="decl_cvFindGraphEdgeByPtr">FindGraphEdgeByPtr</a></h3>
4826 <p class="Blurb">Finds edge in graph</p>
4827 <pre>
4828 CvGraphEdge* cvFindGraphEdgeByPtr( const CvGraph* graph, const CvGraphVtx* start_vtx,
4829                                    const CvGraphVtx* end_vtx );
4830 #define cvGraphFindEdgeByPtr cvFindGraphEdgeByPtr
4831 </pre><p><dl>
4832 <dt>graph<dd>Graph.
4833 <dt>start_vtx<dd>Pointer to the starting vertex of the edge.
4834 <dt>end_vtx<dd>Pointer to the ending vertex of the edge. For undirected graph the order of the vertex
4835 parameters does not matter.
4836 </dl><p>
4837 The function <code>cvFindGraphEdge</code> finds the graph edge connecting two specified vertices
4838 and returns pointer to it or NULL if the edge does not exists.</p>
4839
4840
4841 <hr><h3><a name="decl_cvGraphEdgeIdx">GraphEdgeIdx</a></h3>
4842 <p class="Blurb">Returns index of graph edge</p>
4843 <pre>
4844 int cvGraphEdgeIdx( CvGraph* graph, CvGraphEdge* edge );
4845 </pre><p><dl>
4846 <dt>graph<dd>Graph.
4847 <dt>edge<dd>Pointer to the graph edge.
4848 </dl><p>
4849 The function <code>cvGraphEdgeIdx</code> returns index of the graph edge.</p>
4850
4851
4852 <hr><h3><a name="decl_cvGraphVtxDegree">GraphVtxDegree</a></h3>
4853 <p class="Blurb">Counts edges incident to the vertex</p>
4854 <pre>
4855 int cvGraphVtxDegree( const CvGraph* graph, int vtx_idx );
4856 </pre><p><dl>
4857 <dt>graph<dd>Graph.
4858 <dt>vtx<dd>Index of the graph vertex.
4859 </dl><p>
4860 The function <code>cvGraphVtxDegree</code> returns the number of edges
4861 incident to the specified vertex, both incoming and outgoing.
4862 To count the edges, the following code is used:</p>
4863 <pre>
4864     CvGraphEdge* edge = vertex->first; int count = 0;
4865     while( edge )
4866     {
4867         edge = CV_NEXT_GRAPH_EDGE( edge, vertex );
4868         count++;
4869     }
4870 </pre>
4871 <p>The macro <code>CV_NEXT_GRAPH_EDGE( edge, vertex )</code> returns the edge incident to <code>vertex</code>
4872 that follows after <code>edge</code>.</p>
4873
4874
4875 <hr><h3><a name="decl_cvGraphVtxDegreeByPtr">GraphVtxDegreeByPtr</a></h3>
4876 <p class="Blurb">Finds edge in graph</p>
4877 <pre>
4878 int cvGraphVtxDegreeByPtr( const CvGraph* graph, const CvGraphVtx* vtx );
4879 </pre><p><dl>
4880 <dt>graph<dd>Graph.
4881 <dt>vtx<dd>Pointer to the graph vertex.
4882 </dl><p>
4883 The function <code>cvGraphVtxDegree</code> returns the number of edges
4884 incident to the specified vertex, both incoming and outgoing.</p>
4885
4886
4887 <hr><h3><a name="decl_cvClearGraph">ClearGraph</a></h3>
4888 <p class="Blurb">Clears graph</p>
4889 <pre>
4890 void cvClearGraph( CvGraph* graph );
4891 </pre><p><dl>
4892 <dt>graph<dd>Graph.
4893 </dl><p>
4894 The function <code>cvClearGraph</code> removes all vertices and edges from the graph.
4895 The function has O(1) time complexity.</p>
4896
4897
4898 <hr><h3><a name="decl_cvCloneGraph">CloneGraph</a></h3>
4899 <p class="Blurb">Clone graph</p>
4900 <pre>
4901 CvGraph* cvCloneGraph( const CvGraph* graph, CvMemStorage* storage );
4902 </pre><p><dl>
4903 <dt>graph<dd>The graph to copy.
4904 <dt>storage<dd>Container for the copy.
4905 </dl><p>
4906 The function <code>cvCloneGraph</code> creates full copy of the graph. If the graph vertices
4907 or edges have pointers to some external data, it still be shared between the copies.
4908 The vertex and edge indices in the new graph may be different from the original, because
4909 the function defragments the vertex and edge sets.</p>
4910
4911
4912 <hr><h3><a name="decl_CvGraphScanner">CvGraphScanner</a></h3>
4913 <p class="Blurb">Graph traversal state</p>
4914 <pre>
4915     typedef struct CvGraphScanner
4916     {
4917         CvGraphVtx* vtx;       /* current graph vertex (or current edge origin) */
4918         CvGraphVtx* dst;       /* current graph edge destination vertex */
4919         CvGraphEdge* edge;     /* current edge */
4920
4921         CvGraph* graph;        /* the graph */
4922         CvSeq*   stack;        /* the graph vertex stack */
4923         int      index;        /* the lower bound of certainly visited vertices */
4924         int      mask;         /* event mask */
4925     }
4926     CvGraphScanner;
4927 </pre>
4928 <p>The structure <a href="#decl_CvGraphScanner">CvGraphScanner</a> is used for depth-first graph traversal.
4929 See discussion of the functions below.</p>
4930
4931
4932 <hr><h3><a name="decl_cvCreateGraphScanner">CreateGraphScanner</a></h3>
4933 <p class="Blurb">Creates structure for depth-first graph traversal</p>
4934 <pre>
4935 CvGraphScanner*  cvCreateGraphScanner( CvGraph* graph, CvGraphVtx* vtx=NULL,
4936                                        int mask=CV_GRAPH_ALL_ITEMS );
4937 </pre><p><dl>
4938 <dt>graph<dd>Graph.
4939 <dt>vtx<dd>Initial vertex to start from. If NULL, the traversal starts from the first vertex (a vertex with the
4940            minimal index in the sequence of vertices).
4941 <dt>mask<dd>Event mask indicating which events are interesting to the user (where <a href="#decl_cvNextGraphItem">cvNextGraphItem</a>
4942             function returns control to the user)
4943             It can be <code>CV_GRAPH_ALL_ITEMS</code> (all events are interesting)
4944             or combination of the following flags:<ul>
4945             <li>CV_GRAPH_VERTEX - stop at the graph vertices visited for the first time<br>
4946             <li>CV_GRAPH_TREE_EDGE - stop at tree edges (<code>tree edge</code> is the edge connecting the last visited vertex and
4947                                  the vertex to be visited next)<br>
4948             <li>CV_GRAPH_BACK_EDGE - stop at back edges (<code>back edge</code> is an edge connecting
4949                                  the last visited vertex with some of its ancestors in the search tree)<br>
4950             <li>CV_GRAPH_FORWARD_EDGE - stop at forward edges (<code>forward edge</code> is an edge connecting
4951                                  the last visited vertex with some of its descendants in the search tree).
4952                                  The <code>forward edges</code> are only possible during oriented graph traversal)<br>
4953             <li>CV_GRAPH_CROSS_EDGE - stop at cross edges (<code>cross edge</code> is an edge connecting different search trees or
4954                                  branches of the same tree.
4955                                  The <code>cross edges</code> are only possible during oriented graphs traversal)<br>
4956             <li>CV_GRAPH_ANY_EDGE - stop and any edge (<code>tree, back, forward</code> and <code>cross edges</code>)<br>
4957             <li>CV_GRAPH_NEW_TREE - stop in the beginning of every new search tree. When the traversal procedure
4958                                 visits all vertices and edges reachable from the initial vertex (the visited vertices
4959                                 together with tree edges make up a tree), it searches for some unvisited vertex
4960                                 in the graph and resumes the traversal process from that vertex.
4961                                 Before starting a new tree (including the very first tree
4962                                 when <code>cvNextGraphItem</code> is called for the first time)
4963                                 it generates <code>CV_GRAPH_NEW_TREE</code> event.<br>
4964                                 For undirected graphs each search tree corresponds to a connected component of the graph.<br>
4965             <li>CV_GRAPH_BACKTRACKING - stop at every already visited vertex during backtracking - returning to
4966                                 already visited vertexes of the traversal tree.<br></ul>
4967 </dl><p>
4968 The function <code>cvCreateGraphScanner</code> creates structure for
4969 depth-first graph traversal/search.
4970 The initialized structure is used in <a href="#decl_cvNextGraphItem">cvNextGraphItem</a> function
4971 - the incremental traversal procedure.</p>
4972
4973
4974 <hr><h3><a name="decl_cvNextGraphItem">NextGraphItem</a></h3>
4975 <p class="Blurb">Makes one or more steps of the graph traversal procedure</p>
4976 <pre>
4977 int cvNextGraphItem( CvGraphScanner* scanner );
4978 </pre><p><dl>
4979 <dt>scanner<dd>Graph traversal state. It is updated by the function.
4980 </dl><p>
4981 The function <code>cvNextGraphItem</code> traverses through the graph until an event interesting to the user
4982 (that is, an event, specified in the <code>mask</code> in <a href="#decl_cvCreateGraphScanner">cvCreateGraphScanner</a> call)
4983 is met or the traversal is over. In the first case it returns one of the events,
4984 listed in the description of <code>mask</code> parameter above and with the next call
4985 it resumes the traversal. In the latter case it returns CV_GRAPH_OVER (-1).
4986 When the event is <code>CV_GRAPH_VERTEX</code>, or <code>CV_GRAPH_BACKTRACKING</code> or <code>CV_GRAPH_NEW_TREE</code>,
4987 the currently observed vertex is stored in <code>scanner->vtx</code>. And if the event is edge-related,
4988 the edge itself is stored at <code>scanner->edge</code>,
4989 the previously visited vertex - at <code>scanner->vtx</code> and the other ending vertex of the edge -
4990 at <code>scanner->dst</code>.</p>
4991
4992
4993 <hr><h3><a name="decl_cvReleaseGraphScanner">ReleaseGraphScanner</a></h3>
4994 <p class="Blurb">Finishes graph traversal procedure</p>
4995 <pre>
4996 void cvReleaseGraphScanner( CvGraphScanner** scanner );
4997 </pre><p><dl>
4998 <dt>scanner<dd>Double pointer to graph traverser.
4999 </dl><p>
5000 The function <code>cvGraphScanner</code> finishes graph traversal procedure
5001 and releases the traverser state.</p>
5002
5003
5004 <hr><h2><a name="cxcore_ds_trees">Trees</a></h2>
5005
5006
5007 <hr><h3><a name="decl_CV_TREE_NODE_FIELDS">CV_TREE_NODE_FIELDS</a></h3>
5008 <p class="Blurb">Helper macro for a tree node type declaration</p>
5009 <pre>
5010 #define CV_TREE_NODE_FIELDS(node_type)                          \
5011     int       flags;         /* miscellaneous flags */          \
5012     int       header_size;   /* size of sequence header */      \
5013     struct    node_type* h_prev; /* previous sequence */        \
5014     struct    node_type* h_next; /* next sequence */            \
5015     struct    node_type* v_prev; /* 2nd previous sequence */    \
5016     struct    node_type* v_next; /* 2nd next sequence */
5017 </pre>
5018 <p>The macro <code>CV_TREE_NODE_FIELDS()</code> is used to declare structures
5019 that can be organized into hierarchical structures (trees), such as <a href="#decl_CvSeq">CvSeq</a> -
5020 the basic type for all dynamical structures.
5021 The trees made of nodes declared using this macro can be processed using
5022 the functions described below in this section.</p>
5023
5024
5025 <hr><h3><a name="decl_CvTreeNodeIterator">CvTreeNodeIterator</a></h3>
5026 <p class="Blurb">Opens existing or creates new file storage</p>
5027 <pre>
5028 typedef struct CvTreeNodeIterator
5029 {
5030     const void* node;
5031     int level;
5032     int max_level;
5033 }
5034 CvTreeNodeIterator;
5035 </pre>
5036 <p>The structure <a href="#decl_CvTreeNodeIterator">CvTreeNodeIterator</a> is used to traverse trees.
5037 The tree node declaration should start with <code>CV_TREE_NODE_FIELDS(...)</code> macro.</p>
5038
5039
5040 <hr><h3><a name="decl_cvInitTreeNodeIterator">InitTreeNodeIterator</a></h3>
5041 <p class="Blurb">Initializes tree node iterator</p>
5042 <pre>
5043 void cvInitTreeNodeIterator( CvTreeNodeIterator* tree_iterator,
5044                              const void* first, int max_level );
5045 </pre><p><dl>
5046 <dt>tree_iterator<dd>Tree iterator initialized by the function.
5047 <dt>first<dd>The initial node to start traversing from.
5048 <dt>max_level<dd>The maximal level of the tree (<code>first</code> node assumed to be at the first level) to
5049                 traverse up to. For example, 1 means that only nodes at the same level as <code>first</code>
5050                 should be visited, 2 means that the nodes on the same level as <code>first</code> and
5051                 their direct children should be visited etc.
5052 </dl><p>
5053 The function <code>cvInitTreeNodeIterator</code> initializes tree iterator.
5054 The tree is traversed in depth-first order.</p>
5055
5056
5057 <hr><h3><a name="decl_cvNextTreeNode">NextTreeNode</a></h3>
5058 <p class="Blurb">Returns the currently observed node and moves iterator toward the next node</p>
5059 <pre>
5060 void* cvNextTreeNode( CvTreeNodeIterator* tree_iterator );
5061 </pre><p><dl>
5062 <dt>tree_iterator<dd>Tree iterator initialized by the function.
5063 </dl><p>
5064 The function <code>cvNextTreeNode</code> returns the currently observed node and then
5065 updates the iterator - moves it toward the next node. In other words, the function behavior
5066 is similar to *p++ expression on usual C pointer or C++ collection iterator.
5067 The function returns NULL if there is no more nodes.</p>
5068
5069
5070 <hr><h3><a name="decl_cvPrevTreeNode">PrevTreeNode</a></h3>
5071 <p class="Blurb">Returns the currently observed node and moves iterator toward the previous node</p>
5072 <pre>
5073 void* cvPrevTreeNode( CvTreeNodeIterator* tree_iterator );
5074 </pre><p><dl>
5075 <dt>tree_iterator<dd>Tree iterator initialized by the function.
5076 </dl><p>
5077 The function <code>cvPrevTreeNode</code> returns the currently observed node and then
5078 updates the iterator - moves it toward the previous node. In other words, the function behavior
5079 is similar to *p-- expression on usual C pointer or C++ collection iterator.
5080 The function returns NULL if there is no more nodes.</p>
5081
5082
5083 <hr><h3><a name="decl_cvTreeToNodeSeq">TreeToNodeSeq</a></h3>
5084 <p class="Blurb">Gathers all node pointers to the single sequence</p>
5085 <pre>
5086 CvSeq* cvTreeToNodeSeq( const void* first, int header_size, CvMemStorage* storage );
5087 </pre><p><dl>
5088 <dt>first<dd>The initial tree node.
5089 <dt>header_size<dd>Header size of the created sequence (sizeof(CvSeq) is the most used value).
5090 <dt>storage<dd>Container for the sequence.
5091 </dl><p>
5092 The function <code>cvTreeToNodeSeq</code> puts pointers of all nodes reachable from <code>first</code>
5093 to the single sequence. The pointers are written subsequently in the depth-first order.</p>
5094
5095
5096 <hr><h3><a name="decl_cvInsertNodeIntoTree">InsertNodeIntoTree</a></h3>
5097 <p class="Blurb">Adds new node to the tree</p>
5098 <pre>
5099 void cvInsertNodeIntoTree( void* node, void* parent, void* frame );
5100 </pre><p><dl>
5101 <dt>node<dd>The inserted node.
5102 <dt>parent<dd>The parent node that is already in the tree.
5103 <dt>frame<dd>The top level node. If <code>parent</code> and <code>frame</code> are the same, <code>v_prev</code>
5104             field of <code>node</code> is set to NULL rather than <code>parent</code>.
5105 </dl><p>
5106 The function <code>cvInsertNodeIntoTree</code> adds another node into tree. The function does not
5107 allocate any memory, it can only modify links of the tree nodes.</p>
5108
5109
5110 <hr><h3><a name="decl_cvRemoveNodeFromTree">RemoveNodeFromTree</a></h3>
5111 <p class="Blurb">Removes node from tree</p>
5112 <pre>
5113 void cvRemoveNodeFromTree( void* node, void* frame );
5114 </pre><p><dl>
5115 <dt>node<dd>The removed node.
5116 <dt>frame<dd>The top level node. If <code>node->v_prev = NULL</code> and
5117             <code>node->h_prev</code> is NULL (i.e. if <code>node</code> is the first child of <code>frame</code>),
5118             <code>frame->v_next</code> is set to <code>node->h_next</code> (i.e. the first child or frame is changed).
5119 </dl><p>
5120 The function <code>cvRemoveNodeFromTree</code> removes node from tree. The function does not
5121 deallocate any memory, it can only modify links of the tree nodes.</p>
5122
5123
5124
5125 <hr><h1><a name="cxcore_drawing">Drawing Functions</a></h1>
5126
5127 <p>
5128 Drawing functions work with matrices/images or arbitrary depth.
5129 Antialiasing is implemented only for 8-bit images.
5130 All the functions include parameter color that means rgb value (that may be
5131 constructed with <code>CV_RGB</code> macro or <code>cvScalar</code> function)
5132 for color images and brightness for grayscale images.</p><p>
5133 If a drawn figure is partially or completely outside the image, it is clipped.
5134 For color images the order channel is: <font color=blue>B</font>lue <font color=green>G</font>reen <font color=red>R</font>ed ... 
5135 If one needs a different channel order, it is possible to construct color
5136 via <code>cvScalar</code> with the particular channel order, or
5137 convert the image before and/or after drawing in it with
5138 <a href="opencvref_cv.htm#decl_cvCvtColor">cvCvtColor</a> or
5139 <a href="#decl_cvTransform">cvTransform</a>.
5140 </p>
5141
5142
5143 <hr><h2><a name="cxcore_drawing_shapes">Curves and Shapes</a></h2>
5144
5145 <hr><h3><a name="decl_CV_RGB">CV_RGB</a></h3>
5146 <p class="Blurb">Constructs a color value</p>
5147 <pre>
5148 #define CV_RGB( r, g, b )  cvScalar( (b), (g), (r) )
5149 </pre>
5150
5151
5152 <hr><h3><a name="decl_cvLine">Line</a></h3>
5153 <p class="Blurb">Draws a line segment connecting two points</p>
5154 <pre>
5155 void cvLine( CvArr* img, CvPoint pt1, CvPoint pt2, CvScalar color,
5156              int thickness=1, int line_type=8, int shift=0 );
5157 </pre><p><dl>
5158 <dt>img<dd>The image.
5159 <dt>pt1<dd>First point of the line segment.
5160 <dt>pt2<dd>Second point of the line segment.
5161 <dt>color<dd>Line color.
5162 <dt>thickness<dd>Line thickness.
5163 <dt>line_type<dd>Type of the line:<br>
5164                  <code>8</code> (or <code>0</code>) - 8-connected line.<br>
5165                  <code>4</code> - 4-connected line.<br>
5166                  <code>CV_AA</code> - antialiased line.
5167 <dt>shift<dd>Number of fractional bits in the point coordinates.
5168 </dl><p>
5169 The function <code>cvLine</code> draws the line segment between <code>pt1</code> and <code>pt2</code> points
5170 in the image. The line is clipped by the image or ROI rectangle. For non-antialiased lines
5171 with integer coordinates the 8-connected or 4-connected Bresenham algorithm is used.
5172 Thick lines are drawn with rounding endings. Antialiased lines are drawn using Gaussian filtering.
5173 To specify the line color, the user may use the macro <code>CV_RGB( r, g, b )</code>.</p>
5174
5175
5176 <hr><h3><a name="decl_cvRectangle">Rectangle</a></h3>
5177 <p class="Blurb">Draws simple, thick or filled rectangle</p>
5178 <pre>
5179 void cvRectangle( CvArr* img, CvPoint pt1, CvPoint pt2, CvScalar color,
5180                   int thickness=1, int line_type=8, int shift=0 );
5181 </pre><p><dl>
5182 <dt>img<dd>Image.
5183 <dt>pt1<dd>One of the rectangle vertices.
5184 <dt>pt2<dd>Opposite rectangle vertex.
5185 <dt>color<dd>Line color (RGB) or brightness (grayscale image).
5186 <dt>thickness<dd>Thickness of lines that make up the rectangle. Negative values, e.g. CV_FILLED,
5187 make the function to draw a filled rectangle.
5188 <dt>line_type<dd>Type of the line, see <a href="#decl_cvLine">cvLine</a> description.
5189 <dt>shift<dd>Number of fractional bits in the point coordinates.
5190 </dl><p>
5191 The function <code>cvRectangle</code> draws a rectangle with
5192 two opposite corners <code>pt1</code> and <code>pt2</code>.</p>
5193
5194
5195 <hr><h3><a name="decl_cvCircle">Circle</a></h3>
5196 <p class="Blurb">Draws a circle</p>
5197 <pre>
5198 void cvCircle( CvArr* img, CvPoint center, int radius, CvScalar color,
5199                int thickness=1, int line_type=8, int shift=0 );
5200 </pre><p><dl>
5201 <dt>img<dd>Image where the circle is drawn.
5202 <dt>center<dd>Center of the circle.
5203 <dt>radius<dd>Radius of the circle.
5204 <dt>color<dd>Circle color.
5205 <dt>thickness<dd>Thickness of the circle outline if positive, otherwise indicates that
5206 a filled circle has to be drawn.
5207 <dt>line_type<dd>Type of the circle boundary, see <a href="#decl_cvLine">cvLine</a> description.
5208 <dt>shift<dd>Number of fractional bits in the center coordinates and radius value.
5209 </dl><p>
5210 The function <code>cvCircle</code> draws a simple or filled circle with given center and
5211 radius. The circle is clipped by ROI rectangle. To specify the circle color, the user may
5212 use the macro <code>CV_RGB ( r, g, b )</code>.</p>
5213
5214
5215 <hr><h3><a name="decl_cvEllipse">Ellipse</a></h3>
5216 <p class="Blurb">Draws simple or thick elliptic arc or fills ellipse sector</p>
5217 <pre>
5218 void cvEllipse( CvArr* img, CvPoint center, CvSize axes, double angle,
5219                 double start_angle, double end_angle, CvScalar color,
5220                 int thickness=1, int line_type=8, int shift=0 );
5221 </pre><p><dl>
5222 <dt>img<dd>Image.
5223 <dt>center<dd>Center of the ellipse.
5224 <dt>axes<dd>Length of the ellipse axes.
5225 <dt>angle<dd>Rotation angle.
5226 <dt>start_angle<dd>Starting angle of the elliptic arc.
5227 <dt>end_angle<dd>Ending angle of the elliptic arc.
5228 <dt>color<dd>Ellipse color.
5229 <dt>thickness<dd>Thickness of the ellipse arc.
5230 <dt>line_type<dd>Type of the ellipse boundary, see <a href="#decl_cvLine">cvLine</a> description.
5231 <dt>shift<dd>Number of fractional bits in the center coordinates and axes' values.
5232 </dl><p>
5233 The function <code>cvEllipse</code> draws a simple or thick elliptic arc or fills an ellipse
5234 sector. The arc is clipped by ROI rectangle. A piecewise-linear
5235 approximation is used for antialiased arcs and thick arcs. All the angles are
5236 given in degrees. The picture below explains the meaning of the parameters.</p>
5237 <p>
5238 <font color=blue>Parameters of Elliptic Arc</font>
5239 </p>
5240 <p>
5241 <img align="center" src="pics/ellipse.png" >
5242 </p>
5243
5244
5245 <hr><h3><a name="decl_cvEllipseBox">EllipseBox</a></h3>
5246 <p class="Blurb">Draws simple or thick elliptic arc or fills ellipse sector</p>
5247 <pre>
5248 void cvEllipseBox( CvArr* img, CvBox2D box, CvScalar color,
5249                    int thickness=1, int line_type=8, int shift=0 );
5250 </pre><p><dl>
5251 <dt>img<dd>Image.
5252 <dt>box<dd>The enclosing box of the ellipse drawn
5253 <dt>thickness<dd>Thickness of the ellipse boundary.
5254 <dt>line_type<dd>Type of the ellipse boundary, see <a href="#decl_cvLine">cvLine</a> description.
5255 <dt>shift<dd>Number of fractional bits in the box vertex coordinates.
5256 </dl><p>
5257 The function <code>cvEllipseBox</code> draws a simple or thick ellipse outline,
5258 or fills an ellipse. The functions provides a convenient way to draw an ellipse
5259 approximating some shape; that is what <a href="opencvref_cv.htm#decl_cvCamShift">cvCamShift</a>
5260 and <a href="opencvref_cv.htm#decl_cvFitEllipse">cvFitEllipse</a> do.
5261 The ellipse drawn is clipped by ROI rectangle. A piecewise-linear
5262 approximation is used for antialiased arcs and thick arcs.</p>
5263
5264
5265 <hr><h3><a name="decl_cvFillPoly">FillPoly</a></h3>
5266 <p class="Blurb">Fills polygons interior</p>
5267 <pre>
5268 void cvFillPoly( CvArr* img, CvPoint** pts, int* npts, int contours,
5269                  CvScalar color, int line_type=8, int shift=0 );
5270 </pre><p><dl>
5271 <dt>img<dd>Image.
5272 <dt>pts<dd>Array of pointers to polygons.
5273 <dt>npts<dd>Array of polygon vertex counters.
5274 <dt>contours<dd>Number of contours that bind the filled region.
5275 <dt>color<dd>Polygon color.
5276 <dt>line_type<dd>Type of the polygon boundaries, see <a href="#decl_cvLine">cvLine</a> description.
5277 <dt>shift<dd>Number of fractional bits in the vertex coordinates.
5278 </dl><p>
5279 The function <code>cvFillPoly</code> fills an area bounded by several polygonal contours.
5280 The function fills complex areas, for example, areas with holes, contour self-intersection, etc.</p>
5281
5282
5283 <hr><h3><a name="decl_cvFillConvexPoly">FillConvexPoly</a></h3>
5284 <p class="Blurb">Fills convex polygon</p>
5285 <pre>
5286 void cvFillConvexPoly( CvArr* img, CvPoint* pts, int npts,
5287                        CvScalar color, int line_type=8, int shift=0 );
5288 </pre><p><dl>
5289 <dt>img<dd>Image.
5290 <dt>pts<dd>Array of pointers to a single polygon.
5291 <dt>npts<dd>Polygon vertex counter.
5292 <dt>color<dd>Polygon color.
5293 <dt>line_type<dd>Type of the polygon boundaries, see <a href="#decl_cvLine">cvLine</a> description.
5294 <dt>shift<dd>Number of fractional bits in the vertex coordinates.
5295 </dl><p>
5296 The function <code>cvFillConvexPoly</code> fills convex polygon interior.
5297 This function is much faster than The function <code>cvFillPoly</code> and can fill
5298 not only the convex polygons but any monotonic polygon, i.e. a polygon whose contour intersects every
5299 horizontal line (scan line) twice at the most.</p>
5300
5301
5302 <hr><h3><a name="decl_cvPolyLine">PolyLine</a></h3>
5303 <p class="Blurb">Draws simple or thick polygons</p>
5304 <pre>
5305 void cvPolyLine( CvArr* img, CvPoint** pts, int* npts, int contours, int is_closed,
5306                  CvScalar color, int thickness=1, int line_type=8, int shift=0 );
5307 </pre><p><dl>
5308 <dt>img<dd>Image.
5309 <dt>pts<dd>Array of pointers to polylines.
5310 <dt>npts<dd>Array of polyline vertex counters.
5311 <dt>contours<dd>Number of polyline contours.
5312 <dt>is_closed<dd>Indicates whether the polylines must be drawn closed. If closed, the
5313 function draws the line from the last vertex of every contour to the first
5314 vertex.
5315 <dt>color<dd>Polyline color.
5316 <dt>thickness<dd>Thickness of the polyline edges.
5317 <dt>line_type<dd>Type of the line segments, see <a href="#decl_cvLine">cvLine</a> description.
5318 <dt>shift<dd>Number of fractional bits in the vertex coordinates.
5319 </dl><p>
5320 The function <code>cvPolyLine</code> draws a single or multiple polygonal curves.</p>
5321
5322
5323 <hr><h2><a name="cxcore_drawing_text">Text</a></h2>
5324
5325 <hr><h3><a name="decl_cvInitFont">InitFont</a></h3>
5326 <p class="Blurb">Initializes font structure</p>
5327 <pre>
5328 void cvInitFont( CvFont* font, int font_face, double hscale,
5329                  double vscale, double shear=0,
5330                  int thickness=1, int line_type=8 );
5331 </pre><p><dl>
5332 <dt>font<dd>Pointer to the font structure initialized by the function.
5333 <dt>font_face<dd>Font name identifier. Only a subset of Hershey fonts
5334 (<a href="http://sources.isc.org/utils/misc/hershey-font.txt">http://sources.isc.org/utils/misc/hershey-font.txt</a>)
5335 are supported now:<br>
5336     <code>CV_FONT_HERSHEY_SIMPLEX</code> - normal size sans-serif font<br>
5337     <code>CV_FONT_HERSHEY_PLAIN</code> - small size sans-serif font<br>
5338     <code>CV_FONT_HERSHEY_DUPLEX</code> - normal size sans-serif font (more complex than <code>CV_FONT_HERSHEY_SIMPLEX</code>)<br>
5339     <code>CV_FONT_HERSHEY_COMPLEX</code> - normal size serif font<br>
5340     <code>CV_FONT_HERSHEY_TRIPLEX</code> - normal size serif font (more complex than <code>CV_FONT_HERSHEY_COMPLEX</code>)<br>
5341     <code>CV_FONT_HERSHEY_COMPLEX_SMALL</code> - smaller version of <code>CV_FONT_HERSHEY_COMPLEX</code><br>
5342     <code>CV_FONT_HERSHEY_SCRIPT_SIMPLEX</code> - hand-writing style font<br>
5343     <code>CV_FONT_HERSHEY_SCRIPT_COMPLEX</code> - more complex variant of <code>CV_FONT_HERSHEY_SCRIPT_SIMPLEX</code><br>
5344     The parameter can be composed from one of the values above and optional <code>CV_FONT_ITALIC</code> flag,
5345     that means italic or oblique font.
5346 <dt>hscale<dd>Horizontal scale. If equal to <code>1.0f</code>, the characters have the original
5347 width depending on the font type. If equal to <code>0.5f</code>, the characters are of half
5348 the original width.
5349 <dt>vscale<dd>Vertical scale. If equal to <code>1.0f</code>, the characters have the original
5350 height depending on the font type. If equal to <code>0.5f</code>, the characters are of half
5351 the original height.
5352 <dt>shear<dd>Approximate tangent of the character slope relative to the vertical
5353 line. Zero value means a non-italic font, <code>1.0f</code> means <code>&asymp;45&deg;</code> slope, etc.
5354 thickness Thickness of lines composing letters outlines. The function <code>cvLine</code> is
5355 used for drawing letters.
5356 <dt>thickness<dd>Thickness of the text strokes.
5357 <dt>line_type<dd>Type of the strokes, see <a href="#decl_cvLine">cvLine</a> description.
5358 </dl><p>
5359 The function <code>cvInitFont</code> initializes the font structure that can be passed to
5360 text rendering functions.</p>
5361
5362
5363 <hr><h3><a name="decl_cvPutText">PutText</a></h3>
5364 <p class="Blurb">Draws text string</p>
5365 <pre>
5366 void cvPutText( CvArr* img, const char* text, CvPoint org, const CvFont* font, CvScalar color );
5367 </pre><p><dl>
5368 <dt>img<dd>Input image.
5369 <dt>text<dd>String to print.
5370 <dt>org<dd>Coordinates of the bottom-left corner of the first letter.
5371 <dt>font<dd>Pointer to the font structure.
5372 <dt>color<dd>Text color.
5373 </dl><p>
5374 The function <code>cvPutText</code> renders the text in the image with the specified font and
5375 color. The printed text is clipped by ROI rectangle. Symbols that do not belong
5376 to the specified font are replaced with the rectangle symbol.</p>
5377
5378
5379 <hr><h3><a name="decl_cvGetTextSize">GetTextSize</a></h3>
5380 <p class="Blurb">Retrieves width and height of text string</p>
5381 <pre>
5382 void cvGetTextSize( const char* text_string, const CvFont* font, CvSize* text_size, int* baseline );
5383 </pre><p><dl>
5384 <dt>font<dd>Pointer to the font structure.
5385 <dt>text_string<dd>Input string.
5386 <dt>text_size<dd>Resultant size of the text string. Height of the text does not include
5387 the height of character parts that are below the baseline.
5388 <dt>baseline<dd>y-coordinate of the baseline relatively to the bottom-most text point.
5389 </dl><p>
5390 The function <code>cvGetTextSize</code> calculates the binding rectangle for the given text
5391 string when a specified font is used.</p>
5392
5393
5394 <hr><h2><a name="cxcore_drawing_seq">Point Sets and Contours</a></h2>
5395
5396 <hr><h3><a name="decl_cvDrawContours">DrawContours</a></h3>
5397 <p class="Blurb">Draws contour outlines or interiors in the image</p>
5398 <pre>
5399 void cvDrawContours( CvArr *img, CvSeq* contour,
5400                      CvScalar external_color, CvScalar hole_color,
5401                      int max_level, int thickness=1,
5402                      int line_type=8, CvPoint offset=cvPoint(0,0) );
5403 </pre><p><dl>
5404 <dt>img<dd>Image where the contours are to be drawn. Like in any other drawing
5405 function, the contours are clipped with the ROI.
5406 <dt>contour<dd>Pointer to the first contour.
5407 <dt>external_color<dd>Color of the external contours.
5408 <dt>hole_color<dd>Color of internal contours (holes).
5409 <dt>max_level<dd>Maximal level for drawn contours. If 0, only <code>contour</code> is drawn. If
5410 1, the contour and all contours after it on the same level are drawn. If 2, all
5411 contours after and all contours one level below the contours are drawn, etc.
5412 If the value is negative, the function does not draw the contours following after <code>contour</code>
5413 but draws child contours of <code>contour</code> up to abs(<code>max_level</code>)-1 level.
5414 <dt>thickness<dd>Thickness of lines the contours are drawn with. If it is negative (e.g. =CV_FILLED),
5415 the contour interiors are drawn.
5416 <dt>line_type<dd>Type of the contour segments, see <a href="#decl_cvLine">cvLine</a> description.
5417 <dt>offset<dd>Shift all the point coordinates by the specified value.
5418               It is useful in case if the contours retrieved in some image ROI and
5419               then the ROI offset needs to be taken into account during the rendering.
5420 </dl><p>
5421 The function <code>cvDrawContours</code> draws contour outlines in the image if <code>thickness</code>&gt;=0
5422 or fills area bounded by the contours if <code>thickness</code>&lt;0.
5423 </p>
5424 <h4>Example. Connected component detection via contour functions</h4>
5425 <pre>
5426 #include "cv.h"
5427 #include "highgui.h"
5428
5429 int main( int argc, char** argv )
5430 {
5431     IplImage* src;
5432     // the first command line parameter must be file name of binary (black-n-white) image
5433     if( argc == 2 && (src=cvLoadImage(argv[1], 0))!= 0)
5434     {
5435         IplImage* dst = cvCreateImage( cvGetSize(src), 8, 3 );
5436         CvMemStorage* storage = cvCreateMemStorage(0);
5437         CvSeq* contour = 0;
5438
5439         cvThreshold( src, src, 1, 255, CV_THRESH_BINARY );
5440         cvNamedWindow( "Source", 1 );
5441         cvShowImage( "Source", src );
5442
5443         cvFindContours( src, storage, &amp;contour, sizeof(CvContour), CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE );
5444         cvZero( dst );
5445
5446         for( ; contour != 0; contour = contour->h_next )
5447         {
5448             CvScalar color = CV_RGB( rand()&255, rand()&255, rand()&255 );
5449             /* replace CV_FILLED with 1 to see the outlines */
5450             cvDrawContours( dst, contour, color, color, -1, CV_FILLED, 8 );
5451         }
5452
5453         cvNamedWindow( "Components", 1 );
5454         cvShowImage( "Components", dst );
5455         cvWaitKey(0);
5456     }
5457 }
5458 </pre>
5459 <p>Replace CV_FILLED with 1 in the sample below to see the contour outlines
5460 </p>
5461
5462
5463 <hr><h3><a name="decl_cvInitLineIterator">InitLineIterator</a></h3>
5464 <p class="Blurb">Initializes line iterator</p>
5465 <pre>
5466 int cvInitLineIterator( const CvArr* image, CvPoint pt1, CvPoint pt2,
5467                         CvLineIterator* line_iterator, int connectivity=8,
5468                         int left_to_right=0 );
5469 </pre><p><dl>
5470 <dt>image<dd>Image to sample the line from.
5471 <dt>pt1<dd>First ending point of the line segment.
5472 <dt>pt2<dd>Second ending point of the line segment.
5473 <dt>line_iterator<dd>Pointer to the line iterator state structure.
5474 <dt>connectivity<dd>The scanned line connectivity, 4 or 8.
5475 <dt>left_to_right<dd>The flag, indicating whether the line should be always scanned from the
5476 left-most point to the right-most out of <code>pt1</code> and <code>pt2</code> (<code>left_to_right&ne;0</code>),
5477 or it is scanned in the specified order, from <code>pt1</code> to <code>pt2</code> (<code>left_to_right=0</code>).
5478 </dl><p>
5479 The function <code>cvInitLineIterator</code> initializes the line iterator and returns the
5480 number of pixels between two end points. Both points must be inside the image.
5481 After the iterator has been initialized, all the points on the raster line that
5482 connects the two ending points may be retrieved by successive calls of
5483 <code>CV_NEXT_LINE_POINT</code> point. The points on the line are calculated one by one using
5484 4-connected or 8-connected Bresenham algorithm.</p>
5485 <h4>Example. Using line iterator to calculate sum of pixel values along the color line</h4>
5486 <pre>
5487     CvScalar sum_line_pixels( IplImage* image, CvPoint pt1, CvPoint pt2 )
5488     {
5489         CvLineIterator iterator;
5490         int blue_sum = 0, green_sum = 0, red_sum = 0;
5491         int count = cvInitLineIterator( image, pt1, pt2, &iterator, 8, 0 );
5492
5493         for( int i = 0; i &lt; count; i++ ){
5494             blue_sum += iterator.ptr[0];
5495             green_sum += iterator.ptr[1];
5496             red_sum += iterator.ptr[2];
5497             CV_NEXT_LINE_POINT(iterator);
5498
5499             /* print the pixel coordinates: demonstrates how to calculate the coordinates */
5500             {
5501             int offset, x, y;
5502             /* assume that ROI is not set, otherwise need to take it into account. */
5503             offset = iterator.ptr - (uchar*)(image->imageData);
5504             y = offset/image->widthStep;
5505             x = (offset - y*image->widthStep)/(3*sizeof(uchar) /* size of pixel */);
5506             printf("(%d,%d)\n", x, y );
5507             }
5508         }
5509         return cvScalar( blue_sum, green_sum, red_sum );
5510     }
5511 </pre>
5512
5513
5514 <hr><h3><a name="decl_cvClipLine">ClipLine</a></h3>
5515 <p class="Blurb">Clips the line against the image rectangle</p>
5516 <pre>
5517 int cvClipLine( CvSize img_size, CvPoint* pt1, CvPoint* pt2 );
5518 </pre><p><dl>
5519 <dt>img_size<dd>Size of the image.
5520 <dt>pt1<dd>First ending point of the line segment. It is modified by the function.
5521 <dt>pt2<dd>Second ending point of the line segment. It is modified by the function.
5522 </dl><p>
5523 The function <code>cvClipLine</code> calculates a part of the line segment which is entirely in the image.
5524 It returns 0 if the line segment is completely outside the image and 1 otherwise.
5525 </p>
5526
5527
5528 <hr><h3><a name="decl_cvEllipse2Poly">Ellipse2Poly</a></h3>
5529 <p class="Blurb">Approximates elliptic arc with polyline</p>
5530 <pre>
5531 int cvEllipse2Poly( CvPoint center, CvSize axes,
5532                     int angle, int arc_start,
5533                     int arc_end, CvPoint* pts, int delta );
5534 </pre><p><dl>
5535 <dt>center<dd>Center of the arc.
5536 <dt>axes<dd>Half-sizes of the arc. See <a href="#decl_cvEllipse">cvEllipse</a>.
5537 <dt>angle<dd>Rotation angle of the ellipse in degrees. See <a href="#decl_cvEllipse">cvEllipse</a>.
5538 <dt>start_angle<dd>Starting angle of the elliptic arc.
5539 <dt>end_angle<dd>Ending angle of the elliptic arc.
5540 <dt>pts<dd>The array of points, filled by the function.
5541 <dt>delta<dd>Angle between the subsequent polyline vertices, approximation accuracy.
5542 So, the total number of output points will ceil((end_angle - start_angle)/delta) + 1 at max.
5543 </dl><p>
5544 The function <code>cvEllipse2Poly</code> computes vertices of the polyline that approximates the specified elliptic arc.
5545 It is used by <a href="#decl_cvEllipse">cvEllipse</a>.
5546 </p>
5547
5548
5549 <hr><h3><a name="decl_cvClipLine">ClipLine</a></h3>
5550 CVAPI(int) cvEllipse2Poly( CvPoint center, CvSize axes,
5551                  int angle, int arc_start, int arc_end, CvPoint * pts, int delta );
5552
5553
5554 <hr><h1><a name="cxcore_persistence">Data Persistence and RTTI</a></h1>
5555
5556 <hr><h2><a name="cxcore_persistence_ds">File Storage</a></h2>
5557
5558 <hr><h3><a name="decl_CvFileStorage">CvFileStorage</a></h3>
5559 <p class="Blurb">File Storage</p>
5560 <pre>
5561     typedef struct CvFileStorage
5562     {
5563         ...       // hidden fields
5564     } CvFileStorage;
5565 </pre>
5566 <p>
5567 The structure <a href="#decl_CvFileStorage">CvFileStorage</a> is "black box" representation of
5568 file storage that is associated with a file on disk. Several functions that are described below
5569 take <code>CvFileStorage</code> on input and allow user to save or to load hierarchical collections
5570 that consist of scalar values, standard CXCORE objects (such as matrices, sequences, graphs) and
5571 user-defined objects.
5572 </p><p>
5573 CXCORE can read and write data in XML (<a href="http://www.w3c.org/XML">http://www.w3c.org/XML</a>)
5574 or YAML (<a href="http://www.yaml.org">http://www.yaml.org</a>) formats. Below is the example of
5575 3&times;3 floating-point identity matrix <code>A</code>, stored in XML and YAML files using CXCORE functions:</p>
5576 <p><dl>
5577 <dt><b>XML:</b><dd><pre>
5578 &lt;?xml version="1.0"&gt;
5579 &lt;opencv_storage&gt;
5580 &lt;A type_id="opencv-matrix"&gt;
5581   &lt;rows&gt;3&lt;/rows&gt;
5582   &lt;cols&gt;3&lt;/cols&gt;
5583   &lt;dt&gt;f&lt;/dt&gt;
5584   &lt;data&gt;1. 0. 0. 0. 1. 0. 0. 0. 1.&lt;/data&gt;
5585 &lt;/A&gt;
5586 &lt;/opencv_storage&gt;
5587 </pre>
5588 <dt><b>YAML:</b><dd><pre>
5589 %YAML:1.0
5590 A: !!opencv-matrix
5591   rows: 3
5592   cols: 3
5593   dt: f
5594   data: [ 1., 0., 0., 0., 1., 0., 0., 0., 1.]
5595 </pre>
5596 </dl></p>
5597 <p>
5598 As it can be seen from the examples, XML uses nested tags to represent hierarchy,
5599 while YAML uses indentation for that purpose (similarly to Python programming language).
5600 </p><p>
5601 The same CXCORE functions can read and write data in both formats, the particular format is determined
5602 by the extension of the opened file, .xml for XML files and .yml or .yaml for YAML.
5603 </p>
5604
5605 <hr><h3><a name="decl_CvFileNode">CvFileNode</a></h3>
5606 <p class="Blurb">File Storage Node</p>
5607 <pre>
5608 /* file node type */
5609 #define CV_NODE_NONE        0
5610 #define CV_NODE_INT         1
5611 #define CV_NODE_INTEGER     CV_NODE_INT
5612 #define CV_NODE_REAL        2
5613 #define CV_NODE_FLOAT       CV_NODE_REAL
5614 #define CV_NODE_STR         3
5615 #define CV_NODE_STRING      CV_NODE_STR
5616 #define CV_NODE_REF         4 /* not used */
5617 #define CV_NODE_SEQ         5
5618 #define CV_NODE_MAP         6
5619 #define CV_NODE_TYPE_MASK   7
5620
5621 /* optional flags */
5622 #define CV_NODE_USER        16
5623 #define CV_NODE_EMPTY       32
5624 #define CV_NODE_NAMED       64
5625
5626 #define CV_NODE_TYPE(tag)  ((tag) & CV_NODE_TYPE_MASK)
5627
5628 #define CV_NODE_IS_INT(tag)        (CV_NODE_TYPE(tag) == CV_NODE_INT)
5629 #define CV_NODE_IS_REAL(tag)       (CV_NODE_TYPE(tag) == CV_NODE_REAL)
5630 #define CV_NODE_IS_STRING(tag)     (CV_NODE_TYPE(tag) == CV_NODE_STRING)
5631 #define CV_NODE_IS_SEQ(tag)        (CV_NODE_TYPE(tag) == CV_NODE_SEQ)
5632 #define CV_NODE_IS_MAP(tag)        (CV_NODE_TYPE(tag) == CV_NODE_MAP)
5633 #define CV_NODE_IS_COLLECTION(tag) (CV_NODE_TYPE(tag) >= CV_NODE_SEQ)
5634 #define CV_NODE_IS_FLOW(tag)       (((tag) & CV_NODE_FLOW) != 0)
5635 #define CV_NODE_IS_EMPTY(tag)      (((tag) & CV_NODE_EMPTY) != 0)
5636 #define CV_NODE_IS_USER(tag)       (((tag) & CV_NODE_USER) != 0)
5637 #define CV_NODE_HAS_NAME(tag)      (((tag) & CV_NODE_NAMED) != 0)
5638
5639 #define CV_NODE_SEQ_SIMPLE 256
5640 #define CV_NODE_SEQ_IS_SIMPLE(seq) (((seq)->flags & CV_NODE_SEQ_SIMPLE) != 0)
5641
5642 typedef struct CvString
5643 {
5644     int len;
5645     char* ptr;
5646 }
5647 CvString;
5648
5649 /* all the keys (names) of elements in the read file storage
5650    are stored in the hash to speed up the lookup operations */
5651 typedef struct CvStringHashNode
5652 {
5653     unsigned hashval;
5654     CvString str;
5655     struct CvStringHashNode* next;
5656 }
5657 CvStringHashNode;
5658
5659 /* basic element of the file storage - scalar or collection */
5660 typedef struct CvFileNode
5661 {
5662     int tag;
5663     struct CvTypeInfo* info; /* type information
5664             (only for user-defined object, for others it is 0) */
5665     union
5666     {
5667         double f; /* scalar floating-point number */
5668         int i;    /* scalar integer number */
5669         CvString str; /* text string */
5670         CvSeq* seq; /* sequence (ordered collection of file nodes) */
5671         struct CvMap* map; /* map (collection of named file nodes) */
5672     } data;
5673 }
5674 CvFileNode;
5675 </pre>
5676 <p>
5677 The structure is used only for retrieving data from file storage (i.e. for loading data from file).
5678 When data is written to file, it is done sequentially, with minimal buffering. No data is stored in the
5679 file storage.</p><p>In opposite, when data is read from file, the whole file is parsed and represented in memory
5680 as a tree. Every node of the tree is represented by <a href="#decl_CvFileNode">CvFileNode</a>. Type of the file node
5681 <code>N</code> can be retrieved as <code>CV_NODE_TYPE(N->tag)</code>. Some file nodes (leaves) are scalars:
5682 text strings, integer or floating-point numbers. Other file nodes are collections of file nodes, which can
5683 be scalars or collections in their turn. There are two types of collections: sequences and maps
5684 (we use YAML notation, however, the same is true for XML streams). Sequences (do not mix them with
5685 <a href="#decl_CvSeq">CvSeq</a>) are ordered collections of unnamed file nodes,
5686 maps are unordered collections of named file nodes. Thus, elements of sequences are
5687 accessed by index (<a href="#decl_cvGetSeqElem">cvGetSeqElem</a>),
5688 while elements of maps are accessed by name
5689 (<a href="#decl_cvGetFileNodeByName">cvGetFileNodeByName</a>).
5690 The table below describes the different types of a file node:</p>
5691 <p><table border=1 cellpadding="10%">
5692 <tr><td>Type</td><td>CV_NODE_TYPE(node->tag)</td><td>Value</td></tr>
5693 <tr><td>Integer</td><td>CV_NODE_INT</td><td>node->data.i</td></tr>
5694 <tr><td>Floating-point</td><td>CV_NODE_REAL</td><td>node->data.f</td></tr>
5695 <tr><td>Text string</td><td>CV_NODE_STR</td><td>node->data.str.ptr</td></tr>
5696 <tr><td>Sequence</td><td>CV_NODE_SEQ</td><td>node->data.seq</td></tr>
5697 <tr><td>Map</td><td>CV_NODE_MAP</td><td>node->data.map*</td></tr>
5698 </table>
5699 <dl>
5700 <dt>*<dd>There is no need to access <code>map</code> field directly (BTW, <code>CvMap</code> is a hidden structure).
5701           The elements of the map can be retrieved with <a href="#decl_cvGetFileNodeByName">cvGetFileNodeByName</a>
5702           function that takes pointer to the "map" file node.
5703 <!--
5704 <dt>**<dd>Tag of the file node that represent a user object (see below) also includes <code>CV_NODE_USER</code> flag.
5705           That is, <code>CV_NODE_IS_USER(node->tag)</code> returns 1 on such a node.
5706 <dt>***<dd>The field contains pointer to decoded object. The original map is still available as
5707           <code>node->data.obj.map</code>. -->
5708 </dl>
5709 </p><p>
5710 A user (custom) object is instance of either one of standard CXCORE types, such as <a href="#decl_CvMat">CvMat</a>, <a href="#decl_CvSeq">CvSeq</a> etc.,
5711 or any type registered with <a href="#decl_cvRegisterTypeInfo">cvRegisterTypeInfo</a>. Such an object is initially represented in file as a map
5712 (as shown in XML and YAML sample files above), after file storage has been opened and parsed.
5713 Then the object can be decoded (converted to the native representation) by request -
5714 when user calls <a href="#decl_cvRead">cvRead</a> or
5715 <a href="#decl_cvReadByName">cvReadByName</a> function.</p>
5716
5717 <hr><h3><a name="decl_CvAttrList">CvAttrList</a></h3>
5718 <p class="Blurb">List of attributes</p>
5719 <pre>
5720 typedef struct CvAttrList
5721 {
5722     const char** attr; /* NULL-terminated array of (attribute_name,attribute_value) pairs */
5723     struct CvAttrList* next; /* pointer to next chunk of the attributes list */
5724 }
5725 CvAttrList;
5726
5727 /* initializes CvAttrList structure */
5728 inline CvAttrList cvAttrList( const char** attr=NULL, CvAttrList* next=NULL );
5729
5730 /* returns attribute value or 0 (NULL) if there is no such attribute */
5731 const char* cvAttrValue( const CvAttrList* attr, const char* attr_name );
5732 </pre>
5733 <p>
5734 In the current implementation attributes are used to pass extra parameters when writing user objects
5735 (see <a href="#decl_cvWrite">cvWrite</a>).
5736 XML attributes inside tags are not supported, besides the object type specification
5737 (<code>type_id</code> attribute).
5738 </p>
5739
5740
5741 <hr><h3><a name="decl_cvOpenFileStorage">OpenFileStorage</a></h3>
5742 <p class="Blurb">Opens file storage for reading or writing data</p>
5743 <pre>
5744 CvFileStorage* cvOpenFileStorage( const char* filename, CvMemStorage* memstorage, int flags );
5745 </pre><p><dl>
5746 <dt>filename<dd>Name of the file associated with the storage.
5747 <dt>memstorage<dd>Memory storage used for temporary data and for storing dynamic structures,
5748 such as <a href="#decl_CvSeq">CvSeq</a> or <a href="#decl_CvGraph">CvGraph</a>.
5749 If it is NULL, a temporary memory storage is created and used.
5750 <dt>flags<dd>Can be one of the following:<br>
5751             <code>CV_STORAGE_READ</code> - the storage is open for reading<br>
5752             <code>CV_STORAGE_WRITE</code> - the storage is open for writing<br>
5753 </dl><p>
5754 The function <code>cvOpenFileStorage</code> opens file storage for
5755 reading or writing data. In the latter case a new file is created or existing file is
5756 rewritten. Type of the read of written file is determined by the filename extension: <code>.xml</code>
5757 for <em>XML</em>, and <code>.yml</code> or <code>.yaml</code> for <em>YAML</em>.
5758 The function returns pointer to <a href="#decl_CvFileStorage">CvFileStorage</a> structure.</p>
5759
5760
5761 <hr><h3><a name="decl_cvReleaseFileStorage">ReleaseFileStorage</a></h3>
5762 <p class="Blurb">Releases file storage</p>
5763 <pre>
5764 void  cvReleaseFileStorage( CvFileStorage** fs );
5765 </pre><p><dl>
5766 <dt>fs<dd>Double pointer to the released file storage.
5767 </dl><p>
5768 The function <code>cvReleaseFileStorage</code> closes the file
5769 associated with the storage and releases all the temporary structures.
5770 It must be called after all I/O operations with the storage are finished.</p>
5771
5772
5773 <hr><h2><a name="cxcore_persistence_writing">Writing Data</a></h2>
5774
5775 <hr><h3><a name="decl_cvStartWriteStruct">StartWriteStruct</a></h3>
5776 <p class="Blurb">Starts writing a new structure</p>
5777 <pre>
5778 void  cvStartWriteStruct( CvFileStorage* fs, const char* name,
5779                           int struct_flags, const char* type_name=NULL,
5780                           CvAttrList attributes=cvAttrList());
5781 </pre><p><dl>
5782 <dt>fs<dd>File storage.
5783 <dt>name<dd>Name of the written structure. The structure can be accessed by this name when
5784             the storage is read.
5785 <dt>struct_flags<dd>A combination one of the following values:<br>
5786               <code>CV_NODE_SEQ</code> - the written structure is a sequence (see discussion of
5787                 <a href="#decl_CvFileStorage">CvFileStorage</a>), that is,
5788                 its elements do not have a name. <br>
5789               <code>CV_NODE_MAP</code> - the written structure is a map (see discussion of
5790                 <a href="#decl_CvFileStorage">CvFileStorage</a>), that is,
5791                 all its elements have names. <br>
5792                <em>One and only one of the two above flags must be specified</em><br>
5793               <code>CV_NODE_FLOW</code> - the optional flag that has sense only for YAML streams.
5794                 It means that the structure is written as a flow (not as a block), which is more
5795                 compact. It is recommended to use this flag for structures or arrays whose elements are
5796                 all scalars.
5797 <dt>type_name<dd>Optional parameter - the object type name. In case of XML it is written as
5798                 <code>type_id</code> attribute of the structure opening tag. In case of YAML
5799                 it is written after a colon following the structure name (see the example in
5800                 <a href="#decl_CvFileStorage">CvFileStorage</a> description).
5801                 Mainly it comes with user objects.
5802                 When the storage is read, the encoded type name is used to determine
5803                 the object type (see <a href="#decl_CvTypeInfo">CvTypeInfo</a> and
5804                 <a href="#decl_cvFindTypeInfo">cvFindTypeInfo</a>).
5805 <dt>attributes<dd>This parameter is not used in the current implementation.
5806 </dl><p>
5807 The function <code>cvStartWriteStruct</code> starts writing
5808 a compound structure (collection) that can be a sequence or a map. After all the structure
5809 fields, which can be scalars or structures, are written,
5810 <a href="#decl_cvEndWriteStruct">cvEndWriteStruct</a> should be called.
5811 The function can be used to group some objects or to implement <em>write</em> function for a
5812 some user object (see <a href="#decl_CvTypeInfo">CvTypeInfo</a>).
5813 </p>
5814
5815
5816 <hr><h3><a name="decl_cvEndWriteStruct">EndWriteStruct</a></h3>
5817 <p class="Blurb">Ends writing a structure</p>
5818 <pre>
5819 void  cvEndWriteStruct( CvFileStorage* fs );
5820 </pre><p><dl>
5821 <dt>fs<dd>File storage.
5822 </dl><p>
5823 The function <code>cvEndWriteStruct</code> finishes the
5824 currently written structure.</p>
5825
5826
5827 <hr><h3><a name="decl_cvWriteInt">WriteInt</a></h3>
5828 <p class="Blurb">Writes an integer value</p>
5829 <pre>
5830 void  cvWriteInt( CvFileStorage* fs, const char* name, int value );
5831 </pre><p><dl>
5832 <dt>fs<dd>File storage.
5833 <dt>name<dd>Name of the written value. Should be NULL if and only if the
5834             parent structure is a sequence.
5835 <dt>value<dd>The written value.
5836 </dl><p>
5837 The function <code>cvWriteInt</code> writes a single integer value
5838 (with or without a name) to the file storage.</p>
5839
5840
5841 <hr><h3><a name="decl_cvWriteReal">WriteReal</a></h3>
5842 <p class="Blurb">Writes a floating-point value</p>
5843 <pre>
5844 void  cvWriteReal( CvFileStorage* fs, const char* name, double value );
5845 </pre><p><dl>
5846 <dt>fs<dd>File storage.
5847 <dt>name<dd>Name of the written value. Should be NULL if and only if the
5848             parent structure is a sequence.
5849 <dt>value<dd>The written value.
5850 </dl><p>
5851 The function <code>cvWriteReal</code> writes a single
5852 floating-point value (with or without a name) to the file storage. The special
5853 values are encoded: NaN (Not A Number) as .NaN, &plusmn;Infinity as +.Inf (-.Inf).</p>
5854 <p>The following example shows how to use the low-level writing functions to
5855 store custom structures, such as termination criteria, without registering
5856 a new type.</p>
5857 <pre>
5858 void write_termcriteria( CvFileStorage* fs, const char* struct_name,
5859                          CvTermCriteria* termcrit )
5860 {
5861     cvStartWriteStruct( fs, struct_name, CV_NODE_MAP, NULL, cvAttrList(0,0));
5862     cvWriteComment( fs, "termination criteria", 1 ); // just a description
5863     if( termcrit->type & CV_TERMCRIT_ITER )
5864         cvWriteInt( fs, "max_iterations", termcrit->max_iter );
5865     if( termcrit->type & CV_TERMCRIT_EPS )
5866         cvWriteReal( fs, "accuracy", termcrit->epsilon );
5867     cvEndWriteStruct( fs );
5868 }
5869 </pre>
5870
5871
5872 <hr><h3><a name="decl_cvWriteString">WriteString</a></h3>
5873 <p class="Blurb">Writes a text string</p>
5874 <pre>
5875 void  cvWriteString( CvFileStorage* fs, const char* name,
5876                      const char* str, int quote=0 );
5877 </pre><p><dl>
5878 <dt>fs<dd>File storage.
5879 <dt>name<dd>Name of the written string. Should be NULL if and only if the
5880             parent structure is a sequence.
5881 <dt>str<dd>The written text string.
5882 <dt>quote<dd>If non-zero, the written string is put in quotes, regardless of whether
5883              they are required or not. Otherwise, if the flag is zero, quotes are used
5884              only when they are required (e.g. when the string starts with a digit or contains
5885              spaces).
5886 </dl><p>
5887 The function <code>cvWriteString</code> writes a text string
5888 to the file storage.</p>
5889
5890
5891 <hr><h3><a name="decl_cvWriteComment">WriteComment</a></h3>
5892 <p class="Blurb">Writes comment</p>
5893 <pre>
5894 void  cvWriteComment( CvFileStorage* fs, const char* comment, int eol_comment );
5895 </pre><p><dl>
5896 <dt>fs<dd>File storage.
5897 <dt>comment<dd>The written comment, single-line or multi-line.
5898 <dt>eol_comment<dd>If non-zero, the function tries to put the comment in the end
5899              of current line. If the flag is zero, if the comment is multi-line, or
5900              if it does not fit in the end of the current line, the comment starts
5901              from a new line.
5902 </dl><p>
5903 The function <code>cvWriteComment</code> writes a comment into the
5904 file storage. The comments are skipped when the storage is read, so they may be
5905 used only for debugging or descriptive purposes.</p>
5906
5907
5908 <hr><h3><a name="decl_cvStartNextStream">StartNextStream</a></h3>
5909 <p class="Blurb">Starts the next stream</p>
5910 <pre>
5911 void  cvStartNextStream( CvFileStorage* fs );
5912 </pre><p><dl>
5913 <dt>fs<dd>File storage.
5914 </dl><p>
5915 The function <code>cvStartNextStream</code> starts the next
5916 stream in the file storage. Both YAML and XML supports multiple "streams". This
5917 is useful for concatenating files or for resuming the writing process.</p>
5918
5919
5920 <hr><h3><a name="decl_cvWrite">Write</a></h3>
5921 <p class="Blurb">Writes user object</p>
5922 <pre>
5923 void  cvWrite( CvFileStorage* fs, const char* name,
5924                const void* ptr, CvAttrList attributes=cvAttrList() );
5925 </pre><p><dl>
5926 <dt>fs<dd>File storage.
5927 <dt>name<dd>Name, of the written object. Should be NULL if and only if the parent
5928             structure is a sequence.
5929 <dt>ptr<dd>Pointer to the object.
5930 <dt>attributes<dd>The attributes of the object. They are specific for each particular
5931            type (see the discussion).
5932 </dl><p>
5933 The function <code>cvWrite</code> writes the object to file storage.
5934 First, the appropriate type info is found using <a href="#decl_cvTypeOf">cvTypeOf</a>.
5935 Then, <code>write</code> method of the type info is called.
5936 </p><p>
5937 Attributes are used to customize the writing procedure.
5938 The standard types support the following attributes
5939 (all the <code>*dt</code> attributes have the same format as in
5940 <a href="#decl_cvWriteRawData">cvWriteRawData</a>):
5941 <dl>
5942 <dt><a href="#decl_CvSeq">CvSeq</a><dd>
5943     <ul>
5944     <li><code>header_dt</code> - description
5945     of user fields of the sequence header that follow CvSeq, or CvChain
5946     (if the sequence is Freeman chain) or CvContour (if the sequence is a contour
5947     or point sequence)
5948     <li><code>dt</code> - description of the sequence elements.
5949     <li><code>recursive</code> - if the attribute is present and is not equal to "0" or "false",
5950     the whole tree of sequences (contours) is stored.
5951     </ul>
5952 <dt><code>CvGraph</code><dd>
5953     <ul>
5954     <li><code>header_dt</code> - description of user fields
5955     of the graph header that follow CvGraph;
5956     <li><code>vertex_dt</code> - description of
5957     user fields of graph vertices
5958     <li><code>edge_dt</code> - description of user fields of graph edges (note, that
5959     edge weight is always written, so there is no need to specify it explicitly)
5960     </ul>
5961 </dl>
5962 </p><p>
5963 Below is the code that creates the YAML file shown in <code>CvFileStorage</code>
5964 description:</p><p>
5965 <pre>
5966 #include "cxcore.h"
5967
5968 int main( int argc, char** argv )
5969 {
5970     CvMat* mat = cvCreateMat( 3, 3, CV_32F );
5971     CvFileStorage* fs = cvOpenFileStorage( "example.yml", 0, CV_STORAGE_WRITE );
5972
5973     cvSetIdentity( mat );
5974     cvWrite( fs, "A", mat, cvAttrList(0,0) );
5975
5976     cvReleaseFileStorage( &fs );
5977     cvReleaseMat( &mat );
5978     return 0;
5979 }
5980 </pre></p>
5981
5982
5983 <hr><h3><a name="decl_cvWriteRawData">WriteRawData</a></h3>
5984 <p class="Blurb">Writes multiple numbers</p>
5985 <pre>
5986 void  cvWriteRawData( CvFileStorage* fs, const void* src,
5987                       int len, const char* dt );
5988 </pre><p><dl>
5989 <dt>fs<dd>File storage.
5990 <dt>src<dd>Pointer to the written array
5991 <dt>len<dd>Number of the array elements to write.
5992 <dt>dt<dd>Specification of each array element that has the following format:
5993           <code>([count]{'u'|'c'|'w'|'s'|'i'|'f'|'d'})...</code>, where the characters
5994           correspond to fundamental C types:
5995           <ul>
5996               <li>'u' - 8-bit unsigned number
5997               <li>'c' - 8-bit signed number
5998               <li>'w' - 16-bit unsigned number
5999               <li>'s' - 16-bit signed number
6000               <li>'i' - 32-bit signed number
6001               <li>'f' - single precision floating-point number
6002               <li>'d' - double precision floating-point number
6003               <li>'r' - pointer. 32 lower bits of it are written as a signed
6004                         integer. The type can be used to store structures with
6005                         links between the elements.
6006           </ul>
6007           <code>count</code> is the optional counter of values of the certain type.
6008           For example, <code>dt='2if'</code> means that each array element is a structure
6009           of 2 integers, followed by a single-precision floating-point number. The equivalent
6010           notations of the above specification are <code>'iif'</code>, <code>'2i1f'</code> etc.
6011           Other examples: <code>dt='u'</code> means that the array consists of bytes,
6012           <code>dt='2d'</code> - the array consists of pairs of double&#146;s.
6013 </dl><p>
6014 The function <code>cvWriteRawData</code> writes array,
6015 which elements consist of a single of multiple numbers. The function call can
6016 be replaced with a loop containing a few <a href="#decl_cvWriteInt">cvWriteInt</a>
6017 and <a href="#decl_cvWriteReal">cvWriteReal</a> calls,
6018 but a single call is more efficient. Note, that because none of the elements
6019 have a name, they should be written to a sequence rather than a map.</p>
6020
6021
6022 <hr><h3><a name="decl_cvWriteFileNode">WriteFileNode</a></h3>
6023 <p class="Blurb">Writes file node to another file storage</p>
6024 <pre>
6025 void cvWriteFileNode( CvFileStorage* fs, const char* new_node_name,
6026                       const CvFileNode* node, int embed );
6027 </pre><dl>
6028 <dt>fs<dd>Destination file storage.
6029 <dt>new_file_node<dd>New name of the file node in the destination file storage.
6030                      To keep the existing name,
6031                      use <code><a href="#decl_cvGetFileNodeName">cvGetFileNodeName</a>(node)</code>.
6032 <dt>node<dd>The written node
6033 <dt>embed<dd>If the written node is a collection and this parameter is not zero,
6034              no extra level of hierarchy is created. Instead, all the elements of <code>node</code> are
6035              written into the currently written structure. Of course, map elements may be
6036              written only to map, and sequence elements may be written only to sequence.
6037 </dl><p>
6038 The function <code>cvWriteFileNode</code>
6039 writes a copy of file node to file storage. The possible application of the function are:
6040 merging several file storages into one. Conversion between XML and YAML formats etc.
6041 </p>
6042
6043
6044 <hr><h2><a name="cxcore_persistence_reading">Reading Data</a></h2>
6045
6046 <p>Data are retrieved from file storage in 2 steps:
6047 first, the file node containing the requested data is found;
6048 then, data is extracted from the node manually or using custom <code>read</code> method.</p>
6049
6050
6051 <hr><h3><a name="decl_cvGetRootFileNode">GetRootFileNode</a></h3>
6052 <p class="Blurb">Retrieves one of top-level nodes of the file storage</p>
6053 <pre>
6054 CvFileNode* cvGetRootFileNode( const CvFileStorage* fs, int stream_index=0 );
6055 </pre><p><dl>
6056 <dt>fs<dd>File storage.
6057 <dt>stream_index<dd>Zero-based index of the stream. See <a href="#decl_cvStartNextStream">cvStartNextStream</a>.
6058            In most cases, there is only one stream in the file, however there can be several.
6059 </dl><p>
6060 The function <code>cvGetRootFileNode</code> returns
6061 one of  top-level file nodes. The top-level nodes do not have a name, they correspond to
6062 the streams, that are stored one after another in the file storage.
6063 If the index is out of range, the function returns NULL pointer, so all the top-level
6064 nodes may be iterated by subsequent calls to the function with <code>stream_index=0,1,...</code>,
6065 until NULL pointer is returned. This function may be used as a base for recursive traversal of the
6066 file storage.</p>
6067
6068
6069 <hr><h3><a name="decl_cvGetFileNodeByName">GetFileNodeByName</a></h3>
6070 <p class="Blurb">Finds node in the map or file storage</p>
6071 <pre>
6072 CvFileNode* cvGetFileNodeByName( const CvFileStorage* fs,
6073                                  const CvFileNode* map,
6074                                  const char* name );
6075 </pre><p><dl>
6076 <dt>fs<dd>File storage.
6077 <dt>map<dd>The parent map. If it is NULL, the function searches
6078            in all the top-level nodes (streams), starting from the first one.
6079 <dt>name<dd>The file node name.
6080 </dl><p>
6081 The function <code>cvGetFileNodeByName</code> finds
6082 a file node by <code>name</code>. The node is searched either in <code>map</code>
6083 or, if the pointer is NULL, among the top-level file nodes of the storage.
6084 Using this function for maps and <a href="#decl_cvGetSeqElem">cvGetSeqElem</a>
6085 (or sequence reader) for sequences, it is possible to navigate through the file storage.
6086 To speed up multiple queries for a certain key (e.g. in case of array of structures)
6087 one may use a pair of <a href="#decl_cvGetHashedKey">cvGetHashedKey</a> and
6088 <a href="#decl_cvGetFileNode">cvGetFileNode</a>.</p>
6089
6090
6091 <hr><h3><a name="decl_cvGetHashedKey">GetHashedKey</a></h3>
6092 <p class="Blurb">Returns a unique pointer for given name</p>
6093 <pre>
6094 CvStringHashNode* cvGetHashedKey( CvFileStorage* fs, const char* name,
6095                                   int len=-1, int create_missing=0 );
6096 </pre><p><dl>
6097 <dt>fs<dd>File storage.
6098 <dt>name<dd>Literal node name.
6099 <dt>len<dd>Length of the name (if it is known a priori), or -1 if it needs to
6100            be calculated.
6101 <dt>create_missing<dd>Flag that specifies, whether an absent key should be
6102            added into the hash table, or not.
6103 </dl><p>
6104 The function <code>cvGetHashedKey</code> returns
6105 the unique pointer for each particular file node name. This pointer can be
6106 then passed to <a href="#decl_cvGetFileNode">cvGetFileNode</a> function that
6107 is faster than <a href="#decl_cvGetFileNodeByName">cvGetFileNodeByName</a>
6108 because it compares text strings by comparing pointers rather than the
6109 strings' content.</p><p>Consider the following example: an array of points
6110 is encoded as a sequence of 2-entry maps, e.g.:
6111 <pre>
6112 %YAML:1.0
6113 points:
6114   - { x: 10, y: 10 }
6115   - { x: 20, y: 20 }
6116   - { x: 30, y: 30 }
6117   # ...
6118 </pre>
6119 Then, it is possible to get hashed "x" and "y" pointers to speed up
6120 decoding of the points.
6121 <h4>Example. Reading an array of structures from file storage</h4>
6122 <pre>
6123 #include "cxcore.h"
6124
6125 int main( int argc, char** argv )
6126 {
6127     CvFileStorage* fs = cvOpenFileStorage( "points.yml", 0, CV_STORAGE_READ );
6128     CvStringHashNode* x_key = cvGetHashedNode( fs, "x", -1, 1 );
6129     CvStringHashNode* y_key = cvGetHashedNode( fs, "y", -1, 1 );
6130     CvFileNode* points = cvGetFileNodeByName( fs, 0, "points" );
6131
6132     if( CV_NODE_IS_SEQ(points->tag) )
6133     {
6134         CvSeq* seq = points->data.seq;
6135         int i, total = seq->total;
6136         CvSeqReader reader;
6137         cvStartReadSeq( seq, &reader, 0 );
6138         for( i = 0; i &lt; total; i++ )
6139         {
6140             CvFileNode* pt = (CvFileNode*)reader.ptr;
6141 #if 1 /* faster variant */
6142             CvFileNode* xnode = cvGetFileNode( fs, pt, x_key, 0 );
6143             CvFileNode* ynode = cvGetFileNode( fs, pt, y_key, 0 );
6144             assert( xnode && CV_NODE_IS_INT(xnode->tag) &&
6145                     ynode && CV_NODE_IS_INT(ynode->tag));
6146             int x = xnode->data.i; // or x = cvReadInt( xnode, 0 );
6147             int y = ynode->data.i; // or y = cvReadInt( ynode, 0 );
6148 #elif 1 /* slower variant; does not use x_key & y_key */
6149             CvFileNode* xnode = cvGetFileNodeByName( fs, pt, "x" );
6150             CvFileNode* ynode = cvGetFileNodeByName( fs, pt, "y" );
6151             assert( xnode && CV_NODE_IS_INT(xnode->tag) &&
6152                     ynode && CV_NODE_IS_INT(ynode->tag));
6153             int x = xnode->data.i; // or x = cvReadInt( xnode, 0 );
6154             int y = ynode->data.i; // or y = cvReadInt( ynode, 0 );
6155 #else /* the slowest yet the easiest to use variant */
6156             int x = cvReadIntByName( fs, pt, "x", 0 /* default value */ );
6157             int y = cvReadIntByName( fs, pt, "y", 0 /* default value */ );
6158 #endif
6159             CV_NEXT_SEQ_ELEM( seq->elem_size, reader );
6160             printf("%d: (%d, %d)\n", i, x, y );
6161         }
6162     }
6163     cvReleaseFileStorage( &fs );
6164     return 0;
6165 }
6166 </pre>
6167 <p>Please note that, whatever method of accessing map you are using,
6168 it is still <em>much</em> slower than using plain sequences, for example,
6169 in the above sample, it is more efficient to encode the points as pairs of
6170 integers in the single numeric sequence.</p>
6171
6172
6173 <hr><h3><a name="decl_cvGetFileNode">GetFileNode</a></h3>
6174 <p class="Blurb">Finds node in the map or file storage</p>
6175 <pre>
6176 CvFileNode* cvGetFileNode( CvFileStorage* fs, CvFileNode* map,
6177                            const CvStringHashNode* key, int create_missing=0 );
6178 </pre><p><dl>
6179 <dt>fs<dd>File storage.
6180 <dt>map<dd>The parent map. If it is NULL, the function searches a top-level node.
6181            If both <code>map</code> and <code>key</code> are NULLs,
6182            the function returns the root file node - a map
6183            that contains top-level nodes.
6184 <dt>key<dd>Unique pointer to the node name, retrieved with
6185            <a href="#decl_cvGetHashedKey">cvGetHashedKey</a>.
6186 <dt>create_missing<dd>Flag that specifies, whether an absent node should be
6187            added to the map, or not.
6188 </dl><p>
6189 The function <code>cvGetFileNode</code> finds a file node. It is
6190 a faster version <a href="#decl_cvGetFileNodeByName">cvGetFileNodeByName</a>
6191 (see <a href="#decl_cvGetHashedKey">cvGetHashedKey</a> discussion). Also,
6192 the function can insert a new node, if it is not in the map yet (which is used
6193 by parsing functions).</p>
6194
6195
6196 <hr><h3><a name="decl_cvGetFileNodeName">GetFileNodeName</a></h3>
6197 <p class="Blurb">Returns name of file node</p>
6198 <pre>
6199 const char* cvGetFileNodeName( const CvFileNode* node );
6200 </pre><p><dl>
6201 <dt>node<dd>File node
6202 </dl><p>
6203 The function <code>cvGetFileNodeName</code> returns name of the file node
6204 or NULL, if the file node does not have a name, or if <code>node</code> is <code>NULL</code>.</p>
6205
6206
6207 <hr><h3><a name="decl_cvReadInt">ReadInt</a></h3>
6208 <p class="Blurb">Retrieves integer value from file node</p>
6209 <pre>
6210 int cvReadInt( const CvFileNode* node, int default_value=0 );
6211 </pre><p><dl>
6212 <dt>node<dd>File node.
6213 <dt>default_value<dd>The value that is returned if <code>node</code> is NULL.
6214 </dl><p>
6215 The function <code>cvReadInt</code> returns integer that is
6216 represented by the file node. If the file node is NULL, <code>default_value</code>
6217 is returned (thus, it is convenient to call the function right after
6218 <a href="#decl_cvGetFileNode">cvGetFileNode</a> without checking for NULL pointer),
6219 otherwise if the file node has type <code>CV_NODE_INT</code>,
6220 then <code>node->data.i</code> is returned, otherwise if the file node has
6221 type <code>CV_NODE_REAL</code>, then <code>node->data.f</code>
6222 is converted to integer and returned, otherwise the result is not determined.</p>
6223
6224
6225 <hr><h3><a name="decl_cvReadIntByName">ReadIntByName</a></h3>
6226 <p class="Blurb">Finds file node and returns its value</p>
6227 <pre>
6228 int cvReadIntByName( const CvFileStorage* fs, const CvFileNode* map,
6229                      const char* name, int default_value=0 );
6230 </pre><p><dl>
6231 <dt>fs<dd>File storage.
6232 <dt>map<dd>The parent map. If it is NULL, the function searches a top-level node.
6233 <dt>name<dd>The node name.
6234 <dt>default_value<dd>The value that is returned if the file node is not found.
6235 </dl><p>
6236 The function <code>cvReadIntByName</code> is a simple
6237 superposition of <a href="#decl_cvGetFileNodeByName">cvGetFileNodeByName</a> and
6238 <a href="#decl_cvReadInt">cvReadInt</a>.
6239
6240
6241 <hr><h3><a name="decl_cvReadReal">ReadReal</a></h3>
6242 <p class="Blurb">Retrieves floating-point value from file node</p>
6243 <pre>
6244 double cvReadReal( const CvFileNode* node, double default_value=0. );
6245 </pre><p><dl>
6246 <dt>node<dd>File node.
6247 <dt>default_value<dd>The value that is returned if <code>node</code> is NULL.
6248 </dl><p>
6249 The function <code>cvReadReal</code> returns floating-point value that is
6250 represented by the file node. If the file node is NULL, <code>default_value</code>
6251 is returned (thus, it is convenient to call the function right after
6252 <a href="#decl_cvGetFileNode">cvGetFileNode</a> without checking for NULL pointer),
6253 otherwise if the file node has type <code>CV_NODE_REAL</code>,
6254 then <code>node->data.f</code> is returned, otherwise if the file node has
6255 type <code>CV_NODE_INT</code>, then <code>node->data.f</code>
6256 is converted to floating-point and returned, otherwise the result is not determined.</p>
6257
6258
6259 <hr><h3><a name="decl_cvReadRealByName">ReadRealByName</a></h3>
6260 <p class="Blurb">Finds file node and returns its value</p>
6261 <pre>
6262 double  cvReadRealByName( const CvFileStorage* fs, const CvFileNode* map,
6263                           const char* name, double default_value=0. );
6264 </pre><p><dl>
6265 <dt>fs<dd>File storage.
6266 <dt>map<dd>The parent map. If it is NULL, the function searches a top-level node.
6267 <dt>name<dd>The node name.
6268 <dt>default_value<dd>The value that is returned if the file node is not found.
6269 </dl><p>
6270 The function <code>cvReadRealByName</code> is a simple
6271 superposition of <a href="#decl_cvGetFileNodeByName">cvGetFileNodeByName</a> and
6272 <a href="#decl_cvReadReal">cvReadReal</a>.
6273
6274
6275 <hr><h3><a name="decl_cvReadString">ReadString</a></h3>
6276 <p class="Blurb">Retrieves text string from file node</p>
6277 <pre>
6278 const char* cvReadString( const CvFileNode* node, const char* default_value=NULL );
6279 </pre><p><dl>
6280 <dt>node<dd>File node.
6281 <dt>default_value<dd>The value that is returned if <code>node</code> is NULL.
6282 </dl><p>
6283 The function <code>cvReadString</code> returns text string that is
6284 represented by the file node. If the file node is NULL, <code>default_value</code>
6285 is returned (thus, it is convenient to call the function right after
6286 <a href="#decl_cvGetFileNode">cvGetFileNode</a> without checking for NULL pointer),
6287 otherwise if the file node has type <code>CV_NODE_STR</code>,
6288 then <code>node->data.str.ptr</code> is returned, otherwise the result is not determined.</p>
6289
6290
6291 <hr><h3><a name="decl_cvReadStringByName">ReadStringByName</a></h3>
6292 <p class="Blurb">Finds file node and returns its value</p>
6293 <pre>
6294 const char* cvReadStringByName( const CvFileStorage* fs, const CvFileNode* map,
6295                                 const char* name, const char* default_value=NULL );
6296 </pre><p><dl>
6297 <dt>fs<dd>File storage.
6298 <dt>map<dd>The parent map. If it is NULL, the function searches a top-level node.
6299 <dt>name<dd>The node name.
6300 <dt>default_value<dd>The value that is returned if the file node is not found.
6301 </dl><p>
6302 The function <code>cvReadStringByName</code> is a simple
6303 superposition of <a href="#decl_cvGetFileNodeByName">cvGetFileNodeByName</a> and
6304 <a href="#decl_cvReadString">cvReadString</a>.
6305
6306
6307 <hr><h3><a name="decl_cvRead">Read</a></h3>
6308 <p class="Blurb">Decodes object and returns pointer to it</p>
6309 <pre>
6310 void* cvRead( CvFileStorage* fs, CvFileNode* node,
6311               CvAttrList* attributes=NULL );
6312 </pre><p><dl>
6313 <dt>fs<dd>File storage.
6314 <dt>node<dd>The root object node.
6315 <dt>attributes<dd>Unused parameter.
6316 </dl><p>
6317 The function <code>cvRead</code> decodes user object (creates object
6318 in a native representation from the file storage subtree) and returns it.
6319 The object to be decoded must be an instance of registered type that supports <code>read</code>
6320 method (see <a href="#decl_CvTypeInfo">CvTypeInfo</a>). Type of the object is determined by
6321 the type name that is encoded in the file. If the object is dynamic structure, it is
6322 created either in memory storage, passed to <a href="#decl_cvOpenFileStorage">cvOpenFileStorage</a>
6323 or, if NULL pointer was passed, in temporary memory storage, which is release when
6324 <a href="#decl_cvReleaseFileStorage">cvReleaseFileStorage</a> is called.
6325 Otherwise, if the object is not a dynamic structure, it is created in heap and should be
6326 released with a specialized function or using generic <a href="#decl_cvRelease">cvRelease</a>.</p>
6327
6328
6329 <hr><h3><a name="decl_cvReadByName">ReadByName</a></h3>
6330 <p class="Blurb">Finds object and decodes it</p>
6331 <pre>
6332 void* cvReadByName( CvFileStorage* fs, const CvFileNode* map,
6333                     const char* name, CvAttrList* attributes=NULL );
6334 </pre><p><dl>
6335 <dt>fs<dd>File storage.
6336 <dt>map<dd>The parent map. If it is NULL, the function searches a top-level node.
6337 <dt>name<dd>The node name.
6338 <dt>attributes<dd>Unused parameter.
6339 </dl><p>
6340 The function <code>cvReadByName</code> is a simple
6341 superposition of <a href="#decl_cvGetFileNodeByName">cvGetFileNodeByName</a> and
6342 <a href="#decl_cvRead">cvRead</a>.
6343
6344
6345 <hr><h3><a name="decl_cvReadRawData">ReadRawData</a></h3>
6346 <p class="Blurb">Reads multiple numbers</p>
6347 <pre>
6348 void cvReadRawData( const CvFileStorage* fs, const CvFileNode* src,
6349                     void* dst, const char* dt );
6350 </pre><p><dl>
6351 <dt>fs<dd>File storage.
6352 <dt>src<dd>The file node (a sequence) to read numbers from.
6353 <dt>dst<dd>Pointer to the destination array.
6354 <dt>dt<dd>Specification of each array element. It has the same format as in
6355           <a href="#decl_cvWriteRawData">cvWriteRawData</a>.
6356 </dl><p>
6357 The function <code>cvReadRawData</code> reads elements
6358 from a file node that represents a sequence of scalars</p>
6359
6360
6361 <hr><h3><a name="decl_cvStartReadRawData">StartReadRawData</a></h3>
6362 <p class="Blurb">Initializes file node sequence reader</p>
6363 <pre>
6364 void cvStartReadRawData( const CvFileStorage* fs, const CvFileNode* src,
6365                          CvSeqReader* reader );
6366 </pre><p><dl>
6367 <dt>fs<dd>File storage.
6368 <dt>src<dd>The file node (a sequence) to read numbers from.
6369 <dt>reader<dd>Pointer to the sequence reader.
6370 </dl><p>
6371 The function <code>cvStartReadRawData</code> initializes
6372 sequence reader to read data from file node. The initialized reader can be then
6373 passed to <a href="#decl_cvReadRawDataSlice">cvReadRawDataSlice</a>.</p>
6374
6375
6376 <hr><h3><a name="decl_cvReadRawDataSlice">ReadRawDataSlice</a></h3>
6377 <p class="Blurb">Initializes file node sequence reader</p>
6378 <pre>
6379 void cvReadRawDataSlice( const CvFileStorage* fs, CvSeqReader* reader,
6380                          int count, void* dst, const char* dt );
6381 </pre><p><dl>
6382 <dt>fs<dd>File storage.
6383 <dt>reader<dd>The sequence reader. Initialize it with <a href="#decl_cvStartReadRawData">cvStartReadRawData</a>.
6384 <dt>count<dd>The number of elements to read.
6385 <dt>dst<dd>Pointer to the destination array.
6386 <dt>dt<dd>Specification of each array element. It has the same format as in
6387           <a href="#decl_cvWriteRawData">cvWriteRawData</a>.
6388 </dl><p>
6389 The function <code>cvReadRawDataSlice</code> reads one
6390 or more elements from the file node, representing a sequence, to user-specified
6391 array. The total number of read sequence elements is a product of <code>total</code>
6392 and the number of components in each array element.
6393 For example, if <code>dt='2if'</code>, the function will read <code>total*3</code> sequence elements.
6394 As with any sequence, some parts of the file node sequence may be skipped or read repeatedly
6395 by repositioning the reader using <a href="#decl_cvSetSeqReaderPos">cvSetSeqReaderPos</a>.</p>
6396
6397
6398 <hr><h2><a name="cxcore_persistence_rtti">RTTI and Generic Functions</a></h2>
6399
6400
6401 <hr><h3><a name="decl_CvTypeInfo">CvTypeInfo</a></h3>
6402 <p class="Blurb">Type information</p>
6403 <pre>
6404 typedef int (CV_CDECL *CvIsInstanceFunc)( const void* struct_ptr );
6405 typedef void (CV_CDECL *CvReleaseFunc)( void** struct_dblptr );
6406 typedef void* (CV_CDECL *CvReadFunc)( CvFileStorage* storage, CvFileNode* node );
6407 typedef void (CV_CDECL *CvWriteFunc)( CvFileStorage* storage,
6408                                       const char* name,
6409                                       const void* struct_ptr,
6410                                       CvAttrList attributes );
6411 typedef void* (CV_CDECL *CvCloneFunc)( const void* struct_ptr );
6412
6413 typedef struct CvTypeInfo
6414 {
6415     int flags; /* not used */
6416     int header_size; /* sizeof(CvTypeInfo) */
6417     struct CvTypeInfo* prev; /* previous registered type in the list */
6418     struct CvTypeInfo* next; /* next registered type in the list */
6419     const char* type_name; /* type name, written to file storage */
6420
6421     /* methods */
6422     CvIsInstanceFunc is_instance; /* checks if the passed object belongs to the type */
6423     CvReleaseFunc release; /* releases object (memory etc.) */
6424     CvReadFunc read; /* reads object from file storage */
6425     CvWriteFunc write; /* writes object to file storage */
6426     CvCloneFunc clone; /* creates a copy of the object */
6427 }
6428 CvTypeInfo;
6429 </pre><p>
6430 The structure <a href="#decl_CvTypeInfo">CvTypeInfo</a> contains information about
6431 one of standard or user-defined types. Instances of the type may or may not contain
6432 pointer to the corresponding <a href="#decl_CvTypeInfo">CvTypeInfo</a> structure.
6433 In any case there is a way to find type info structure for given object - using
6434 <a href="#decl_cvTypeOf">cvTypeOf</a> function. Alternatively, type info can be
6435 found by the type name using <a href="#decl_cvFindType">cvFindType</a>, which is
6436 used when object is read from file storage. User can register a new type with
6437 <a href="#decl_cvRegisterType">cvRegisterType</a> that adds the type information structure
6438 into the beginning of the type list - thus, it is possible to create specialized types
6439 from generic standard types and override the basic methods.
6440 <p>
6441
6442
6443 <hr><h3><a name="decl_cvRegisterType">RegisterType</a></h3>
6444 <p class="Blurb">Registers new type</p>
6445 <pre>
6446 void cvRegisterType( const CvTypeInfo* info );
6447 </pre><p><dl>
6448 <dt>info<dd>Type info structure.
6449 </dl><p>
6450 The function <code>cvRegisterType</code> registers a new type,
6451 which is described by <code>info</code>. The function creates a copy of the structure,
6452 so user should delete it after calling the function.</p>
6453
6454
6455 <hr><h3><a name="decl_cvUnregisterType">UnregisterType</a></h3>
6456 <p class="Blurb">Unregisters the type</p>
6457 <pre>
6458 void cvUnregisterType( const char* type_name );
6459 </pre><p><dl>
6460 <dt>type_name<dd>Name of the unregistered type.
6461 </dl><p>
6462 The function <code>cvUnregisterType</code> unregisters the type
6463 with the specified name. If the name is unknown, it is possible to locate the type info
6464 by an instance of the type using <a href="#decl_cvTypeOf">cvTypeOf</a> or by iterating
6465 the type list, starting from <a href="#decl_cvFirstType">cvFirstType</a>, and then
6466 call <code><a href="#decl_cvUnregisterType">cvUnregisterType</a>(info->type_name)</code>.</p>
6467
6468
6469 <hr><h3><a name="decl_cvFirstType">FirstType</a></h3>
6470 <p class="Blurb">Returns the beginning of type list</p>
6471 <pre>
6472 CvTypeInfo* cvFirstType( void );
6473 </pre><p>
6474 The function <code>cvFirstType</code> returns the first type of the list
6475 of registered types. Navigation through the list can be done via <code>prev</code> and <code>next</code>
6476 fields of <a href="#decl_CvTypeInfo">CvTypeInfo</a> structure.</p>
6477
6478
6479 <hr><h3><a name="decl_cvFindType">FindType</a></h3>
6480 <p class="Blurb">Finds type by its name</p>
6481 <pre>
6482 CvTypeInfo* cvFindType( const char* type_name );
6483 </pre><p><dl>
6484 <dt>type_name<dd>Type name.
6485 </dl><p>
6486 The function <code>cvFindType</code> finds a registered type by its name.
6487 It returns NULL, if there is no type with the specified name.</p>
6488
6489
6490 <hr><h3><a name="decl_cvTypeOf">TypeOf</a></h3>
6491 <p class="Blurb">Returns type of the object</p>
6492 <pre>
6493 CvTypeInfo* cvTypeOf( const void* struct_ptr );
6494 </pre><p><dl>
6495 <dt>struct_ptr<dd>The object pointer.
6496 </dl><p>
6497 The function <code>cvTypeOf</code> finds the type of given object. It iterates through the list
6498 of registered types and calls <code>is_instance</code> function/method of every type info structure with
6499 the object until one of them return non-zero or until the whole list has been traversed. In the latter
6500 case the function returns NULL.</p>
6501
6502
6503 <hr><h3><a name="decl_cvRelease">Release</a></h3>
6504 <p class="Blurb">Releases the object</p>
6505 <pre>
6506 void cvRelease( void** struct_ptr );
6507 </pre><p><dl>
6508 <dt>struct_ptr<dd>Double pointer to the object.
6509 </dl><p>
6510 The function <code>cvRelease</code> finds the type of given object and calls
6511 <code>release</code> with the double pointer.</p>
6512
6513
6514 <hr><h3><a name="decl_cvClone">Clone</a></h3>
6515 <p class="Blurb">Makes a clone of the object</p>
6516 <pre>
6517 void* cvClone( const void* struct_ptr );
6518 </pre><p><dl>
6519 <dt>struct_ptr<dd>The object to clone.
6520 </dl><p>
6521 The function <code>cvClone</code> finds the type of given object and calls
6522 <code>clone</code> with the passed object.</p>
6523
6524
6525 <hr><h3><a name="decl_cvSave">Save</a></h3>
6526 <p class="Blurb">Saves object to file</p>
6527 <pre>
6528 void cvSave( const char* filename, const void* struct_ptr,
6529              const char* name=NULL,
6530              const char* comment=NULL,
6531              CvAttrList attributes=cvAttrList());
6532 </pre><p><dl>
6533 <dt>filename<dd>File name.
6534 <dt>struct_ptr<dd>Object to save.
6535 <dt>name<dd>Optional object name. If it is NULL, the name will be formed from <code>filename</code>.
6536 <dt>comment<dd>Optional comment to put in the beginning of the file.
6537 <dt>attributes<dd>Optional attributes passed to <a href="#decl_cvWrite">cvWrite</a>.
6538 </dl><p>
6539 The function <code>cvSave</code> saves object to file. It provides a simple interface
6540 to <a href="#decl_cvWrite">cvWrite</a>.</p>
6541
6542
6543 <hr><h3><a name="decl_cvLoad">Load</a></h3>
6544 <p class="Blurb">Loads object from file</p>
6545 <pre>
6546 void* cvLoad( const char* filename, CvMemStorage* memstorage=NULL,
6547               const char* name=NULL, const char** real_name=NULL );
6548 </pre><p><dl>
6549 <dt>filename<dd>File name.
6550 <dt>memstorage<dd>Memory storage for dynamic structures, such as <a href="#decl_CvSeq">CvSeq</a>
6551                   or <a href="#decl_CvGraph">CvGraph</a>. It is not used for matrices or images.
6552 <dt>name<dd>Optional object name. If it is NULL, the first top-level object in the storage will be loaded.
6553 <dt>real_name<dd>Optional output parameter that will contain name of the loaded object
6554                  (useful if <code>name=NULL</code>).
6555 </dl><p>
6556 The function <code>cvLoad</code> loads object from file.
6557 It provides a simple interface to <a href="#decl_cvRead">cvRead</a>.
6558 After object is loaded,
6559 the file storage is closed and all the temporary buffers are deleted. Thus, to load a dynamic structure,
6560 such as sequence, contour or graph, one should pass a valid destination
6561 memory storage to the function.</p>
6562
6563
6564 <hr><h1><a name="cxcore_misc">Miscellaneous Functions</a></h1>
6565
6566 <hr><h3><a name="decl_cvCheckArr">CheckArr</a></h3>
6567 <p class="Blurb">Checks every element of input array for invalid values</p>
6568 <pre>
6569 int  cvCheckArr( const CvArr* arr, int flags=0,
6570                  double min_val=0, double max_val=0);
6571 #define cvCheckArray cvCheckArr
6572 </pre><p><dl>
6573 <dt>arr<dd>The array to check.
6574 <dt>flags<dd>The operation flags, 0 or combination of:<br>
6575              <code>CV_CHECK_RANGE</code> - if set, the function checks that every value of
6576                               array is within [minVal,maxVal) range,
6577                               otherwise it just checks that every element
6578                               is neither NaN nor &plusmn;Infinity.<br>
6579              <code>CV_CHECK_QUIET</code> - if set, the function does not raises an
6580                               error if an element is invalid or out of range
6581 <dt>min_val<dd>The inclusive lower boundary of valid values range.
6582               It is used only if <code>CV_CHECK_RANGE</code> is set.
6583 <dt>max_val<dd>The exclusive upper boundary of valid values range.
6584               It is used only if <code>CV_CHECK_RANGE</code> is set.
6585 </dl><p>
6586 The function <code>cvCheckArr</code> checks that every array element
6587 is neither NaN nor &plusmn;Infinity.
6588 If <code>CV_CHECK_RANGE</code> is set, it also checks that every element is
6589 greater than or equal to <code>minVal</code> and less than <code>maxVal</code>.
6590 The function returns nonzero if the check succeeded, i.e. all elements
6591 are valid and within the range, and zero otherwise.
6592 In the latter case if <code>CV_CHECK_QUIET</code> flag is not set, the function
6593 raises runtime error.
6594 </p>
6595
6596
6597 <hr><h3><a name="decl_cvKMeans2">KMeans2</a></h3>
6598 <p class="Blurb">Splits set of vectors by given number of clusters</p>
6599 <pre>
6600 void cvKMeans2( const CvArr* samples, int cluster_count,
6601                 CvArr* labels, CvTermCriteria termcrit );
6602 </pre><p><dl>
6603 <dt>samples<dd>Floating-point matrix of input samples, one row per sample.
6604 <dt>cluster_count<dd>Number of clusters to split the set by.
6605 <dt>labels<dd>Output integer vector storing cluster indices for every sample.
6606 <dt>termcrit<dd>Specifies maximum number of iterations and/or accuracy (distance the centers move by
6607 between the subsequent iterations).
6608 </dl><p>
6609 The function <code>cvKMeans2</code> implements k-means algorithm that finds centers of <code>cluster_count</code> clusters
6610 and groups the input samples around the clusters. On output <code>labels(i)</code> contains a cluster index
6611 for sample stored in the i-th row of <code>samples</code> matrix.
6612 <h4>Example. Clustering random samples of k-variate Gaussian distribution</h4>
6613 <pre>
6614 #include "cxcore.h"
6615 #include "highgui.h"
6616
6617 void main( int argc, char** argv )
6618 {
6619     #define MAX_CLUSTERS 5
6620     CvScalar color_tab[MAX_CLUSTERS];
6621     IplImage* img = cvCreateImage( cvSize( 500, 500 ), 8, 3 );
6622     CvRNG rng = cvRNG(0xffffffff);
6623     
6624     color_tab[0] = CV_RGB(255,0,0);
6625     color_tab[1] = CV_RGB(0,255,0);
6626     color_tab[2] = CV_RGB(100,100,255);
6627     color_tab[3] = CV_RGB(255,0,255);
6628     color_tab[4] = CV_RGB(255,255,0);
6629
6630     cvNamedWindow( "clusters", 1 );
6631
6632     for(;;)
6633     {
6634         int k, cluster_count = cvRandInt(&rng)%MAX_CLUSTERS + 1;
6635         int i, sample_count = cvRandInt(&rng)%1000 + 1;
6636         CvMat* points = cvCreateMat( sample_count, 1, CV_32FC2 );
6637         CvMat* clusters = cvCreateMat( sample_count, 1, CV_32SC1 );
6638
6639         /* generate random sample from multivariate Gaussian distribution */
6640         for( k = 0; k &lt; cluster_count; k++ )
6641         {
6642             CvPoint center;
6643             CvMat point_chunk;
6644             center.x = cvRandInt(&rng)%img->width;
6645             center.y = cvRandInt(&rng)%img->height;
6646             cvGetRows( points, &point_chunk, k*sample_count/cluster_count,
6647                        k == cluster_count - 1 ? sample_count : (k+1)*sample_count/cluster_count );
6648             cvRandArr( &rng, &point_chunk, CV_RAND_NORMAL,
6649                        cvScalar(center.x,center.y,0,0),
6650                        cvScalar(img->width/6, img->height/6,0,0) );
6651         }
6652
6653         /* shuffle samples */
6654         for( i = 0; i &lt; sample_count/2; i++ )
6655         {
6656             CvPoint2D32f* pt1 = (CvPoint2D32f*)points->data.fl + cvRandInt(&rng)%sample_count;
6657             CvPoint2D32f* pt2 = (CvPoint2D32f*)points->data.fl + cvRandInt(&rng)%sample_count;
6658             CvPoint2D32f temp;
6659             CV_SWAP( *pt1, *pt2, temp );
6660         }
6661
6662         cvKMeans2( points, cluster_count, clusters,
6663                    cvTermCriteria( CV_TERMCRIT_EPS+CV_TERMCRIT_ITER, 10, 1.0 ));
6664
6665         cvZero( img );
6666
6667         for( i = 0; i &lt; sample_count; i++ )
6668         {
6669             CvPoint2D32f pt = ((CvPoint2D32f*)points->data.fl)[i];
6670             int cluster_idx = clusters->data.i[i];
6671             cvCircle( img, cvPointFrom32f(pt), 2, color_tab[cluster_idx], CV_FILLED );
6672         }
6673
6674         cvReleaseMat( &amp;points );
6675         cvReleaseMat( &amp;clusters );
6676
6677         cvShowImage( "clusters", img );
6678
6679         int key = cvWaitKey(0);
6680         if( key == 27 ) // 'ESC'
6681             break;
6682     }
6683 }
6684 </pre>
6685
6686
6687 <hr><h3><a name="decl_cvSeqPartition">SeqPartition</a></h3>
6688 <p class="Blurb">Splits sequence into equivalence classes</p>
6689 <pre>
6690 typedef int (CV_CDECL* CvCmpFunc)(const void* a, const void* b, void* userdata);
6691 int cvSeqPartition( const CvSeq* seq, CvMemStorage* storage, CvSeq** labels,
6692                     CvCmpFunc is_equal, void* userdata );
6693 </pre><p><dl>
6694 <dt>seq<dd>The sequence to partition.
6695 <dt>storage<dd>The storage to store the sequence of equivalence classes. If it is NULL,
6696                the function uses <code>seq->storage</code> for output labels.
6697 <dt>labels<dd>Output parameter. Double pointer to the sequence
6698               of 0-based labels of input sequence elements.
6699 <dt>is_equal<dd>The relation function that should return non-zero if the two particular sequence elements
6700                 are from the same class, and zero otherwise.
6701                 The partitioning algorithm uses transitive closure of the relation function as equivalence criteria.
6702 <dt>userdata<dd>Pointer that is transparently passed to the <code>is_equal</code> function.
6703 </dl><p>
6704 The function <code>cvSeqPartition</code> implements quadratic algorithm for splitting
6705 a set into one or more classes of equivalence. The function returns the number of equivalence classes.
6706 </p>
6707 <h4>Example. Partitioning 2d point set.</h4>
6708 <pre>
6709 #include "cxcore.h"
6710 #include "highgui.h"
6711 #include &lt;stdio.h&gt;
6712
6713 CvSeq* point_seq = 0;
6714 IplImage* canvas = 0;
6715 CvScalar* colors = 0;
6716 int pos = 10;
6717
6718 int is_equal( const void* _a, const void* _b, void* userdata )
6719 {
6720     CvPoint a = *(const CvPoint*)_a;
6721     CvPoint b = *(const CvPoint*)_b;
6722     double threshold = *(double*)userdata;
6723     return (double)(a.x - b.x)*(a.x - b.x) + (double)(a.y - b.y)*(a.y - b.y) &lt;= threshold;
6724 }
6725
6726 void on_track( int pos )
6727 {
6728     CvSeq* labels = 0;
6729     double threshold = pos*pos;
6730     int i, class_count = cvSeqPartition( point_seq, 0, &labels, is_equal, &threshold );
6731     printf("%4d classes\n", class_count );
6732     cvZero( canvas );
6733
6734     for( i = 0; i &lt; labels-&gt;total; i++ )
6735     {
6736         CvPoint pt = *(CvPoint*)cvGetSeqElem( point_seq, i, 0 );
6737         CvScalar color = colors[*(int*)cvGetSeqElem( labels, i, 0 )];
6738         cvCircle( canvas, pt, 1, color, -1 );
6739     }
6740
6741     cvShowImage( "points", canvas );
6742 }
6743
6744 int main( int argc, char** argv )
6745 {
6746     CvMemStorage* storage = cvCreateMemStorage(0);
6747     point_seq = cvCreateSeq( CV_32SC2, sizeof(CvSeq), sizeof(CvPoint), storage );
6748     CvRNG rng = cvRNG(0xffffffff);
6749
6750     int width = 500, height = 500;
6751     int i, count = 1000;
6752     canvas = cvCreateImage( cvSize(width,height), 8, 3 );
6753
6754     colors = (CvScalar*)cvAlloc( count*sizeof(colors[0]) );
6755     for( i = 0; i &lt; count; i++ )
6756     {
6757         CvPoint pt;
6758         int icolor;
6759         pt.x = cvRandInt( &rng ) % width;
6760         pt.y = cvRandInt( &rng ) % height;
6761         cvSeqPush( point_seq, &pt );
6762         icolor = cvRandInt( &rng ) | 0x00404040;
6763         colors[i] = CV_RGB(icolor & 255, (icolor >> 8)&255, (icolor >> 16)&255);
6764     }
6765
6766     cvNamedWindow( "points", 1 );
6767     cvCreateTrackbar( "threshold", "points", &pos, 50, on_track );
6768     on_track(pos);
6769     cvWaitKey(0);
6770     return 0;
6771 }
6772 </pre>
6773
6774
6775 <hr><h1><a name="cxcore_system">Error Handling and System Functions</a></h1>
6776
6777 <hr><h2><a name="cxcore_system_error">Error Handling</a></h2>
6778
6779 <p>Error handling in OpenCV is similar to IPL (Image Processing Library).
6780 In case of error functions do not return the error code. Instead, they raise
6781 an error using <a href="#decl_error_macros">CV_ERROR</a> macro that calls
6782 <a href="#decl_cvError">cvError</a> that, in its turn, sets the error status
6783 with <a href="#decl_cvSetErrStatus">cvSetErrStatus</a> and
6784 calls a standard or user-defined error handler (that can display a message box,
6785 write to log etc., see <a href="#decl_cvRedirectError">cvRedirectError</a>,
6786 <a href="#decl_cvNulDevReport">cvNulDevReport, cvStdErrReport, cvGuiBoxReport</a>).
6787 There is global variable, one per each program thread, that contains current
6788 error status (an integer value). The status can be retrieved with
6789 <a href="#decl_cvGetErrStatus">cvGetErrStatus</a> function.
6790 </p>
6791 <p>
6792 There are three modes of error handling (see <a href="#decl_cvSetErrMode">cvSetErrMode</a>
6793 and <a href="#decl_cvGetErrMode">cvGetErrMode</a>):
6794 <dl>
6795 <dt>Leaf<dd>The program is terminated after error handler is called.
6796             <em>This is the default value</em>. It is useful for debugging, as the error
6797             is signalled immediately after it occurs. However, for production systems
6798             other two methods may be preferable as they provide more control.
6799 <dt>Parent<dd>The program is not terminated, but the error handler is called.
6800               The stack is unwinded (it is done w/o using C++ exception mechanism).
6801               User may check error code after calling Cxcore function with
6802               <a href="#decl_cvGetErrStatus">cvGetErrStatus</a> and react.
6803 <dt>Silent<dd>Similar to <em>Parent</em> mode, but no error handler is called.
6804 </dl>
6805 <p>Actually, the semantics of <em>Leaf</em> and <em>Parent</em> modes is implemented by
6806 error handlers and the above description is true for <a href="#decl_cvNulDevReport">cvNulDevReport, cvStdErrReport</a>.
6807 <a href="#decl_cvNulDevReport">cvGuiBoxReport</a> behaves slightly differently,
6808 and some custom error handler may implement quite different semantics.</p>
6809
6810 <hr><h3><a name="decl_error_macros">ERROR Handling Macros</a></h3>
6811 <p class="Blurb">Macros for raising an error, checking for errors etc.</p>
6812 <pre>
6813 /* special macros for enclosing processing statements within a function and separating
6814    them from prologue (resource initialization) and epilogue (guaranteed resource release) */
6815 #define __BEGIN__       {
6816 #define __END__         goto exit; exit: ; }
6817 /* proceeds to "resource release" stage */
6818 #define EXIT            goto exit
6819
6820 /* Declares locally the function name for CV_ERROR() use */
6821 #define CV_FUNCNAME( Name )  \
6822     static char cvFuncName[] = Name
6823
6824 /* Raises an error within the current context */
6825 #define CV_ERROR( Code, Msg )                                       \
6826 {                                                                   \
6827      cvError( (Code), cvFuncName, Msg, __FILE__, __LINE__ );        \
6828      EXIT;                                                          \
6829 }
6830
6831 /* Checks status after calling CXCORE function */
6832 #define CV_CHECK()                                                  \
6833 {                                                                   \
6834     if( cvGetErrStatus() &lt; 0 )                                   \
6835         CV_ERROR( CV_StsBackTrace, "Inner function failed." );      \
6836 }
6837
6838 /* Provides shorthand for CXCORE function call and CV_CHECK() */
6839 #define CV_CALL( Statement )                                        \
6840 {                                                                   \
6841     Statement;                                                      \
6842     CV_CHECK();                                                     \
6843 }
6844
6845 /* Checks some condition in both debug and release configurations */
6846 #define CV_ASSERT( Condition )                                          \
6847 {                                                                       \
6848     if( !(Condition) )                                                  \
6849         CV_ERROR( CV_StsInternal, "Assertion: " #Condition " failed" ); \
6850 }
6851
6852 /* these macros are similar to their CV_... counterparts, but they
6853    do not need exit label nor cvFuncName to be defined */
6854 #define OPENCV_ERROR(status,func_name,err_msg) ...
6855 #define OPENCV_ERRCHK(func_name,err_msg) ...
6856 #define OPENCV_ASSERT(condition,func_name,err_msg) ...
6857 #define OPENCV_CALL(statement) ...
6858 </pre>
6859 Instead of a discussion, here are the documented example
6860 of typical CXCORE function and the example of the function use.
6861 <h4><a name="decl_error_handling_sample">Use of Error Handling Macros</a></h4>
6862 <pre>
6863 #include "cxcore.h"
6864 #include &lt;stdio.h&gt;
6865
6866 void cvResizeDCT( CvMat* input_array, CvMat* output_array )
6867 {
6868     CvMat* temp_array = 0; // declare pointer that should be released anyway.
6869
6870     CV_FUNCNAME( "cvResizeDCT" ); // declare cvFuncName
6871
6872     __BEGIN__; // start processing. There may be some declarations just after this macro,
6873                // but they couldn't be accessed from the epilogue.
6874
6875     if( !CV_IS_MAT(input_array) || !CV_IS_MAT(output_array) )
6876         // use CV_ERROR() to raise an error
6877         CV_ERROR( CV_StsBadArg, "input_array or output_array are not valid matrices" );
6878
6879     // some restrictions that are going to be removed later, may be checked with CV_ASSERT()
6880     CV_ASSERT( input_array->rows == 1 && output_array->rows == 1 );
6881
6882     // use CV_CALL for safe function call
6883     CV_CALL( temp_array = cvCreateMat( input_array->rows, MAX(input_array->cols,output_array->cols),
6884                                        input_array->type ));
6885
6886     if( output_array->cols &gt; input_array->cols )
6887         CV_CALL( cvZero( temp_array ));
6888
6889     temp_array->cols = input_array->cols;
6890     CV_CALL( cvDCT( input_array, temp_array, CV_DXT_FORWARD ));
6891     temp_array->cols = output_array->cols;
6892     CV_CALL( cvDCT( temp_array, output_array, CV_DXT_INVERSE ));
6893     CV_CALL( cvScale( output_array, output_array, 1./sqrt((double)input_array->cols*output_array->cols), 0 ));
6894
6895     __END__; // finish processing. Epilogue follows after the macro.
6896
6897     // release temp_array. If temp_array has not been allocated before an error occurred, cvReleaseMat
6898     // takes care of it and does nothing in this case.
6899     cvReleaseMat( &temp_array );
6900 }
6901
6902
6903 int main( int argc, char** argv )
6904 {
6905     CvMat* src = cvCreateMat( 1, 512, CV_32F );
6906 #if 1 /* no errors */
6907     CvMat* dst = cvCreateMat( 1, 256, CV_32F );
6908 #else
6909     CvMat* dst = 0; /* test error processing mechanism */
6910 #endif
6911     cvSet( src, cvRealScalar(1.), 0 );
6912 #if 0 /* change 0 to 1 to suppress error handler invocation */
6913     cvSetErrMode( CV_ErrModeSilent );
6914 #endif
6915     cvResizeDCT( src, dst ); // if some error occurs, the message box will pop up, or a message will be
6916                              // written to log, or some user-defined processing will be done
6917     if( cvGetErrStatus() &lt; 0 )
6918         printf("Some error occurred" );
6919     else
6920         printf("Everything is OK" );
6921     return 0;
6922 }
6923 </pre>
6924
6925
6926 <hr><h3><a name="decl_cvGetErrStatus">GetErrStatus</a></h3>
6927 <p class="Blurb">Returns the current error status</p>
6928 <pre>
6929 int cvGetErrStatus( void );
6930 </pre><p>
6931 The function <code>cvGetErrStatus</code> returns the current error status -
6932 the value set with the last <a href="#decl_cvSetErrStatus">cvSetErrStatus</a> call. Note, that
6933 in <em>Leaf</em> mode the program terminates immediately after error occurred, so to
6934 always get control after the function call, one should call <a href="#decl_cvSetErrMode">cvSetErrMode</a>
6935 and set <em>Parent</em> or <em>Silent</em> error mode.
6936 </p>
6937
6938
6939 <hr><h3><a name="decl_cvSetErrStatus">SetErrStatus</a></h3>
6940 <p class="Blurb">Sets the error status</p>
6941 <pre>
6942 void cvSetErrStatus( int status );
6943 </pre><p><dl>
6944 <dt>status<dd>The error status.
6945 </dl><p>
6946 The function <code>cvSetErrStatus</code> sets the error status to
6947 the specified value. Mostly, the function is used to reset the error status (set to it <code>CV_StsOk</code>)
6948 to recover after error. In other cases it is more natural to call <a href="#decl_cvError">cvError</a> or
6949 <a href="#decl_error_macros">CV_ERROR</a>.
6950 </p>
6951
6952
6953 <hr><h3><a name="decl_cvGetErrMode">GetErrMode</a></h3>
6954 <p class="Blurb">Returns the current error mode</p>
6955 <pre>
6956 int cvGetErrMode( void );
6957 </pre><p>
6958 The function <code>cvGetErrMode</code> returns the current error mode -
6959 the value set with the last <a href="#decl_cvSetErrMode">cvSetErrMode</a> call.
6960 </p>
6961
6962
6963 <hr><h3><a name="decl_cvSetErrMode">SetErrMode</a></h3>
6964 <p class="Blurb">Sets the error mode</p>
6965 <pre>
6966 #define CV_ErrModeLeaf    0
6967 #define CV_ErrModeParent  1
6968 #define CV_ErrModeSilent  2
6969 int cvSetErrMode( int mode );
6970 </pre><p><dl>
6971 <dt>mode<dd>The error mode.
6972 </dl><p>
6973 The function <code>cvSetErrMode</code> sets the specified error mode.
6974 For description of different error modes see the beginning of the <a href="#cxcore_system_error">section</a>.
6975 </p>
6976
6977
6978 <hr><h3><a name="decl_cvError">Error</a></h3>
6979 <p class="Blurb">Raises an error</p>
6980 <pre>
6981 int cvError( int status, const char* func_name,
6982              const char* err_msg, const char* file_name, int line );
6983 </pre><p><dl>
6984 <dt>status<dd>The error status.
6985 <dt>func_name<dd>Name of the function where the error occurred.
6986 <dt>err_msg<dd>Additional information/diagnostics about the error.
6987 <dt>file_name<dd>Name of the file where the error occurred.
6988 <dt>line<dd>Line number, where the error occurred.
6989 </dl><p>
6990 The function <code>cvError</code> sets the error status
6991 to the specified value (via <a href="#decl_cvSetErrStatus">cvSetErrStatus</a>)
6992 and, if the error mode is not <em>Silent</em>, calls the error handler.</p>
6993
6994
6995 <hr><h3><a name="decl_cvErrorStr">ErrorStr</a></h3>
6996 <p class="Blurb">Returns textual description of error status code</p>
6997 <pre>
6998 const char* cvErrorStr( int status );
6999 </pre><p><dl>
7000 <dt>status<dd>The error status.
7001 </dl><p>
7002 The function <code>cvErrorStr</code> returns the textual description
7003 for the specified error status code. In case of unknown status the function returns NULL pointer.
7004 </p>
7005
7006
7007 <hr><h3><a name="decl_cvRedirectError">RedirectError</a></h3>
7008 <p class="Blurb">Sets a new error handler</p>
7009 <pre>
7010 typedef int (CV_CDECL *CvErrorCallback)( int status, const char* func_name,
7011                     const char* err_msg, const char* file_name, int line );
7012
7013 CvErrorCallback cvRedirectError( CvErrorCallback error_handler,
7014                                  void* userdata=NULL, void** prev_userdata=NULL );
7015 </pre><p><dl>
7016 <dt>error_handler<dd>The new error_handler.
7017 <dt>userdata<dd>Arbitrary pointer that is transparently passed to the error handler.
7018 <dt>prev_userdata<dd>Pointer to the previously assigned user data pointer.
7019 </dl><p>
7020 The function <code>cvRedirectError</code> sets a new error handler that
7021 can be one of <a href="#decl_cvNulDevReport">standard handlers</a> or a custom handler that has
7022 the certain interface. The handler takes the same parameters as <a href="#decl_cvError">cvError</a>
7023 function. If the handler returns non-zero value, the program is terminated, otherwise, it continues.
7024 The error handler may check the current error mode with <a href="#decl_cvGetErrMode">cvGetErrMode</a>
7025 to make a decision.
7026 </p>
7027
7028
7029 <hr><h3><a name="decl_cvNulDevReport">cvNulDevReport</a>
7030 <a name="decl_cvStdErrReport">cvStdErrReport</a>
7031 <a name="decl_cvGuiBoxReport">cvGuiBoxReport</a></h3>
7032 <p class="Blurb">Provide standard error handling</p>
7033 <pre>
7034 int cvNulDevReport( int status, const char* func_name,
7035                     const char* err_msg, const char* file_name,
7036                     int line, void* userdata );
7037
7038 int cvStdErrReport( int status, const char* func_name,
7039                     const char* err_msg, const char* file_name,
7040                     int line, void* userdata );
7041
7042 int cvGuiBoxReport( int status, const char* func_name,
7043                     const char* err_msg, const char* file_name,
7044                     int line, void* userdata );
7045 </pre><p><dl>
7046 <dt>status<dd>The error status.
7047 <dt>func_name<dd>Name of the function where the error occurred.
7048 <dt>err_msg<dd>Additional information/diagnostics about the error.
7049 <dt>file_name<dd>Name of the file where the error occurred.
7050 <dt>line<dd>Line number, where the error occurred.
7051 <dt>userdata<dd>Pointer to the user data. Ignored by the standard handlers.
7052 </dl><p>
7053 The functions <code>cvNullDevReport, cvStdErrReport</code> and <code>cvGuiBoxReport</code>
7054 provide standard error handling. <code>cvGuiBoxReport</code> is the default
7055 error handler on Win32 systems, <code>cvStdErrReport</code> - on other systems.
7056 <code>cvGuiBoxReport</code> pops up message box with the error description and
7057 suggest a few options. Below is the sample message box that may be received with the
7058 <a name="decl_error_handling_sample">sample code</a> above, if one introduce an error as described
7059 in the sample</p>
7060 <h4>Error Message Box</h4>
7061 <p>
7062 <img align="center" src="pics/errmsg.png" >
7063 </p>
7064 If the error handler is set <code>cvStdErrReport</code>, the above message will
7065 be printed to standard error output and program will be terminated or continued, depending on the
7066 current error mode.</p>
7067 <h4>Error Message printed to Standard Error Output (in <em>Leaf</em> mode)</h4>
7068 <pre>
7069 OpenCV ERROR: Bad argument (input_array or output_array are not valid matrices)
7070         in function cvResizeDCT, D:\User\VP\Projects\avl_proba\a.cpp(75)
7071 Terminating the application...
7072 </pre>
7073
7074
7075 <hr><h2><a name="cxcore_system_sys">System and Utility Functions</a></h2>
7076
7077 <hr><h3><a name="decl_cvAlloc">Alloc</a></h3>
7078 <p class="Blurb">Allocates memory buffer</p>
7079 <pre>
7080 void* cvAlloc( size_t size );
7081 </pre><p><dl>
7082 <dt>size<dd>Buffer size in bytes.
7083 </dl><p>
7084 The function <code>cvAlloc</code> allocates <code>size</code> bytes and
7085 returns pointer to the allocated buffer. In case of error
7086 the function reports an error and returns NULL pointer.
7087 By default cvAlloc calls icvAlloc which itself calls malloc,
7088 however it is possible to assign user-defined memory allocation/deallocation
7089 functions using <a href="#decl_cvSetMemoryManager">cvSetMemoryManager</a> function.
7090 </p>
7091
7092
7093 <hr><h3><a name="decl_cvFree">Free</a></h3>
7094 <p class="Blurb">Deallocates memory buffer</p>
7095 <pre>
7096 void cvFree( T** ptr );
7097 </pre><p><dl>
7098 <dt>buffer<dd>Double pointer to released buffer.
7099 </dl><p>
7100 The function <code>cvFree</code> deallocates memory buffer allocated by <a href="#decl_cvAlloc">cvAlloc</a>.
7101 It clears the pointer to buffer upon exit, that is why the double pointer is
7102 used. If *buffer is already NULL, the function does nothing
7103 </p>
7104
7105
7106 <hr><h3><a name="decl_cvGetTickCount">GetTickCount</a></h3>
7107 <p class="Blurb">Returns number of tics</p>
7108 <pre>
7109 int64 cvGetTickCount( void );
7110 </pre><p>
7111 The function <code>cvGetTickCount</code> returns number of tics
7112 starting from some platform-dependent event (number of CPU ticks from the startup, number of milliseconds
7113 from 1970th year etc.). The function is useful for accurate measurement of
7114 a function/user-code execution time. To convert the number of tics to time units, use
7115 <a href="#decl_cvGetTickFrequency">cvGetTickFrequency</a>.</p>
7116
7117 <hr><h3><a name="decl_cvGetTickFrequency">GetTickFrequency</a></h3>
7118 <p class="Blurb">Returns number of tics per microsecond</p>
7119 <pre>
7120 double cvGetTickFrequency( void );
7121 </pre><p>
7122 The function <code>cvGetTickFrequency</code> returns number of tics
7123 per microsecond. Thus, the quotient of <a href="#decl_cvGetTickCount">cvGetTickCount</a>() and
7124 <a href="#decl_cvGetTickFrequency">cvGetTickFrequency</a>() will give a number of microseconds
7125 starting from the platform-dependent event.</p>
7126
7127
7128 <hr><h3><a name="decl_cvRegisterModule">RegisterModule</a></h3>
7129 <p class="Blurb">Registers another module</p>
7130 <pre>
7131 typedef struct CvPluginFuncInfo
7132 {
7133     void** func_addr;
7134     void* default_func_addr;
7135     const char* func_names;
7136     int search_modules;
7137     int loaded_from;
7138 }
7139 CvPluginFuncInfo;
7140
7141 typedef struct CvModuleInfo
7142 {
7143     struct CvModuleInfo* next;
7144     const char* name;
7145     const char* version;
7146     CvPluginFuncInfo* func_tab;
7147 }
7148 CvModuleInfo;
7149
7150 int cvRegisterModule( const CvModuleInfo* module_info );
7151 </pre><p><dl>
7152 <dt>module_info<dd>Information about the module.
7153 </dl><p>
7154 The function <code>cvRegisterModule</code> adds module to the list of registered
7155 modules. After the module is registered, information about it can be retrieved
7156 using <a href="#decl_cvGetModuleInfo">cvGetModuleInfo</a> function. Also, the registered module
7157 makes full use of optimized plugins (IPP, MKL, ...), supported by CXCORE.
7158 CXCORE itself, CV (computer vision), CVAUX (auxiliary computer vision) and HIGHGUI
7159 (visualization & image/video acquisition) are examples of modules. Registration is usually done
7160 then the shared library is loaded. See cxcore/src/cxswitcher.cpp and cv/src/cvswitcher.cpp
7161 for details, how registration is done and
7162 look at cxcore/src/cxswitcher.cpp, cxcore/src/_cxipp.h on how IPP and MKL are connected to the modules.</p>
7163
7164
7165 <hr><h3><a name="decl_cvGetModuleInfo">GetModuleInfo</a></h3>
7166 <p class="Blurb">Retrieves information about the registered module(s) and plugins</p>
7167 <pre>
7168 void  cvGetModuleInfo( const char* module_name,
7169                        const char** version,
7170                        const char** loaded_addon_plugins );
7171 </pre><p><dl>
7172 <dt>module_name<dd>Name of the module of interest, or NULL, which means all the modules.
7173 <dt>version<dd>The output parameter. Information about the module(s), including version.
7174 <dt>loaded_addon_plugins<dd>The list of names and versions of the optimized plugins that CXCORE was
7175         able to find and load.
7176 </dl><p>
7177 The function <code>cvGetModuleInfo</code> returns information about one of
7178 or all of the registered modules. The returned information is stored inside the libraries, so
7179 user should not deallocate or modify the returned text strings.</p>
7180
7181
7182 <hr><h3><a name="decl_cvUseOptimized">UseOptimized</a></h3>
7183 <p class="Blurb">Switches between optimized/non-optimized modes</p>
7184 <pre>
7185 int cvUseOptimized( int on_off );
7186 </pre><p><dl>
7187 <dt>on_off<dd>Use optimized (&lt;&gt;0) or not (0).
7188 </dl><p>
7189 The function <code>cvUseOptimized</code> switches between the mode, where
7190 only pure C implementations from cxcore, OpenCV etc. are used, and the mode, where
7191 IPP and MKL functions are used if available. When <code>cvUseOptimized(0)</code> is called,
7192 all the optimized libraries are unloaded. The function may be useful for debugging, IPP&MKL upgrade
7193 on the fly, online speed comparisons etc. It returns the number of optimized functions loaded.
7194 Note that by default the optimized plugins are loaded, so it is not necessary to
7195 call <code>cvUseOptimized(1)</code> in the beginning of the program (actually, it will only
7196 increase the startup time)</p>
7197
7198
7199 <hr><h3><a name="decl_cvSetMemoryManager">SetMemoryManager</a></h3>
7200 <p class="Blurb">Assigns custom/default memory managing functions</p>
7201 <pre>
7202 typedef void* (CV_CDECL *CvAllocFunc)(size_t size, void* userdata);
7203 typedef int (CV_CDECL *CvFreeFunc)(void* pptr, void* userdata);
7204
7205 void cvSetMemoryManager( CvAllocFunc alloc_func=NULL,
7206                          CvFreeFunc free_func=NULL,
7207                          void* userdata=NULL );
7208 </pre><p><dl>
7209 <dt>alloc_func<dd>Allocation function; the interface is similar to <code>malloc</code>, except that <code>userdata</code>
7210               may be used to determine the context.
7211 <dt>free_func<dd>Deallocation function; the interface is similar to <code>free</code>.
7212 <dt>userdata<dd>User data that is transparently passed to the custom functions.
7213 </dl><p>
7214 The function <code>cvSetMemoryManager</code>
7215 sets user-defined memory management functions (replacements for malloc and free) that
7216 will be called by cvAlloc, cvFree and higher-level functions (e.g. cvCreateImage).
7217 Note, that the function should be called when there is data allocated using <a href="#decl_cvAlloc">cvAlloc<a>.
7218 Also, to avoid infinite recursive calls, it is not allowed to call <a href="#decl_cvAlloc">cvAlloc</a>
7219 and <a href="#decl_cvFree">cvFree</a> from the custom allocation/deallocation functions.</p>
7220 <p>
7221 If <code>alloc_func</code> and <code>free_func</code> pointers are <code>NULL</code>,
7222 the default memory managing functions are restored.</p>
7223
7224
7225 <hr><h3><a name="decl_cvSetIPLAllocators">SetIPLAllocators</a></h3>
7226 <p class="Blurb">Switches to IPL functions for image allocation/deallocation</p>
7227 <pre>
7228 typedef IplImage* (CV_STDCALL* Cv_iplCreateImageHeader)
7229                             (int,int,int,char*,char*,int,int,int,int,int,
7230                             IplROI*,IplImage*,void*,IplTileInfo*);
7231 typedef void (CV_STDCALL* Cv_iplAllocateImageData)(IplImage*,int,int);
7232 typedef void (CV_STDCALL* Cv_iplDeallocate)(IplImage*,int);
7233 typedef IplROI* (CV_STDCALL* Cv_iplCreateROI)(int,int,int,int,int);
7234 typedef IplImage* (CV_STDCALL* Cv_iplCloneImage)(const IplImage*);
7235
7236 void cvSetIPLAllocators( Cv_iplCreateImageHeader create_header,
7237                          Cv_iplAllocateImageData allocate_data,
7238                          Cv_iplDeallocate deallocate,
7239                          Cv_iplCreateROI create_roi,
7240                          Cv_iplCloneImage clone_image );
7241
7242 #define CV_TURN_ON_IPL_COMPATIBILITY()                                  \
7243     cvSetIPLAllocators( iplCreateImageHeader, iplAllocateImage,         \
7244                         iplDeallocate, iplCreateROI, iplCloneImage )
7245 </pre><p><dl>
7246 <dt>create_header<dd>Pointer to iplCreateImageHeader.
7247 <dt>allocate_data<dd>Pointer to iplAllocateImage.
7248 <dt>deallocate<dd>Pointer to iplDeallocate.
7249 <dt>create_roi<dd>Pointer to iplCreateROI.
7250 <dt>clone_image<dd>Pointer to iplCloneImage.
7251 </dl><p>
7252 The function <code>cvSetIPLAllocators</code>
7253 makes CXCORE to use IPL functions for image allocation/deallocation operations.
7254 For convenience, there is the wrapping macro <code>CV_TURN_ON_IPL_COMPATIBILITY</code>.
7255 The function is useful for applications where IPL and CXCORE/OpenCV are used together and still
7256 there are calls to <code>iplCreateImageHeader</code> etc. The function is not necessary if
7257 IPL is called only for data processing and all the allocation/deallocation is done by CXCORE,
7258 or if all the allocation/deallocation is done by IPL and some of OpenCV functions are used to
7259 process the data.</p>
7260
7261
7262 <hr><h3><a name="decl_cvGetNumThreads">GetNumThreads</a></h3>
7263 <p class="Blurb">Returns the current number of threads used</p>
7264 <pre>
7265 int cvGetNumThreads(void);
7266 </pre>
7267 <p>
7268 The function <code>cvGetNumThreads</code> return the current number of threads
7269 that are used by parallelized (via OpenMP) OpenCV functions.</p>
7270
7271
7272 <hr><h3><a name="decl_cvSetNumThreads">SetNumThreads</a></h3>
7273 <p class="Blurb">Sets the number of threads</p>
7274 <pre>
7275 void cvSetNumThreads( int threads=0 );
7276 </pre><p><dl>
7277 <dt>threads<dd>The number of threads.
7278 </dl><p>
7279 The function <code>cvSetNumThreads</code> sets the number of threads
7280 that are used by parallelized OpenCV functions. When the argument
7281 is zero or negative, and at the beginning of the program,
7282 the number of threads is set to the number of processors in the system,
7283 as returned by the function <code>omp_get_num_procs()</code> from OpenMP runtime.
7284 </p>
7285
7286
7287 <hr><h3><a name="decl_cvGetThreadNum">GetThreadNum</a></h3>
7288 <p class="Blurb">Returns index of the current thread</p>
7289 <pre>
7290 int cvGetThreadNum( void );
7291 </pre><p>
7292 The function <code>cvGetThreadNum</code> returns the index, from 0 to
7293 <a href="#decl_cvGetNumThreads">cvGetNumThreads</a>()-1, of the thread that called the function.
7294 It is a wrapper for the function <code>omp_get_thread_num()</code> from OpenMP runtime.
7295 The retrieved index may be used to access local-thread data inside the parallelized code fragments.
7296 </p>
7297
7298
7299 <hr><h1><a name="cxcore_func_index">Alphabetical List of Functions</a></h1>
7300
7301 <hr><h3>A</h3>
7302 <table width="100%">
7303 <tr>
7304 <td width="25%"><a href="#decl_cvAbsDiff">AbsDiff</a></td>
7305 <td width="25%"><a href="#decl_cvAddWeighted">AddWeighted</a></td>
7306 <td width="25%"><a href="#decl_cvAvg">Avg</a></td>
7307 </tr>
7308 <tr>
7309 <td width="25%"><a href="#decl_cvAbsDiffS">AbsDiffS</a></td>
7310 <td width="25%"><a href="#decl_cvAlloc">Alloc</a></td>
7311 <td width="25%"><a href="#decl_cvAvgSdv">AvgSdv</a></td>
7312 </tr>
7313 <tr>
7314 <td width="25%"><a href="#decl_cvAdd">Add</a></td>
7315 <td width="25%"><a href="#decl_cvAnd">And</a></td>
7316 <td width="25%%"></td>
7317 </tr>
7318 <tr>
7319 <td width="25%"><a href="#decl_cvAddS">AddS</a></td>
7320 <td width="25%"><a href="#decl_cvAndS">AndS</a></td>
7321 <td width="25%%"></td>
7322 </tr>
7323 </table>
7324 <hr><h3>B</h3>
7325 <table width="100%">
7326 <tr>
7327 <td width="25%"><a href="#decl_cvBackProjectPCA">BackProjectPCA</a></td>
7328 <td width="25%%"></td>
7329 <td width="25%%"></td>
7330 </tr>
7331 </table>
7332 <hr><h3>C</h3>
7333 <table width="100%">
7334 <tr>
7335 <td width="25%"><a href="#decl_cvCalcCovarMatrix">CalcCovarMatrix</a></td>
7336 <td width="25%"><a href="#decl_cvCloneGraph">CloneGraph</a></td>
7337 <td width="25%"><a href="#decl_cvCreateGraph">CreateGraph</a></td>
7338 </tr>
7339 <tr>
7340 <td width="25%"><a href="#decl_cvCalcPCA">CalcPCA</a></td>
7341 <td width="25%"><a href="#decl_cvCloneImage">CloneImage</a></td>
7342 <td width="25%"><a href="#decl_cvCreateGraphScanner">CreateGraphScanner</a></td>
7343 </tr>
7344 <tr>
7345 <td width="25%"><a href="#decl_cvCartToPolar">CartToPolar</a></td>
7346 <td width="25%"><a href="#decl_cvCloneMat">CloneMat</a></td>
7347 <td width="25%"><a href="#decl_cvCreateImage">CreateImage</a></td>
7348 </tr>
7349 <tr>
7350 <td width="25%"><a href="#decl_cvCbrt">Cbrt</a></td>
7351 <td width="25%"><a href="#decl_cvCloneMatND">CloneMatND</a></td>
7352 <td width="25%"><a href="#decl_cvCreateImageHeader">CreateImageHeader</a></td>
7353 </tr>
7354 <tr>
7355 <td width="25%"><a href="#decl_cvCheckArr">CheckArr</a></td>
7356 <td width="25%"><a href="#decl_cvCloneSeq">CloneSeq</a></td>
7357 <td width="25%"><a href="#decl_cvCreateMat">CreateMat</a></td>
7358 </tr>
7359 <tr>
7360 <td width="25%"><a href="#decl_cvCircle">Circle</a></td>
7361 <td width="25%"><a href="#decl_cvCloneSparseMat">CloneSparseMat</a></td>
7362 <td width="25%"><a href="#decl_cvCreateMatHeader">CreateMatHeader</a></td>
7363 </tr>
7364 <tr>
7365 <td width="25%"><a href="#decl_cvClearGraph">ClearGraph</a></td>
7366 <td width="25%"><a href="#decl_cvCmp">Cmp</a></td>
7367 <td width="25%"><a href="#decl_cvCreateMatND">CreateMatND</a></td>
7368 </tr>
7369 <tr>
7370 <td width="25%"><a href="#decl_cvClearMemStorage">ClearMemStorage</a></td>
7371 <td width="25%"><a href="#decl_cvCmpS">CmpS</a></td>
7372 <td width="25%"><a href="#decl_cvCreateMatNDHeader">CreateMatNDHeader</a></td>
7373 </tr>
7374 <tr>
7375 <td width="25%"><a href="#decl_cvClearND">ClearND</a></td>
7376 <td width="25%"><a href="#decl_cvConvertScale">ConvertScale</a></td>
7377 <td width="25%"><a href="#decl_cvCreateMemStorage">CreateMemStorage</a></td>
7378 </tr>
7379 <tr>
7380 <td width="25%"><a href="#decl_cvClearSeq">ClearSeq</a></td>
7381 <td width="25%"><a href="#decl_cvConvertScaleAbs">ConvertScaleAbs</a></td>
7382 <td width="25%"><a href="#decl_cvCreateSeq">CreateSeq</a></td>
7383 </tr>
7384 <tr>
7385 <td width="25%"><a href="#decl_cvClearSet">ClearSet</a></td>
7386 <td width="25%"><a href="#decl_cvCopy">Copy</a></td>
7387 <td width="25%"><a href="#decl_cvCreateSet">CreateSet</a></td>
7388 </tr>
7389 <tr>
7390 <td width="25%"><a href="#decl_cvClipLine">ClipLine</a></td>
7391 <td width="25%"><a href="#decl_cvCountNonZero">CountNonZero</a></td>
7392 <td width="25%"><a href="#decl_cvCreateSparseMat">CreateSparseMat</a></td>
7393 </tr>
7394 <tr>
7395 <td width="25%"><a href="#decl_cvClipLine">ClipLine</a></td>
7396 <td width="25%"><a href="#decl_cvCreateChildMemStorage">CreateChildMemStorage</a></td>
7397 <td width="25%"><a href="#decl_cvCrossProduct">CrossProduct</a></td>
7398 </tr>
7399 <tr>
7400 <td width="25%"><a href="#decl_cvClone">Clone</a></td>
7401 <td width="25%"><a href="#decl_cvCreateData">CreateData</a></td>
7402 <td width="25%"><a href="#decl_cvCvtSeqToArray">CvtSeqToArray</a></td>
7403 </tr>
7404 </table>
7405 <hr><h3>D</h3>
7406 <table width="100%">
7407 <tr>
7408 <td width="25%"><a href="#decl_cvDCT">DCT</a></td>
7409 <td width="25%"><a href="#decl_cvDet">Det</a></td>
7410 <td width="25%"><a href="#decl_cvDrawContours">DrawContours</a></td>
7411 </tr>
7412 <tr>
7413 <td width="25%"><a href="#decl_cvDFT">DFT</a></td>
7414 <td width="25%"><a href="#decl_cvDiv">Div</a></td>
7415 <td width="25%%"></td>
7416 </tr>
7417 <tr>
7418 <td width="25%"><a href="#decl_cvDecRefData">DecRefData</a></td>
7419 <td width="25%"><a href="#decl_cvDotProduct">DotProduct</a></td>
7420 <td width="25%%"></td>
7421 </tr>
7422 </table>
7423 <hr><h3>E</h3>
7424 <table width="100%">
7425 <tr>
7426 <td width="25%"><a href="#decl_cvEigenVV">EigenVV</a></td>
7427 <td width="25%"><a href="#decl_cvEllipseBox">EllipseBox</a></td>
7428 <td width="25%"><a href="#decl_cvError">Error</a></td>
7429 </tr>
7430 <tr>
7431 <td width="25%"><a href="#decl_cvEllipse">Ellipse</a></td>
7432 <td width="25%"><a href="#decl_cvEndWriteSeq">EndWriteSeq</a></td>
7433 <td width="25%"><a href="#decl_cvErrorStr">ErrorStr</a></td>
7434 </tr>
7435 <tr>
7436 <td width="25%"><a href="#decl_cvEllipse2Poly">Ellipse2Poly</a></td>
7437 <td width="25%"><a href="#decl_cvEndWriteStruct">EndWriteStruct</a></td>
7438 <td width="25%"><a href="#decl_cvExp">Exp</a></td>
7439 </tr>
7440 </table>
7441 <hr><h3>F</h3>
7442 <table width="100%">
7443 <tr>
7444 <td width="25%"><a href="#decl_cvFastArctan">FastArctan</a></td>
7445 <td width="25%"><a href="#decl_cvFindGraphEdgeByPtr">FindGraphEdgeByPtr</a></td>
7446 <td width="25%"><a href="#decl_cvFlushSeqWriter">FlushSeqWriter</a></td>
7447 </tr>
7448 <tr>
7449 <td width="25%"><a href="#decl_cvFillConvexPoly">FillConvexPoly</a></td>
7450 <td width="25%"><a href="#decl_cvFindType">FindType</a></td>
7451 <td width="25%"><a href="#decl_cvFree">Free</a></td>
7452 </tr>
7453 <tr>
7454 <td width="25%"><a href="#decl_cvFillPoly">FillPoly</a></td>
7455 <td width="25%"><a href="#decl_cvFirstType">FirstType</a></td>
7456 <td width="25%%"></td>
7457 </tr>
7458 <tr>
7459 <td width="25%"><a href="#decl_cvFindGraphEdge">FindGraphEdge</a></td>
7460 <td width="25%"><a href="#decl_cvFlip">Flip</a></td>
7461 <td width="25%%"></td>
7462 </tr>
7463 </table>
7464 <hr><h3>G</h3>
7465 <table width="100%">
7466 <tr>
7467 <td width="25%"><a href="#decl_cvGEMM">GEMM</a></td>
7468 <td width="25%"><a href="#decl_cvGetMat">GetMat</a></td>
7469 <td width="25%"><a href="#decl_cvGetTickCount">GetTickCount</a></td>
7470 </tr>
7471 <tr>
7472 <td width="25%"><a href="#decl_cvGet*D">Get*D</a></td>
7473 <td width="25%"><a href="#decl_cvGetModuleInfo">GetModuleInfo</a></td>
7474 <td width="25%"><a href="#decl_cvGetTickFrequency">GetTickFrequency</a></td>
7475 </tr>
7476 <tr>
7477 <td width="25%"><a href="#decl_cvGetCol">GetCol</a></td>
7478 <td width="25%"><a href="#decl_cvGetNextSparseNode">GetNextSparseNode</a></td>
7479 <td width="25%"><a href="#decl_cvGraphAddEdge">GraphAddEdge</a></td>
7480 </tr>
7481 <tr>
7482 <td width="25%"><a href="#decl_cvGetDiag">GetDiag</a></td>
7483 <td width="25%"><a href="#decl_cvGetNumThreads">GetNumThreads</a></td>
7484 <td width="25%"><a href="#decl_cvGraphAddEdgeByPtr">GraphAddEdgeByPtr</a></td>
7485 </tr>
7486 <tr>
7487 <td width="25%"><a href="#decl_cvGetDims">GetDims</a></td>
7488 <td width="25%"><a href="#decl_cvGetOptimalDFTSize">GetOptimalDFTSize</a></td>
7489 <td width="25%"><a href="#decl_cvGraphAddVtx">GraphAddVtx</a></td>
7490 </tr>
7491 <tr>
7492 <td width="25%"><a href="#decl_cvGetElemType">GetElemType</a></td>
7493 <td width="25%"><a href="#decl_cvGetRawData">GetRawData</a></td>
7494 <td width="25%"><a href="#decl_cvGraphEdgeIdx">GraphEdgeIdx</a></td>
7495 </tr>
7496 <tr>
7497 <td width="25%"><a href="#decl_cvGetErrMode">GetErrMode</a></td>
7498 <td width="25%"><a href="#decl_cvGetReal*D">GetReal*D</a></td>
7499 <td width="25%"><a href="#decl_cvGraphRemoveEdge">GraphRemoveEdge</a></td>
7500 </tr>
7501 <tr>
7502 <td width="25%"><a href="#decl_cvGetErrStatus">GetErrStatus</a></td>
7503 <td width="25%"><a href="#decl_cvGetRootFileNode">GetRootFileNode</a></td>
7504 <td width="25%"><a href="#decl_cvGraphRemoveEdgeByPtr">GraphRemoveEdgeByPtr</a></td>
7505 </tr>
7506 <tr>
7507 <td width="25%"><a href="#decl_cvGetFileNode">GetFileNode</a></td>
7508 <td width="25%"><a href="#decl_cvGetRow">GetRow</a></td>
7509 <td width="25%"><a href="#decl_cvGraphRemoveVtx">GraphRemoveVtx</a></td>
7510 </tr>
7511 <tr>
7512 <td width="25%"><a href="#decl_cvGetFileNodeByName">GetFileNodeByName</a></td>
7513 <td width="25%"><a href="#decl_cvGetSeqElem">GetSeqElem</a></td>
7514 <td width="25%"><a href="#decl_cvGraphRemoveVtxByPtr">GraphRemoveVtxByPtr</a></td>
7515 </tr>
7516 <tr>
7517 <td width="25%"><a href="#decl_cvGetFileNodeName">GetFileNodeName</a></td>
7518 <td width="25%"><a href="#decl_cvGetSeqReaderPos">GetSeqReaderPos</a></td>
7519 <td width="25%"><a href="#decl_cvGraphVtxDegree">GraphVtxDegree</a></td>
7520 </tr>
7521 <tr>
7522 <td width="25%"><a href="#decl_cvGetGraphVtx">GetGraphVtx</a></td>
7523 <td width="25%"><a href="#decl_cvGetSetElem">GetSetElem</a></td>
7524 <td width="25%"><a href="#decl_cvGraphVtxDegreeByPtr">GraphVtxDegreeByPtr</a></td>
7525 </tr>
7526 <tr>
7527 <td width="25%"><a href="#decl_cvGetHashedKey">GetHashedKey</a></td>
7528 <td width="25%"><a href="#decl_cvGetSize">GetSize</a></td>
7529 <td width="25%"><a href="#decl_cvGraphVtxIdx">GraphVtxIdx</a></td>
7530 </tr>
7531 <tr>
7532 <td width="25%"><a href="#decl_cvGetImage">GetImage</a></td>
7533 <td width="25%"><a href="#decl_cvGetSubRect">GetSubRect</a></td>
7534 <td width="25%"><a href="#decl_cvGuiBoxReport">GuiBoxReport</a></td>
7535 </tr>
7536 <tr>
7537 <td width="25%"><a href="#decl_cvGetImageCOI">GetImageCOI</a></td>
7538 <td width="25%"><a href="#decl_cvGetTextSize">GetTextSize</a></td>
7539 <td width="25%"><a href="#decl_cvmGet">Get</a></td>
7540 </tr>
7541 <tr>
7542 <td width="25%"><a href="#decl_cvGetImageROI">GetImageROI</a></td>
7543 <td width="25%"><a href="#decl_cvGetThreadNum">GetThreadNum</a></td>
7544 <td width="25%%"></td>
7545 </tr>
7546 </table>
7547 <hr><h3>I</h3>
7548 <table width="100%">
7549 <tr>
7550 <td width="25%"><a href="#decl_cvInRange">InRange</a></td>
7551 <td width="25%"><a href="#decl_cvInitLineIterator">InitLineIterator</a></td>
7552 <td width="25%"><a href="#decl_cvInsertNodeIntoTree">InsertNodeIntoTree</a></td>
7553 </tr>
7554 <tr>
7555 <td width="25%"><a href="#decl_cvInRangeS">InRangeS</a></td>
7556 <td width="25%"><a href="#decl_cvInitMatHeader">InitMatHeader</a></td>
7557 <td width="25%"><a href="#decl_cvInvSqrt">InvSqrt</a></td>
7558 </tr>
7559 <tr>
7560 <td width="25%"><a href="#decl_cvIncRefData">IncRefData</a></td>
7561 <td width="25%"><a href="#decl_cvInitMatNDHeader">InitMatNDHeader</a></td>
7562 <td width="25%"><a href="#decl_cvInvert">Invert</a></td>
7563 </tr>
7564 <tr>
7565 <td width="25%"><a href="#decl_cvInitFont">InitFont</a></td>
7566 <td width="25%"><a href="#decl_cvInitSparseMatIterator">InitSparseMatIterator</a></td>
7567 <td width="25%"><a href="#decl_cvIsInf">IsInf</a></td>
7568 </tr>
7569 <tr>
7570 <td width="25%"><a href="#decl_cvInitImageHeader">InitImageHeader</a></td>
7571 <td width="25%"><a href="#decl_cvInitTreeNodeIterator">InitTreeNodeIterator</a></td>
7572 <td width="25%"><a href="#decl_cvIsNaN">IsNaN</a></td>
7573 </tr>
7574 </table>
7575 <hr><h3>K</h3>
7576 <table width="100%">
7577 <tr>
7578 <td width="25%"><a href="#decl_cvKMeans2">KMeans2</a></td>
7579 <td width="25%%"></td>
7580 <td width="25%%"></td>
7581 </tr>
7582 </table>
7583 <hr><h3>L</h3>
7584 <table width="100%">
7585 <tr>
7586 <td width="25%"><a href="#decl_cvLUT">LUT</a></td>
7587 <td width="25%"><a href="#decl_cvLoad">Load</a></td>
7588 <td width="25%%"></td>
7589 </tr>
7590 <tr>
7591 <td width="25%"><a href="#decl_cvLine">Line</a></td>
7592 <td width="25%"><a href="#decl_cvLog">Log</a></td>
7593 <td width="25%%"></td>
7594 </tr>
7595 </table>
7596 <hr><h3>M</h3>
7597 <table width="100%">
7598 <tr>
7599 <td width="25%"><a href="#decl_cvMahalonobis">Mahalonobis</a></td>
7600 <td width="25%"><a href="#decl_cvMemStorageAlloc">MemStorageAlloc</a></td>
7601 <td width="25%"><a href="#decl_cvMinS">MinS</a></td>
7602 </tr>
7603 <tr>
7604 <td width="25%"><a href="#decl_cvMakeSeqHeaderForArray">MakeSeqHeaderForArray</a></td>
7605 <td width="25%"><a href="#decl_cvMemStorageAllocString">MemStorageAllocString</a></td>
7606 <td width="25%"><a href="#decl_cvMixChannels">MixChannels</a></td>
7607 </tr>
7608 <tr>
7609 <td width="25%"><a href="#decl_cvMat">Mat</a></td>
7610 <td width="25%"><a href="#decl_cvMerge">Merge</a></td>
7611 <td width="25%"><a href="#decl_cvMul">Mul</a></td>
7612 </tr>
7613 <tr>
7614 <td width="25%"><a href="#decl_cvMax">Max</a></td>
7615 <td width="25%"><a href="#decl_cvMin">Min</a></td>
7616 <td width="25%"><a href="#decl_cvMulSpectrums">MulSpectrums</a></td>
7617 </tr>
7618 <tr>
7619 <td width="25%"><a href="#decl_cvMaxS">MaxS</a></td>
7620 <td width="25%"><a href="#decl_cvMinMaxLoc">MinMaxLoc</a></td>
7621 <td width="25%"><a href="#decl_cvMulTransposed">MulTransposed</a></td>
7622 </tr>
7623 </table>
7624 <hr><h3>N</h3>
7625 <table width="100%">
7626 <tr>
7627 <td width="25%"><a href="#decl_cvNextGraphItem">NextGraphItem</a></td>
7628 <td width="25%"><a href="#decl_cvNorm">Norm</a></td>
7629 <td width="25%"><a href="#decl_cvNot">Not</a></td>
7630 </tr>
7631 <tr>
7632 <td width="25%"><a href="#decl_cvNextTreeNode">NextTreeNode</a></td>
7633 <td width="25%"><a href="#decl_cvNormalize">Normalize</a></td>
7634 <td width="25%"><a href="#decl_cvNulDevReport">NulDevReport</a></td>
7635 </tr>
7636 </table>
7637 <hr><h3>O</h3>
7638 <table width="100%">
7639 <tr>
7640 <td width="25%"><a href="#decl_cvOpenFileStorage">OpenFileStorage</a></td>
7641 <td width="25%"><a href="#decl_cvOr">Or</a></td>
7642 <td width="25%"><a href="#decl_cvOrS">OrS</a></td>
7643 </tr>
7644 </table>
7645 <hr><h3>P</h3>
7646 <table width="100%">
7647 <tr>
7648 <td width="25%"><a href="#decl_cvPerspectiveTransform">PerspectiveTransform</a></td>
7649 <td width="25%"><a href="#decl_cvPow">Pow</a></td>
7650 <td width="25%"><a href="#decl_cvPtr*D">Ptr*D</a></td>
7651 </tr>
7652 <tr>
7653 <td width="25%"><a href="#decl_cvPolarToCart">PolarToCart</a></td>
7654 <td width="25%"><a href="#decl_cvPrevTreeNode">PrevTreeNode</a></td>
7655 <td width="25%"><a href="#decl_cvPutText">PutText</a></td>
7656 </tr>
7657 <tr>
7658 <td width="25%"><a href="#decl_cvPolyLine">PolyLine</a></td>
7659 <td width="25%"><a href="#decl_cvProjectPCA">ProjectPCA</a></td>
7660 <td width="25%%"></td>
7661 </tr>
7662 </table>
7663 <hr><h3>R</h3>
7664 <table width="100%">
7665 <tr>
7666 <td width="25%"><a href="#decl_cvRNG">RNG</a></td>
7667 <td width="25%"><a href="#decl_cvReadRealByName">ReadRealByName</a></td>
7668 <td width="25%"><a href="#decl_cvReleaseImageHeader">ReleaseImageHeader</a></td>
7669 </tr>
7670 <tr>
7671 <td width="25%"><a href="#decl_cvRandArr">RandArr</a></td>
7672 <td width="25%"><a href="#decl_cvReadString">ReadString</a></td>
7673 <td width="25%"><a href="#decl_cvReleaseMat">ReleaseMat</a></td>
7674 </tr>
7675 <tr>
7676 <td width="25%"><a href="#decl_cvRandInt">RandInt</a></td>
7677 <td width="25%"><a href="#decl_cvReadStringByName">ReadStringByName</a></td>
7678 <td width="25%"><a href="#decl_cvReleaseMatND">ReleaseMatND</a></td>
7679 </tr>
7680 <tr>
7681 <td width="25%"><a href="#decl_cvRandReal">RandReal</a></td>
7682 <td width="25%"><a href="#decl_cvRectangle">Rectangle</a></td>
7683 <td width="25%"><a href="#decl_cvReleaseMemStorage">ReleaseMemStorage</a></td>
7684 </tr>
7685 <tr>
7686 <td width="25%"><a href="#decl_cvRandShuffle">RandShuffle</a></td>
7687 <td width="25%"><a href="#decl_cvRedirectError">RedirectError</a></td>
7688 <td width="25%"><a href="#decl_cvReleaseSparseMat">ReleaseSparseMat</a></td>
7689 </tr>
7690 <tr>
7691 <td width="25%"><a href="#decl_cvRange">Range</a></td>
7692 <td width="25%"><a href="#decl_cvReduce">Reduce</a></td>
7693 <td width="25%"><a href="#decl_cvRemoveNodeFromTree">RemoveNodeFromTree</a></td>
7694 </tr>
7695 <tr>
7696 <td width="25%"><a href="#decl_cvRead">Read</a></td>
7697 <td width="25%"><a href="#decl_cvRegisterModule">RegisterModule</a></td>
7698 <td width="25%"><a href="#decl_cvRepeat">Repeat</a></td>
7699 </tr>
7700 <tr>
7701 <td width="25%"><a href="#decl_cvReadByName">ReadByName</a></td>
7702 <td width="25%"><a href="#decl_cvRegisterType">RegisterType</a></td>
7703 <td width="25%"><a href="#decl_cvResetImageROI">ResetImageROI</a></td>
7704 </tr>
7705 <tr>
7706 <td width="25%"><a href="#decl_cvReadInt">ReadInt</a></td>
7707 <td width="25%"><a href="#decl_cvRelease">Release</a></td>
7708 <td width="25%"><a href="#decl_cvReshape">Reshape</a></td>
7709 </tr>
7710 <tr>
7711 <td width="25%"><a href="#decl_cvReadIntByName">ReadIntByName</a></td>
7712 <td width="25%"><a href="#decl_cvReleaseData">ReleaseData</a></td>
7713 <td width="25%"><a href="#decl_cvReshapeMatND">ReshapeMatND</a></td>
7714 </tr>
7715 <tr>
7716 <td width="25%"><a href="#decl_cvReadRawData">ReadRawData</a></td>
7717 <td width="25%"><a href="#decl_cvReleaseFileStorage">ReleaseFileStorage</a></td>
7718 <td width="25%"><a href="#decl_cvRestoreMemStoragePos">RestoreMemStoragePos</a></td>
7719 </tr>
7720 <tr>
7721 <td width="25%"><a href="#decl_cvReadRawDataSlice">ReadRawDataSlice</a></td>
7722 <td width="25%"><a href="#decl_cvReleaseGraphScanner">ReleaseGraphScanner</a></td>
7723 <td width="25%"><a href="#decl_cvRound">Round</a></td>
7724 </tr>
7725 <tr>
7726 <td width="25%"><a href="#decl_cvReadReal">ReadReal</a></td>
7727 <td width="25%"><a href="#decl_cvReleaseImage">ReleaseImage</a></td>
7728 <td width="25%%"></td>
7729 </tr>
7730 </table>
7731 <hr><h3>S</h3>
7732 <table width="100%">
7733 <tr>
7734 <td width="25%"><a href="#decl_cvSVBkSb">SVBkSb</a></td>
7735 <td width="25%"><a href="#decl_cvSeqSlice">SeqSlice</a></td>
7736 <td width="25%"><a href="#decl_cvSetSeqReaderPos">SetSeqReaderPos</a></td>
7737 </tr>
7738 <tr>
7739 <td width="25%"><a href="#decl_cvSVD">SVD</a></td>
7740 <td width="25%"><a href="#decl_cvSeqSort">SeqSort</a></td>
7741 <td width="25%"><a href="#decl_cvSetZero">SetZero</a></td>
7742 </tr>
7743 <tr>
7744 <td width="25%"><a href="#decl_cvSave">Save</a></td>
7745 <td width="25%"><a href="#decl_cvSet">Set</a></td>
7746 <td width="25%"><a href="#decl_cvSolve">Solve</a></td>
7747 </tr>
7748 <tr>
7749 <td width="25%"><a href="#decl_cvSaveMemStoragePos">SaveMemStoragePos</a></td>
7750 <td width="25%"><a href="#decl_cvSet*D">Set*D</a></td>
7751 <td width="25%"><a href="#decl_cvSolveCubic">SolveCubic</a></td>
7752 </tr>
7753 <tr>
7754 <td width="25%"><a href="#decl_cvScaleAdd">ScaleAdd</a></td>
7755 <td width="25%"><a href="#decl_cvSetAdd">SetAdd</a></td>
7756 <td width="25%"><a href="#decl_cvSplit">Split</a></td>
7757 </tr>
7758 <tr>
7759 <td width="25%"><a href="#decl_cvSeqElemIdx">SeqElemIdx</a></td>
7760 <td width="25%"><a href="#decl_cvSetData">SetData</a></td>
7761 <td width="25%"><a href="#decl_cvSqrt">Sqrt</a></td>
7762 </tr>
7763 <tr>
7764 <td width="25%"><a href="#decl_cvSeqInsert">SeqInsert</a></td>
7765 <td width="25%"><a href="#decl_cvSetErrMode">SetErrMode</a></td>
7766 <td width="25%"><a href="#decl_cvStartAppendToSeq">StartAppendToSeq</a></td>
7767 </tr>
7768 <tr>
7769 <td width="25%"><a href="#decl_cvSeqInsertSlice">SeqInsertSlice</a></td>
7770 <td width="25%"><a href="#decl_cvSetErrStatus">SetErrStatus</a></td>
7771 <td width="25%"><a href="#decl_cvStartNextStream">StartNextStream</a></td>
7772 </tr>
7773 <tr>
7774 <td width="25%"><a href="#decl_cvSeqInvert">SeqInvert</a></td>
7775 <td width="25%"><a href="#decl_cvSetIPLAllocators">SetIPLAllocators</a></td>
7776 <td width="25%"><a href="#decl_cvStartReadRawData">StartReadRawData</a></td>
7777 </tr>
7778 <tr>
7779 <td width="25%"><a href="#decl_cvSeqPartition">SeqPartition</a></td>
7780 <td width="25%"><a href="#decl_cvSetIdentity">SetIdentity</a></td>
7781 <td width="25%"><a href="#decl_cvStartReadSeq">StartReadSeq</a></td>
7782 </tr>
7783 <tr>
7784 <td width="25%"><a href="#decl_cvSeqPop">SeqPop</a></td>
7785 <td width="25%"><a href="#decl_cvSetImageCOI">SetImageCOI</a></td>
7786 <td width="25%"><a href="#decl_cvStartWriteSeq">StartWriteSeq</a></td>
7787 </tr>
7788 <tr>
7789 <td width="25%"><a href="#decl_cvSeqPopFront">SeqPopFront</a></td>
7790 <td width="25%"><a href="#decl_cvSetImageROI">SetImageROI</a></td>
7791 <td width="25%"><a href="#decl_cvStartWriteStruct">StartWriteStruct</a></td>
7792 </tr>
7793 <tr>
7794 <td width="25%"><a href="#decl_cvSeqPopMulti">SeqPopMulti</a></td>
7795 <td width="25%"><a href="#decl_cvSetMemoryManager">SetMemoryManager</a></td>
7796 <td width="25%"><a href="#decl_cvStdErrReport">StdErrReport</a></td>
7797 </tr>
7798 <tr>
7799 <td width="25%"><a href="#decl_cvSeqPush">SeqPush</a></td>
7800 <td width="25%"><a href="#decl_cvSetNew">SetNew</a></td>
7801 <td width="25%"><a href="#decl_cvSub">Sub</a></td>
7802 </tr>
7803 <tr>
7804 <td width="25%"><a href="#decl_cvSeqPushFront">SeqPushFront</a></td>
7805 <td width="25%"><a href="#decl_cvSetNumThreads">SetNumThreads</a></td>
7806 <td width="25%"><a href="#decl_cvSubRS">SubRS</a></td>
7807 </tr>
7808 <tr>
7809 <td width="25%"><a href="#decl_cvSeqPushMulti">SeqPushMulti</a></td>
7810 <td width="25%"><a href="#decl_cvSetReal*D">SetReal*D</a></td>
7811 <td width="25%"><a href="#decl_cvSubS">SubS</a></td>
7812 </tr>
7813 <tr>
7814 <td width="25%"><a href="#decl_cvSeqRemove">SeqRemove</a></td>
7815 <td width="25%"><a href="#decl_cvSetRemove">SetRemove</a></td>
7816 <td width="25%"><a href="#decl_cvSum">Sum</a></td>
7817 </tr>
7818 <tr>
7819 <td width="25%"><a href="#decl_cvSeqRemoveSlice">SeqRemoveSlice</a></td>
7820 <td width="25%"><a href="#decl_cvSetRemoveByPtr">SetRemoveByPtr</a></td>
7821 <td width="25%"><a href="#decl_cvmSet">Set</a></td>
7822 </tr>
7823 <tr>
7824 <td width="25%"><a href="#decl_cvSeqSearch">SeqSearch</a></td>
7825 <td width="25%"><a href="#decl_cvSetSeqBlockSize">SetSeqBlockSize</a></td>
7826 <td width="25%%"></td>
7827 </tr>
7828 </table>
7829 <hr><h3>T</h3>
7830 <table width="100%">
7831 <tr>
7832 <td width="25%"><a href="#decl_cvTrace">Trace</a></td>
7833 <td width="25%"><a href="#decl_cvTranspose">Transpose</a></td>
7834 <td width="25%"><a href="#decl_cvTypeOf">TypeOf</a></td>
7835 </tr>
7836 <tr>
7837 <td width="25%"><a href="#decl_cvTransform">Transform</a></td>
7838 <td width="25%"><a href="#decl_cvTreeToNodeSeq">TreeToNodeSeq</a></td>
7839 <td width="25%%"></td>
7840 </tr>
7841 </table>
7842 <hr><h3>U</h3>
7843 <table width="100%">
7844 <tr>
7845 <td width="25%"><a href="#decl_cvUnregisterType">UnregisterType</a></td>
7846 <td width="25%"><a href="#decl_cvUseOptimized">UseOptimized</a></td>
7847 <td width="25%%"></td>
7848 </tr>
7849 </table>
7850 <hr><h3>W</h3>
7851 <table width="100%">
7852 <tr>
7853 <td width="25%"><a href="#decl_cvWrite">Write</a></td>
7854 <td width="25%"><a href="#decl_cvWriteInt">WriteInt</a></td>
7855 <td width="25%"><a href="#decl_cvWriteString">WriteString</a></td>
7856 </tr>
7857 <tr>
7858 <td width="25%"><a href="#decl_cvWriteComment">WriteComment</a></td>
7859 <td width="25%"><a href="#decl_cvWriteRawData">WriteRawData</a></td>
7860 <td width="25%%"></td>
7861 </tr>
7862 <tr>
7863 <td width="25%"><a href="#decl_cvWriteFileNode">WriteFileNode</a></td>
7864 <td width="25%"><a href="#decl_cvWriteReal">WriteReal</a></td>
7865 <td width="25%%"></td>
7866 </tr>
7867 </table>
7868 <hr><h3>X</h3>
7869 <table width="100%">
7870 <tr>
7871 <td width="25%"><a href="#decl_cvXor">Xor</a></td>
7872 <td width="25%"><a href="#decl_cvXorS">XorS</a></td>
7873 <td width="25%%"></td>
7874 </tr>
7875 </table>
7876
7877 <hr><h1><a name="cxcore_sample_index">List of Examples</a></h1>
7878
7879 </body>
7880 </html>