1 /*M///////////////////////////////////////////////////////////////////////////////////////
\r
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
\r
5 // By downloading, copying, installing or using the software you agree to this license.
\r
6 // If you do not agree to this license, do not download, install,
\r
7 // copy or use the software.
\r
10 // License Agreement
\r
11 // For Open Source Computer Vision Library
\r
13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
\r
14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
\r
15 // Third party copyrights are property of their respective owners.
\r
17 // Redistribution and use in source and binary forms, with or without modification,
\r
18 // are permitted provided that the following conditions are met:
\r
20 // * Redistribution's of source code must retain the above copyright notice,
\r
21 // this list of conditions and the following disclaimer.
\r
23 // * Redistribution's in binary form must reproduce the above copyright notice,
\r
24 // this list of conditions and the following disclaimer in the documentation
\r
25 // and/or other materials provided with the distribution.
\r
27 // * The name of the copyright holders may not be used to endorse or promote products
\r
28 // derived from this software without specific prior written permission.
\r
30 // This software is provided by the copyright holders and contributors "as is" and
\r
31 // any express or implied warranties, including, but not limited to, the implied
\r
32 // warranties of merchantability and fitness for a particular purpose are disclaimed.
\r
33 // In no event shall the Intel Corporation or contributors be liable for any direct,
\r
34 // indirect, incidental, special, exemplary, or consequential damages
\r
35 // (including, but not limited to, procurement of substitute goods or services;
\r
36 // loss of use, data, or profits; or business interruption) however caused
\r
37 // and on any theory of liability, whether in contract, strict liability,
\r
38 // or tort (including negligence or otherwise) arising in any way out of
\r
39 // the use of this software, even if advised of the possibility of such damage.
\r
51 #ifndef SKIP_INCLUDES
\r
52 #if defined HAVE_IPL && !defined __IPL_H__
\r
53 #ifndef _INC_WINDOWS
\r
54 #define CV_PRETEND_WINDOWS
\r
55 #define _INC_WINDOWS
\r
56 typedef struct tagBITMAPINFOHEADER BITMAPINFOHEADER;
\r
59 #if defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64
\r
62 #include "ipl/ipl.h"
\r
64 #ifdef CV_PRETEND_WINDOWS
\r
68 #endif // SKIP_INCLUDES
\r
70 #include "cxtypes.h"
\r
71 #include "cxerror.h"
\r
78 /****************************************************************************************\
\r
79 * Array allocation, deallocation, initialization and access to elements *
\r
80 \****************************************************************************************/
\r
82 /* <malloc> wrapper.
\r
83 If there is no enough memory, the function
\r
84 (as well as other OpenCV functions that call cvAlloc)
\r
86 CVAPI(void*) cvAlloc( size_t size );
\r
89 Here and further all the memory releasing functions
\r
90 (that all call cvFree) take double pointer in order to
\r
91 to clear pointer to the data after releasing it.
\r
92 Passing pointer to NULL pointer is Ok: nothing happens in this case
\r
94 CVAPI(void) cvFree_( void* ptr );
\r
95 #define cvFree(ptr) (cvFree_(*(ptr)), *(ptr)=0)
\r
97 /* Allocates and initializes IplImage header */
\r
98 CVAPI(IplImage*) cvCreateImageHeader( CvSize size, int depth, int channels );
\r
100 /* Inializes IplImage header */
\r
101 CVAPI(IplImage*) cvInitImageHeader( IplImage* image, CvSize size, int depth,
\r
102 int channels, int origin CV_DEFAULT(0),
\r
103 int align CV_DEFAULT(4));
\r
105 /* Creates IPL image (header and data) */
\r
106 CVAPI(IplImage*) cvCreateImage( CvSize size, int depth, int channels );
\r
108 /* Releases (i.e. deallocates) IPL image header */
\r
109 CVAPI(void) cvReleaseImageHeader( IplImage** image );
\r
111 /* Releases IPL image header and data */
\r
112 CVAPI(void) cvReleaseImage( IplImage** image );
\r
114 /* Creates a copy of IPL image (widthStep may differ) */
\r
115 CVAPI(IplImage*) cvCloneImage( const IplImage* image );
\r
117 /* Sets a Channel Of Interest (only a few functions support COI) -
\r
118 use cvCopy to extract the selected channel and/or put it back */
\r
119 CVAPI(void) cvSetImageCOI( IplImage* image, int coi );
\r
121 /* Retrieves image Channel Of Interest */
\r
122 CVAPI(int) cvGetImageCOI( const IplImage* image );
\r
124 /* Sets image ROI (region of interest) (COI is not changed) */
\r
125 CVAPI(void) cvSetImageROI( IplImage* image, CvRect rect );
\r
127 /* Resets image ROI and COI */
\r
128 CVAPI(void) cvResetImageROI( IplImage* image );
\r
130 /* Retrieves image ROI */
\r
131 CVAPI(CvRect) cvGetImageROI( const IplImage* image );
\r
133 /* Allocates and initalizes CvMat header */
\r
134 CVAPI(CvMat*) cvCreateMatHeader( int rows, int cols, int type );
\r
136 #define CV_AUTOSTEP 0x7fffffff
\r
138 /* Initializes CvMat header */
\r
139 CVAPI(CvMat*) cvInitMatHeader( CvMat* mat, int rows, int cols,
\r
140 int type, void* data CV_DEFAULT(NULL),
\r
141 int step CV_DEFAULT(CV_AUTOSTEP) );
\r
143 /* Allocates and initializes CvMat header and allocates data */
\r
144 CVAPI(CvMat*) cvCreateMat( int rows, int cols, int type );
\r
146 /* Releases CvMat header and deallocates matrix data
\r
147 (reference counting is used for data) */
\r
148 CVAPI(void) cvReleaseMat( CvMat** mat );
\r
150 /* Decrements CvMat data reference counter and deallocates the data if
\r
152 CV_INLINE void cvDecRefData( CvArr* arr )
\r
154 if( CV_IS_MAT( arr ))
\r
156 CvMat* mat = (CvMat*)arr;
\r
157 mat->data.ptr = NULL;
\r
158 if( mat->refcount != NULL && --*mat->refcount == 0 )
\r
159 cvFree( &mat->refcount );
\r
160 mat->refcount = NULL;
\r
162 else if( CV_IS_MATND( arr ))
\r
164 CvMatND* mat = (CvMatND*)arr;
\r
165 mat->data.ptr = NULL;
\r
166 if( mat->refcount != NULL && --*mat->refcount == 0 )
\r
167 cvFree( &mat->refcount );
\r
168 mat->refcount = NULL;
\r
172 /* Increments CvMat data reference counter */
\r
173 CV_INLINE int cvIncRefData( CvArr* arr )
\r
176 if( CV_IS_MAT( arr ))
\r
178 CvMat* mat = (CvMat*)arr;
\r
179 if( mat->refcount != NULL )
\r
180 refcount = ++*mat->refcount;
\r
182 else if( CV_IS_MATND( arr ))
\r
184 CvMatND* mat = (CvMatND*)arr;
\r
185 if( mat->refcount != NULL )
\r
186 refcount = ++*mat->refcount;
\r
192 /* Creates an exact copy of the input matrix (except, may be, step value) */
\r
193 CVAPI(CvMat*) cvCloneMat( const CvMat* mat );
\r
196 /* Makes a new matrix from <rect> subrectangle of input array.
\r
197 No data is copied */
\r
198 CVAPI(CvMat*) cvGetSubRect( const CvArr* arr, CvMat* submat, CvRect rect );
\r
199 #define cvGetSubArr cvGetSubRect
\r
201 /* Selects row span of the input array: arr(start_row:delta_row:end_row,:)
\r
202 (end_row is not included into the span). */
\r
203 CVAPI(CvMat*) cvGetRows( const CvArr* arr, CvMat* submat,
\r
204 int start_row, int end_row,
\r
205 int delta_row CV_DEFAULT(1));
\r
207 CV_INLINE CvMat* cvGetRow( const CvArr* arr, CvMat* submat, int row )
\r
209 return cvGetRows( arr, submat, row, row + 1, 1 );
\r
213 /* Selects column span of the input array: arr(:,start_col:end_col)
\r
214 (end_col is not included into the span) */
\r
215 CVAPI(CvMat*) cvGetCols( const CvArr* arr, CvMat* submat,
\r
216 int start_col, int end_col );
\r
218 CV_INLINE CvMat* cvGetCol( const CvArr* arr, CvMat* submat, int col )
\r
220 return cvGetCols( arr, submat, col, col + 1 );
\r
223 /* Select a diagonal of the input array.
\r
224 (diag = 0 means the main diagonal, >0 means a diagonal above the main one,
\r
225 <0 - below the main one).
\r
226 The diagonal will be represented as a column (nx1 matrix). */
\r
227 CVAPI(CvMat*) cvGetDiag( const CvArr* arr, CvMat* submat,
\r
228 int diag CV_DEFAULT(0));
\r
230 /* low-level scalar <-> raw data conversion functions */
\r
231 CVAPI(void) cvScalarToRawData( const CvScalar* scalar, void* data, int type,
\r
232 int extend_to_12 CV_DEFAULT(0) );
\r
234 CVAPI(void) cvRawDataToScalar( const void* data, int type, CvScalar* scalar );
\r
236 /* Allocates and initializes CvMatND header */
\r
237 CVAPI(CvMatND*) cvCreateMatNDHeader( int dims, const int* sizes, int type );
\r
239 /* Allocates and initializes CvMatND header and allocates data */
\r
240 CVAPI(CvMatND*) cvCreateMatND( int dims, const int* sizes, int type );
\r
242 /* Initializes preallocated CvMatND header */
\r
243 CVAPI(CvMatND*) cvInitMatNDHeader( CvMatND* mat, int dims, const int* sizes,
\r
244 int type, void* data CV_DEFAULT(NULL) );
\r
246 /* Releases CvMatND */
\r
247 CV_INLINE void cvReleaseMatND( CvMatND** mat )
\r
249 cvReleaseMat( (CvMat**)mat );
\r
252 /* Creates a copy of CvMatND (except, may be, steps) */
\r
253 CVAPI(CvMatND*) cvCloneMatND( const CvMatND* mat );
\r
255 /* Allocates and initializes CvSparseMat header and allocates data */
\r
256 CVAPI(CvSparseMat*) cvCreateSparseMat( int dims, const int* sizes, int type );
\r
258 /* Releases CvSparseMat */
\r
259 CVAPI(void) cvReleaseSparseMat( CvSparseMat** mat );
\r
261 /* Creates a copy of CvSparseMat (except, may be, zero items) */
\r
262 CVAPI(CvSparseMat*) cvCloneSparseMat( const CvSparseMat* mat );
\r
264 /* Initializes sparse array iterator
\r
265 (returns the first node or NULL if the array is empty) */
\r
266 CVAPI(CvSparseNode*) cvInitSparseMatIterator( const CvSparseMat* mat,
\r
267 CvSparseMatIterator* mat_iterator );
\r
269 // returns next sparse array node (or NULL if there is no more nodes)
\r
270 CV_INLINE CvSparseNode* cvGetNextSparseNode( CvSparseMatIterator* mat_iterator )
\r
272 if( mat_iterator->node->next )
\r
273 return mat_iterator->node = mat_iterator->node->next;
\r
277 for( idx = ++mat_iterator->curidx; idx < mat_iterator->mat->hashsize; idx++ )
\r
279 CvSparseNode* node = (CvSparseNode*)mat_iterator->mat->hashtable[idx];
\r
282 mat_iterator->curidx = idx;
\r
283 return mat_iterator->node = node;
\r
290 /**************** matrix iterator: used for n-ary operations on dense arrays *********/
\r
292 #define CV_MAX_ARR 10
\r
294 typedef struct CvNArrayIterator
\r
296 int count; /* number of arrays */
\r
297 int dims; /* number of dimensions to iterate */
\r
298 CvSize size; /* maximal common linear size: { width = size, height = 1 } */
\r
299 uchar* ptr[CV_MAX_ARR]; /* pointers to the array slices */
\r
300 int stack[CV_MAX_DIM]; /* for internal use */
\r
301 CvMatND* hdr[CV_MAX_ARR]; /* pointers to the headers of the
\r
302 matrices that are processed */
\r
306 #define CV_NO_DEPTH_CHECK 1
\r
307 #define CV_NO_CN_CHECK 2
\r
308 #define CV_NO_SIZE_CHECK 4
\r
310 /* initializes iterator that traverses through several arrays simulteneously
\r
311 (the function together with cvNextArraySlice is used for
\r
312 N-ari element-wise operations) */
\r
313 CVAPI(int) cvInitNArrayIterator( int count, CvArr** arrs,
\r
314 const CvArr* mask, CvMatND* stubs,
\r
315 CvNArrayIterator* array_iterator,
\r
316 int flags CV_DEFAULT(0) );
\r
318 /* returns zero value if iteration is finished, non-zero (slice length) otherwise */
\r
319 CVAPI(int) cvNextNArraySlice( CvNArrayIterator* array_iterator );
\r
322 /* Returns type of array elements:
\r
323 CV_8UC1 ... CV_64FC4 ... */
\r
324 CVAPI(int) cvGetElemType( const CvArr* arr );
\r
326 /* Retrieves number of an array dimensions and
\r
327 optionally sizes of the dimensions */
\r
328 CVAPI(int) cvGetDims( const CvArr* arr, int* sizes CV_DEFAULT(NULL) );
\r
331 /* Retrieves size of a particular array dimension.
\r
332 For 2d arrays cvGetDimSize(arr,0) returns number of rows (image height)
\r
333 and cvGetDimSize(arr,1) returns number of columns (image width) */
\r
334 CVAPI(int) cvGetDimSize( const CvArr* arr, int index );
\r
337 /* ptr = &arr(idx0,idx1,...). All indexes are zero-based,
\r
338 the major dimensions go first (e.g. (y,x) for 2D, (z,y,x) for 3D */
\r
339 CVAPI(uchar*) cvPtr1D( const CvArr* arr, int idx0, int* type CV_DEFAULT(NULL));
\r
340 CVAPI(uchar*) cvPtr2D( const CvArr* arr, int idx0, int idx1, int* type CV_DEFAULT(NULL) );
\r
341 CVAPI(uchar*) cvPtr3D( const CvArr* arr, int idx0, int idx1, int idx2,
\r
342 int* type CV_DEFAULT(NULL));
\r
344 /* For CvMat or IplImage number of indices should be 2
\r
345 (row index (y) goes first, column index (x) goes next).
\r
346 For CvMatND or CvSparseMat number of infices should match number of <dims> and
\r
347 indices order should match the array dimension order. */
\r
348 CVAPI(uchar*) cvPtrND( const CvArr* arr, const int* idx, int* type CV_DEFAULT(NULL),
\r
349 int create_node CV_DEFAULT(1),
\r
350 unsigned* precalc_hashval CV_DEFAULT(NULL));
\r
352 /* value = arr(idx0,idx1,...) */
\r
353 CVAPI(CvScalar) cvGet1D( const CvArr* arr, int idx0 );
\r
354 CVAPI(CvScalar) cvGet2D( const CvArr* arr, int idx0, int idx1 );
\r
355 CVAPI(CvScalar) cvGet3D( const CvArr* arr, int idx0, int idx1, int idx2 );
\r
356 CVAPI(CvScalar) cvGetND( const CvArr* arr, const int* idx );
\r
358 /* for 1-channel arrays */
\r
359 CVAPI(double) cvGetReal1D( const CvArr* arr, int idx0 );
\r
360 CVAPI(double) cvGetReal2D( const CvArr* arr, int idx0, int idx1 );
\r
361 CVAPI(double) cvGetReal3D( const CvArr* arr, int idx0, int idx1, int idx2 );
\r
362 CVAPI(double) cvGetRealND( const CvArr* arr, const int* idx );
\r
364 /* arr(idx0,idx1,...) = value */
\r
365 CVAPI(void) cvSet1D( CvArr* arr, int idx0, CvScalar value );
\r
366 CVAPI(void) cvSet2D( CvArr* arr, int idx0, int idx1, CvScalar value );
\r
367 CVAPI(void) cvSet3D( CvArr* arr, int idx0, int idx1, int idx2, CvScalar value );
\r
368 CVAPI(void) cvSetND( CvArr* arr, const int* idx, CvScalar value );
\r
370 /* for 1-channel arrays */
\r
371 CVAPI(void) cvSetReal1D( CvArr* arr, int idx0, double value );
\r
372 CVAPI(void) cvSetReal2D( CvArr* arr, int idx0, int idx1, double value );
\r
373 CVAPI(void) cvSetReal3D( CvArr* arr, int idx0,
\r
374 int idx1, int idx2, double value );
\r
375 CVAPI(void) cvSetRealND( CvArr* arr, const int* idx, double value );
\r
377 /* clears element of ND dense array,
\r
378 in case of sparse arrays it deletes the specified node */
\r
379 CVAPI(void) cvClearND( CvArr* arr, const int* idx );
\r
381 /* Converts CvArr (IplImage or CvMat,...) to CvMat.
\r
382 If the last parameter is non-zero, function can
\r
383 convert multi(>2)-dimensional array to CvMat as long as
\r
384 the last array's dimension is continous. The resultant
\r
385 matrix will be have appropriate (a huge) number of rows */
\r
386 CVAPI(CvMat*) cvGetMat( const CvArr* arr, CvMat* header,
\r
387 int* coi CV_DEFAULT(NULL),
\r
388 int allowND CV_DEFAULT(0));
\r
390 /* Converts CvArr (IplImage or CvMat) to IplImage */
\r
391 CVAPI(IplImage*) cvGetImage( const CvArr* arr, IplImage* image_header );
\r
394 /* Changes a shape of multi-dimensional array.
\r
395 new_cn == 0 means that number of channels remains unchanged.
\r
396 new_dims == 0 means that number and sizes of dimensions remain the same
\r
397 (unless they need to be changed to set the new number of channels)
\r
398 if new_dims == 1, there is no need to specify new dimension sizes
\r
399 The resultant configuration should be achievable w/o data copying.
\r
400 If the resultant array is sparse, CvSparseMat header should be passed
\r
401 to the function else if the result is 1 or 2 dimensional,
\r
402 CvMat header should be passed to the function
\r
403 else CvMatND header should be passed */
\r
404 CVAPI(CvArr*) cvReshapeMatND( const CvArr* arr,
\r
405 int sizeof_header, CvArr* header,
\r
406 int new_cn, int new_dims, int* new_sizes );
\r
408 #define cvReshapeND( arr, header, new_cn, new_dims, new_sizes ) \
\r
409 cvReshapeMatND( (arr), sizeof(*(header)), (header), \
\r
410 (new_cn), (new_dims), (new_sizes))
\r
412 CVAPI(CvMat*) cvReshape( const CvArr* arr, CvMat* header,
\r
413 int new_cn, int new_rows CV_DEFAULT(0) );
\r
415 /* Repeats source 2d array several times in both horizontal and
\r
416 vertical direction to fill destination array */
\r
417 CVAPI(void) cvRepeat( const CvArr* src, CvArr* dst );
\r
419 /* Allocates array data */
\r
420 CVAPI(void) cvCreateData( CvArr* arr );
\r
422 /* Releases array data */
\r
423 CVAPI(void) cvReleaseData( CvArr* arr );
\r
425 /* Attaches user data to the array header. The step is reffered to
\r
426 the pre-last dimension. That is, all the planes of the array
\r
427 must be joint (w/o gaps) */
\r
428 CVAPI(void) cvSetData( CvArr* arr, void* data, int step );
\r
430 /* Retrieves raw data of CvMat, IplImage or CvMatND.
\r
431 In the latter case the function raises an error if
\r
432 the array can not be represented as a matrix */
\r
433 CVAPI(void) cvGetRawData( const CvArr* arr, uchar** data,
\r
434 int* step CV_DEFAULT(NULL),
\r
435 CvSize* roi_size CV_DEFAULT(NULL));
\r
437 /* Returns width and height of array in elements */
\r
438 CVAPI(CvSize) cvGetSize( const CvArr* arr );
\r
440 /* Copies source array to destination array */
\r
441 CVAPI(void) cvCopy( const CvArr* src, CvArr* dst,
\r
442 const CvArr* mask CV_DEFAULT(NULL) );
\r
444 /* Sets all or "masked" elements of input array
\r
445 to the same value*/
\r
446 CVAPI(void) cvSet( CvArr* arr, CvScalar value,
\r
447 const CvArr* mask CV_DEFAULT(NULL) );
\r
449 /* Clears all the array elements (sets them to 0) */
\r
450 CVAPI(void) cvSetZero( CvArr* arr );
\r
451 #define cvZero cvSetZero
\r
454 /* Splits a multi-channel array into the set of single-channel arrays or
\r
455 extracts particular [color] plane */
\r
456 CVAPI(void) cvSplit( const CvArr* src, CvArr* dst0, CvArr* dst1,
\r
457 CvArr* dst2, CvArr* dst3 );
\r
459 /* Merges a set of single-channel arrays into the single multi-channel array
\r
460 or inserts one particular [color] plane to the array */
\r
461 CVAPI(void) cvMerge( const CvArr* src0, const CvArr* src1,
\r
462 const CvArr* src2, const CvArr* src3,
\r
465 /* Copies several channels from input arrays to
\r
466 certain channels of output arrays */
\r
467 CVAPI(void) cvMixChannels( const CvArr** src, int src_count,
\r
468 CvArr** dst, int dst_count,
\r
469 const int* from_to, int pair_count );
\r
471 /* Performs linear transformation on every source array element:
\r
472 dst(x,y,c) = scale*src(x,y,c)+shift.
\r
473 Arbitrary combination of input and output array depths are allowed
\r
474 (number of channels must be the same), thus the function can be used
\r
475 for type conversion */
\r
476 CVAPI(void) cvConvertScale( const CvArr* src, CvArr* dst,
\r
477 double scale CV_DEFAULT(1),
\r
478 double shift CV_DEFAULT(0) );
\r
479 #define cvCvtScale cvConvertScale
\r
480 #define cvScale cvConvertScale
\r
481 #define cvConvert( src, dst ) cvConvertScale( (src), (dst), 1, 0 )
\r
484 /* Performs linear transformation on every source array element,
\r
485 stores absolute value of the result:
\r
486 dst(x,y,c) = abs(scale*src(x,y,c)+shift).
\r
487 destination array must have 8u type.
\r
488 In other cases one may use cvConvertScale + cvAbsDiffS */
\r
489 CVAPI(void) cvConvertScaleAbs( const CvArr* src, CvArr* dst,
\r
490 double scale CV_DEFAULT(1),
\r
491 double shift CV_DEFAULT(0) );
\r
492 #define cvCvtScaleAbs cvConvertScaleAbs
\r
495 /* checks termination criteria validity and
\r
496 sets eps to default_eps (if it is not set),
\r
497 max_iter to default_max_iters (if it is not set)
\r
499 CVAPI(CvTermCriteria) cvCheckTermCriteria( CvTermCriteria criteria,
\r
500 double default_eps,
\r
501 int default_max_iters );
\r
503 /****************************************************************************************\
\r
504 * Arithmetic, logic and comparison operations *
\r
505 \****************************************************************************************/
\r
507 /* dst(mask) = src1(mask) + src2(mask) */
\r
508 CVAPI(void) cvAdd( const CvArr* src1, const CvArr* src2, CvArr* dst,
\r
509 const CvArr* mask CV_DEFAULT(NULL));
\r
511 /* dst(mask) = src(mask) + value */
\r
512 CVAPI(void) cvAddS( const CvArr* src, CvScalar value, CvArr* dst,
\r
513 const CvArr* mask CV_DEFAULT(NULL));
\r
515 /* dst(mask) = src1(mask) - src2(mask) */
\r
516 CVAPI(void) cvSub( const CvArr* src1, const CvArr* src2, CvArr* dst,
\r
517 const CvArr* mask CV_DEFAULT(NULL));
\r
519 /* dst(mask) = src(mask) - value = src(mask) + (-value) */
\r
520 CV_INLINE void cvSubS( const CvArr* src, CvScalar value, CvArr* dst,
\r
521 const CvArr* mask CV_DEFAULT(NULL))
\r
523 cvAddS( src, cvScalar( -value.val[0], -value.val[1], -value.val[2], -value.val[3]),
\r
527 /* dst(mask) = value - src(mask) */
\r
528 CVAPI(void) cvSubRS( const CvArr* src, CvScalar value, CvArr* dst,
\r
529 const CvArr* mask CV_DEFAULT(NULL));
\r
531 /* dst(idx) = src1(idx) * src2(idx) * scale
\r
532 (scaled element-wise multiplication of 2 arrays) */
\r
533 CVAPI(void) cvMul( const CvArr* src1, const CvArr* src2,
\r
534 CvArr* dst, double scale CV_DEFAULT(1) );
\r
536 /* element-wise division/inversion with scaling:
\r
537 dst(idx) = src1(idx) * scale / src2(idx)
\r
538 or dst(idx) = scale / src2(idx) if src1 == 0 */
\r
539 CVAPI(void) cvDiv( const CvArr* src1, const CvArr* src2,
\r
540 CvArr* dst, double scale CV_DEFAULT(1));
\r
542 /* dst = src1 * scale + src2 */
\r
543 CVAPI(void) cvScaleAdd( const CvArr* src1, CvScalar scale,
\r
544 const CvArr* src2, CvArr* dst );
\r
545 #define cvAXPY( A, real_scalar, B, C ) cvScaleAdd(A, cvRealScalar(real_scalar), B, C)
\r
547 /* dst = src1 * alpha + src2 * beta + gamma */
\r
548 CVAPI(void) cvAddWeighted( const CvArr* src1, double alpha,
\r
549 const CvArr* src2, double beta,
\r
550 double gamma, CvArr* dst );
\r
552 /* result = sum_i(src1(i) * src2(i)) (results for all channels are accumulated together) */
\r
553 CVAPI(double) cvDotProduct( const CvArr* src1, const CvArr* src2 );
\r
555 /* dst(idx) = src1(idx) & src2(idx) */
\r
556 CVAPI(void) cvAnd( const CvArr* src1, const CvArr* src2,
\r
557 CvArr* dst, const CvArr* mask CV_DEFAULT(NULL));
\r
559 /* dst(idx) = src(idx) & value */
\r
560 CVAPI(void) cvAndS( const CvArr* src, CvScalar value,
\r
561 CvArr* dst, const CvArr* mask CV_DEFAULT(NULL));
\r
563 /* dst(idx) = src1(idx) | src2(idx) */
\r
564 CVAPI(void) cvOr( const CvArr* src1, const CvArr* src2,
\r
565 CvArr* dst, const CvArr* mask CV_DEFAULT(NULL));
\r
567 /* dst(idx) = src(idx) | value */
\r
568 CVAPI(void) cvOrS( const CvArr* src, CvScalar value,
\r
569 CvArr* dst, const CvArr* mask CV_DEFAULT(NULL));
\r
571 /* dst(idx) = src1(idx) ^ src2(idx) */
\r
572 CVAPI(void) cvXor( const CvArr* src1, const CvArr* src2,
\r
573 CvArr* dst, const CvArr* mask CV_DEFAULT(NULL));
\r
575 /* dst(idx) = src(idx) ^ value */
\r
576 CVAPI(void) cvXorS( const CvArr* src, CvScalar value,
\r
577 CvArr* dst, const CvArr* mask CV_DEFAULT(NULL));
\r
579 /* dst(idx) = ~src(idx) */
\r
580 CVAPI(void) cvNot( const CvArr* src, CvArr* dst );
\r
582 /* dst(idx) = lower(idx) <= src(idx) < upper(idx) */
\r
583 CVAPI(void) cvInRange( const CvArr* src, const CvArr* lower,
\r
584 const CvArr* upper, CvArr* dst );
\r
586 /* dst(idx) = lower <= src(idx) < upper */
\r
587 CVAPI(void) cvInRangeS( const CvArr* src, CvScalar lower,
\r
588 CvScalar upper, CvArr* dst );
\r
590 #define CV_CMP_EQ 0
\r
591 #define CV_CMP_GT 1
\r
592 #define CV_CMP_GE 2
\r
593 #define CV_CMP_LT 3
\r
594 #define CV_CMP_LE 4
\r
595 #define CV_CMP_NE 5
\r
597 /* The comparison operation support single-channel arrays only.
\r
598 Destination image should be 8uC1 or 8sC1 */
\r
600 /* dst(idx) = src1(idx) _cmp_op_ src2(idx) */
\r
601 CVAPI(void) cvCmp( const CvArr* src1, const CvArr* src2, CvArr* dst, int cmp_op );
\r
603 /* dst(idx) = src1(idx) _cmp_op_ value */
\r
604 CVAPI(void) cvCmpS( const CvArr* src, double value, CvArr* dst, int cmp_op );
\r
606 /* dst(idx) = min(src1(idx),src2(idx)) */
\r
607 CVAPI(void) cvMin( const CvArr* src1, const CvArr* src2, CvArr* dst );
\r
609 /* dst(idx) = max(src1(idx),src2(idx)) */
\r
610 CVAPI(void) cvMax( const CvArr* src1, const CvArr* src2, CvArr* dst );
\r
612 /* dst(idx) = min(src(idx),value) */
\r
613 CVAPI(void) cvMinS( const CvArr* src, double value, CvArr* dst );
\r
615 /* dst(idx) = max(src(idx),value) */
\r
616 CVAPI(void) cvMaxS( const CvArr* src, double value, CvArr* dst );
\r
618 /* dst(x,y,c) = abs(src1(x,y,c) - src2(x,y,c)) */
\r
619 CVAPI(void) cvAbsDiff( const CvArr* src1, const CvArr* src2, CvArr* dst );
\r
621 /* dst(x,y,c) = abs(src(x,y,c) - value(c)) */
\r
622 CVAPI(void) cvAbsDiffS( const CvArr* src, CvArr* dst, CvScalar value );
\r
623 #define cvAbs( src, dst ) cvAbsDiffS( (src), (dst), cvScalarAll(0))
\r
625 /****************************************************************************************\
\r
626 * Math operations *
\r
627 \****************************************************************************************/
\r
629 /* Does cartesian->polar coordinates conversion.
\r
630 Either of output components (magnitude or angle) is optional */
\r
631 CVAPI(void) cvCartToPolar( const CvArr* x, const CvArr* y,
\r
632 CvArr* magnitude, CvArr* angle CV_DEFAULT(NULL),
\r
633 int angle_in_degrees CV_DEFAULT(0));
\r
635 /* Does polar->cartesian coordinates conversion.
\r
636 Either of output components (magnitude or angle) is optional.
\r
637 If magnitude is missing it is assumed to be all 1's */
\r
638 CVAPI(void) cvPolarToCart( const CvArr* magnitude, const CvArr* angle,
\r
639 CvArr* x, CvArr* y,
\r
640 int angle_in_degrees CV_DEFAULT(0));
\r
642 /* Does powering: dst(idx) = src(idx)^power */
\r
643 CVAPI(void) cvPow( const CvArr* src, CvArr* dst, double power );
\r
645 /* Does exponention: dst(idx) = exp(src(idx)).
\r
646 Overflow is not handled yet. Underflow is handled.
\r
647 Maximal relative error is ~7e-6 for single-precision input */
\r
648 CVAPI(void) cvExp( const CvArr* src, CvArr* dst );
\r
650 /* Calculates natural logarithms: dst(idx) = log(abs(src(idx))).
\r
651 Logarithm of 0 gives large negative number(~-700)
\r
652 Maximal relative error is ~3e-7 for single-precision output
\r
654 CVAPI(void) cvLog( const CvArr* src, CvArr* dst );
\r
656 /* Fast arctangent calculation */
\r
657 CVAPI(float) cvFastArctan( float y, float x );
\r
659 /* Fast cubic root calculation */
\r
660 CVAPI(float) cvCbrt( float value );
\r
662 /* Checks array values for NaNs, Infs or simply for too large numbers
\r
663 (if CV_CHECK_RANGE is set). If CV_CHECK_QUIET is set,
\r
664 no runtime errors is raised (function returns zero value in case of "bad" values).
\r
665 Otherwise cvError is called */
\r
666 #define CV_CHECK_RANGE 1
\r
667 #define CV_CHECK_QUIET 2
\r
668 CVAPI(int) cvCheckArr( const CvArr* arr, int flags CV_DEFAULT(0),
\r
669 double min_val CV_DEFAULT(0), double max_val CV_DEFAULT(0));
\r
670 #define cvCheckArray cvCheckArr
\r
672 #define CV_RAND_UNI 0
\r
673 #define CV_RAND_NORMAL 1
\r
674 CVAPI(void) cvRandArr( CvRNG* rng, CvArr* arr, int dist_type,
\r
675 CvScalar param1, CvScalar param2 );
\r
677 CVAPI(void) cvRandShuffle( CvArr* mat, CvRNG* rng,
\r
678 double iter_factor CV_DEFAULT(1.));
\r
680 #define CV_SORT_EVERY_ROW 0
\r
681 #define CV_SORT_EVERY_COLUMN 1
\r
682 #define CV_SORT_ASCENDING 0
\r
683 #define CV_SORT_DESCENDING 16
\r
685 CVAPI(void) cvSort( const CvArr* src, CvArr* dst CV_DEFAULT(NULL),
\r
686 CvArr* idxmat CV_DEFAULT(NULL),
\r
687 int flags CV_DEFAULT(0));
\r
689 /* Finds real roots of a cubic equation */
\r
690 CVAPI(int) cvSolveCubic( const CvMat* coeffs, CvMat* roots );
\r
692 /* Finds all real and complex roots of a polynomial equation */
\r
693 CVAPI(void) cvSolvePoly(const CvMat* coeffs, CvMat *roots2,
\r
694 int maxiter CV_DEFAULT(20), int fig CV_DEFAULT(100));
\r
696 /****************************************************************************************\
\r
697 * Matrix operations *
\r
698 \****************************************************************************************/
\r
700 /* Calculates cross product of two 3d vectors */
\r
701 CVAPI(void) cvCrossProduct( const CvArr* src1, const CvArr* src2, CvArr* dst );
\r
703 /* Matrix transform: dst = A*B + C, C is optional */
\r
704 #define cvMatMulAdd( src1, src2, src3, dst ) cvGEMM( (src1), (src2), 1., (src3), 1., (dst), 0 )
\r
705 #define cvMatMul( src1, src2, dst ) cvMatMulAdd( (src1), (src2), NULL, (dst))
\r
707 #define CV_GEMM_A_T 1
\r
708 #define CV_GEMM_B_T 2
\r
709 #define CV_GEMM_C_T 4
\r
710 /* Extended matrix transform:
\r
711 dst = alpha*op(A)*op(B) + beta*op(C), where op(X) is X or X^T */
\r
712 CVAPI(void) cvGEMM( const CvArr* src1, const CvArr* src2, double alpha,
\r
713 const CvArr* src3, double beta, CvArr* dst,
\r
714 int tABC CV_DEFAULT(0));
\r
715 #define cvMatMulAddEx cvGEMM
\r
717 /* Transforms each element of source array and stores
\r
718 resultant vectors in destination array */
\r
719 CVAPI(void) cvTransform( const CvArr* src, CvArr* dst,
\r
720 const CvMat* transmat,
\r
721 const CvMat* shiftvec CV_DEFAULT(NULL));
\r
722 #define cvMatMulAddS cvTransform
\r
724 /* Does perspective transform on every element of input array */
\r
725 CVAPI(void) cvPerspectiveTransform( const CvArr* src, CvArr* dst,
\r
726 const CvMat* mat );
\r
728 /* Calculates (A-delta)*(A-delta)^T (order=0) or (A-delta)^T*(A-delta) (order=1) */
\r
729 CVAPI(void) cvMulTransposed( const CvArr* src, CvArr* dst, int order,
\r
730 const CvArr* delta CV_DEFAULT(NULL),
\r
731 double scale CV_DEFAULT(1.) );
\r
733 /* Tranposes matrix. Square matrices can be transposed in-place */
\r
734 CVAPI(void) cvTranspose( const CvArr* src, CvArr* dst );
\r
735 #define cvT cvTranspose
\r
737 /* Completes the symmetric matrix from the lower (LtoR=0) or from the upper (LtoR!=0) part */
\r
738 CVAPI(void) cvCompleteSymm( CvMat* matrix, int LtoR CV_DEFAULT(0) );
\r
740 /* Mirror array data around horizontal (flip=0),
\r
741 vertical (flip=1) or both(flip=-1) axises:
\r
742 cvFlip(src) flips images vertically and sequences horizontally (inplace) */
\r
743 CVAPI(void) cvFlip( const CvArr* src, CvArr* dst CV_DEFAULT(NULL),
\r
744 int flip_mode CV_DEFAULT(0));
\r
745 #define cvMirror cvFlip
\r
748 #define CV_SVD_MODIFY_A 1
\r
749 #define CV_SVD_U_T 2
\r
750 #define CV_SVD_V_T 4
\r
752 /* Performs Singular Value Decomposition of a matrix */
\r
753 CVAPI(void) cvSVD( CvArr* A, CvArr* W, CvArr* U CV_DEFAULT(NULL),
\r
754 CvArr* V CV_DEFAULT(NULL), int flags CV_DEFAULT(0));
\r
756 /* Performs Singular Value Back Substitution (solves A*X = B):
\r
757 flags must be the same as in cvSVD */
\r
758 CVAPI(void) cvSVBkSb( const CvArr* W, const CvArr* U,
\r
759 const CvArr* V, const CvArr* B,
\r
760 CvArr* X, int flags );
\r
764 #define CV_SVD_SYM 2
\r
765 #define CV_CHOLESKY 3
\r
767 #define CV_NORMAL 16
\r
769 /* Inverts matrix */
\r
770 CVAPI(double) cvInvert( const CvArr* src, CvArr* dst,
\r
771 int method CV_DEFAULT(CV_LU));
\r
772 #define cvInv cvInvert
\r
774 /* Solves linear system (src1)*(dst) = (src2)
\r
775 (returns 0 if src1 is a singular and CV_LU method is used) */
\r
776 CVAPI(int) cvSolve( const CvArr* src1, const CvArr* src2, CvArr* dst,
\r
777 int method CV_DEFAULT(CV_LU));
\r
779 /* Calculates determinant of input matrix */
\r
780 CVAPI(double) cvDet( const CvArr* mat );
\r
782 /* Calculates trace of the matrix (sum of elements on the main diagonal) */
\r
783 CVAPI(CvScalar) cvTrace( const CvArr* mat );
\r
785 /* Finds eigen values and vectors of a symmetric matrix */
\r
786 CVAPI(void) cvEigenVV( CvArr* mat, CvArr* evects, CvArr* evals,
\r
787 double eps CV_DEFAULT(0),
\r
788 int lowindex CV_DEFAULT(-1),
\r
789 int highindex CV_DEFAULT(-1));
\r
791 ///* Finds selected eigen values and vectors of a symmetric matrix */
\r
792 //CVAPI(void) cvSelectedEigenVV( CvArr* mat, CvArr* evects, CvArr* evals,
\r
793 // int lowindex, int highindex );
\r
795 /* Makes an identity matrix (mat_ij = i == j) */
\r
796 CVAPI(void) cvSetIdentity( CvArr* mat, CvScalar value CV_DEFAULT(cvRealScalar(1)) );
\r
798 /* Fills matrix with given range of numbers */
\r
799 CVAPI(CvArr*) cvRange( CvArr* mat, double start, double end );
\r
801 /* Calculates covariation matrix for a set of vectors */
\r
802 /* transpose([v1-avg, v2-avg,...]) * [v1-avg,v2-avg,...] */
\r
803 #define CV_COVAR_SCRAMBLED 0
\r
805 /* [v1-avg, v2-avg,...] * transpose([v1-avg,v2-avg,...]) */
\r
806 #define CV_COVAR_NORMAL 1
\r
808 /* do not calc average (i.e. mean vector) - use the input vector instead
\r
809 (useful for calculating covariance matrix by parts) */
\r
810 #define CV_COVAR_USE_AVG 2
\r
812 /* scale the covariance matrix coefficients by number of the vectors */
\r
813 #define CV_COVAR_SCALE 4
\r
815 /* all the input vectors are stored in a single matrix, as its rows */
\r
816 #define CV_COVAR_ROWS 8
\r
818 /* all the input vectors are stored in a single matrix, as its columns */
\r
819 #define CV_COVAR_COLS 16
\r
821 CVAPI(void) cvCalcCovarMatrix( const CvArr** vects, int count,
\r
822 CvArr* cov_mat, CvArr* avg, int flags );
\r
824 #define CV_PCA_DATA_AS_ROW 0
\r
825 #define CV_PCA_DATA_AS_COL 1
\r
826 #define CV_PCA_USE_AVG 2
\r
827 CVAPI(void) cvCalcPCA( const CvArr* data, CvArr* mean,
\r
828 CvArr* eigenvals, CvArr* eigenvects, int flags );
\r
830 CVAPI(void) cvProjectPCA( const CvArr* data, const CvArr* mean,
\r
831 const CvArr* eigenvects, CvArr* result );
\r
833 CVAPI(void) cvBackProjectPCA( const CvArr* proj, const CvArr* mean,
\r
834 const CvArr* eigenvects, CvArr* result );
\r
836 /* Calculates Mahalanobis(weighted) distance */
\r
837 CVAPI(double) cvMahalanobis( const CvArr* vec1, const CvArr* vec2, const CvArr* mat );
\r
838 #define cvMahalonobis cvMahalanobis
\r
840 /****************************************************************************************\
\r
841 * Array Statistics *
\r
842 \****************************************************************************************/
\r
844 /* Finds sum of array elements */
\r
845 CVAPI(CvScalar) cvSum( const CvArr* arr );
\r
847 /* Calculates number of non-zero pixels */
\r
848 CVAPI(int) cvCountNonZero( const CvArr* arr );
\r
850 /* Calculates mean value of array elements */
\r
851 CVAPI(CvScalar) cvAvg( const CvArr* arr, const CvArr* mask CV_DEFAULT(NULL) );
\r
853 /* Calculates mean and standard deviation of pixel values */
\r
854 CVAPI(void) cvAvgSdv( const CvArr* arr, CvScalar* mean, CvScalar* std_dev,
\r
855 const CvArr* mask CV_DEFAULT(NULL) );
\r
857 /* Finds global minimum, maximum and their positions */
\r
858 CVAPI(void) cvMinMaxLoc( const CvArr* arr, double* min_val, double* max_val,
\r
859 CvPoint* min_loc CV_DEFAULT(NULL),
\r
860 CvPoint* max_loc CV_DEFAULT(NULL),
\r
861 const CvArr* mask CV_DEFAULT(NULL) );
\r
863 /* types of array norm */
\r
867 #define CV_NORM_MASK 7
\r
868 #define CV_RELATIVE 8
\r
870 #define CV_MINMAX 32
\r
872 #define CV_DIFF_C (CV_DIFF | CV_C)
\r
873 #define CV_DIFF_L1 (CV_DIFF | CV_L1)
\r
874 #define CV_DIFF_L2 (CV_DIFF | CV_L2)
\r
875 #define CV_RELATIVE_C (CV_RELATIVE | CV_C)
\r
876 #define CV_RELATIVE_L1 (CV_RELATIVE | CV_L1)
\r
877 #define CV_RELATIVE_L2 (CV_RELATIVE | CV_L2)
\r
879 /* Finds norm, difference norm or relative difference norm for an array (or two arrays) */
\r
880 CVAPI(double) cvNorm( const CvArr* arr1, const CvArr* arr2 CV_DEFAULT(NULL),
\r
881 int norm_type CV_DEFAULT(CV_L2),
\r
882 const CvArr* mask CV_DEFAULT(NULL) );
\r
884 CVAPI(void) cvNormalize( const CvArr* src, CvArr* dst,
\r
885 double a CV_DEFAULT(1.), double b CV_DEFAULT(0.),
\r
886 int norm_type CV_DEFAULT(CV_L2),
\r
887 const CvArr* mask CV_DEFAULT(NULL) );
\r
890 #define CV_REDUCE_SUM 0
\r
891 #define CV_REDUCE_AVG 1
\r
892 #define CV_REDUCE_MAX 2
\r
893 #define CV_REDUCE_MIN 3
\r
895 CVAPI(void) cvReduce( const CvArr* src, CvArr* dst, int dim CV_DEFAULT(-1),
\r
896 int op CV_DEFAULT(CV_REDUCE_SUM) );
\r
898 /****************************************************************************************\
\r
899 * Discrete Linear Transforms and Related Functions *
\r
900 \****************************************************************************************/
\r
902 #define CV_DXT_FORWARD 0
\r
903 #define CV_DXT_INVERSE 1
\r
904 #define CV_DXT_SCALE 2 /* divide result by size of array */
\r
905 #define CV_DXT_INV_SCALE (CV_DXT_INVERSE + CV_DXT_SCALE)
\r
906 #define CV_DXT_INVERSE_SCALE CV_DXT_INV_SCALE
\r
907 #define CV_DXT_ROWS 4 /* transform each row individually */
\r
908 #define CV_DXT_MUL_CONJ 8 /* conjugate the second argument of cvMulSpectrums */
\r
910 /* Discrete Fourier Transform:
\r
912 real->ccs (forward),
\r
913 ccs->real (inverse) */
\r
914 CVAPI(void) cvDFT( const CvArr* src, CvArr* dst, int flags,
\r
915 int nonzero_rows CV_DEFAULT(0) );
\r
916 #define cvFFT cvDFT
\r
918 /* Multiply results of DFTs: DFT(X)*DFT(Y) or DFT(X)*conj(DFT(Y)) */
\r
919 CVAPI(void) cvMulSpectrums( const CvArr* src1, const CvArr* src2,
\r
920 CvArr* dst, int flags );
\r
922 /* Finds optimal DFT vector size >= size0 */
\r
923 CVAPI(int) cvGetOptimalDFTSize( int size0 );
\r
925 /* Discrete Cosine Transform */
\r
926 CVAPI(void) cvDCT( const CvArr* src, CvArr* dst, int flags );
\r
928 /****************************************************************************************\
\r
929 * Dynamic data structures *
\r
930 \****************************************************************************************/
\r
932 /* Calculates length of sequence slice (with support of negative indices). */
\r
933 CVAPI(int) cvSliceLength( CvSlice slice, const CvSeq* seq );
\r
936 /* Creates new memory storage.
\r
937 block_size == 0 means that default,
\r
938 somewhat optimal size, is used (currently, it is 64K) */
\r
939 CVAPI(CvMemStorage*) cvCreateMemStorage( int block_size CV_DEFAULT(0));
\r
942 /* Creates a memory storage that will borrow memory blocks from parent storage */
\r
943 CVAPI(CvMemStorage*) cvCreateChildMemStorage( CvMemStorage* parent );
\r
946 /* Releases memory storage. All the children of a parent must be released before
\r
947 the parent. A child storage returns all the blocks to parent when it is released */
\r
948 CVAPI(void) cvReleaseMemStorage( CvMemStorage** storage );
\r
951 /* Clears memory storage. This is the only way(!!!) (besides cvRestoreMemStoragePos)
\r
952 to reuse memory allocated for the storage - cvClearSeq,cvClearSet ...
\r
953 do not free any memory.
\r
954 A child storage returns all the blocks to the parent when it is cleared */
\r
955 CVAPI(void) cvClearMemStorage( CvMemStorage* storage );
\r
957 /* Remember a storage "free memory" position */
\r
958 CVAPI(void) cvSaveMemStoragePos( const CvMemStorage* storage, CvMemStoragePos* pos );
\r
960 /* Restore a storage "free memory" position */
\r
961 CVAPI(void) cvRestoreMemStoragePos( CvMemStorage* storage, CvMemStoragePos* pos );
\r
963 /* Allocates continuous buffer of the specified size in the storage */
\r
964 CVAPI(void*) cvMemStorageAlloc( CvMemStorage* storage, size_t size );
\r
966 /* Allocates string in memory storage */
\r
967 CVAPI(CvString) cvMemStorageAllocString( CvMemStorage* storage, const char* ptr,
\r
968 int len CV_DEFAULT(-1) );
\r
970 /* Creates new empty sequence that will reside in the specified storage */
\r
971 CVAPI(CvSeq*) cvCreateSeq( int seq_flags, int header_size,
\r
972 int elem_size, CvMemStorage* storage );
\r
974 /* Changes default size (granularity) of sequence blocks.
\r
975 The default size is ~1Kbyte */
\r
976 CVAPI(void) cvSetSeqBlockSize( CvSeq* seq, int delta_elems );
\r
979 /* Adds new element to the end of sequence. Returns pointer to the element */
\r
980 CVAPI(schar*) cvSeqPush( CvSeq* seq, const void* element CV_DEFAULT(NULL));
\r
983 /* Adds new element to the beginning of sequence. Returns pointer to it */
\r
984 CVAPI(schar*) cvSeqPushFront( CvSeq* seq, const void* element CV_DEFAULT(NULL));
\r
987 /* Removes the last element from sequence and optionally saves it */
\r
988 CVAPI(void) cvSeqPop( CvSeq* seq, void* element CV_DEFAULT(NULL));
\r
991 /* Removes the first element from sequence and optioanally saves it */
\r
992 CVAPI(void) cvSeqPopFront( CvSeq* seq, void* element CV_DEFAULT(NULL));
\r
997 /* Adds several new elements to the end of sequence */
\r
998 CVAPI(void) cvSeqPushMulti( CvSeq* seq, const void* elements,
\r
999 int count, int in_front CV_DEFAULT(0) );
\r
1001 /* Removes several elements from the end of sequence and optionally saves them */
\r
1002 CVAPI(void) cvSeqPopMulti( CvSeq* seq, void* elements,
\r
1003 int count, int in_front CV_DEFAULT(0) );
\r
1005 /* Inserts a new element in the middle of sequence.
\r
1006 cvSeqInsert(seq,0,elem) == cvSeqPushFront(seq,elem) */
\r
1007 CVAPI(schar*) cvSeqInsert( CvSeq* seq, int before_index,
\r
1008 const void* element CV_DEFAULT(NULL));
\r
1010 /* Removes specified sequence element */
\r
1011 CVAPI(void) cvSeqRemove( CvSeq* seq, int index );
\r
1014 /* Removes all the elements from the sequence. The freed memory
\r
1015 can be reused later only by the same sequence unless cvClearMemStorage
\r
1016 or cvRestoreMemStoragePos is called */
\r
1017 CVAPI(void) cvClearSeq( CvSeq* seq );
\r
1020 /* Retrieves pointer to specified sequence element.
\r
1021 Negative indices are supported and mean counting from the end
\r
1022 (e.g -1 means the last sequence element) */
\r
1023 CVAPI(schar*) cvGetSeqElem( const CvSeq* seq, int index );
\r
1025 /* Calculates index of the specified sequence element.
\r
1026 Returns -1 if element does not belong to the sequence */
\r
1027 CVAPI(int) cvSeqElemIdx( const CvSeq* seq, const void* element,
\r
1028 CvSeqBlock** block CV_DEFAULT(NULL) );
\r
1030 /* Initializes sequence writer. The new elements will be added to the end of sequence */
\r
1031 CVAPI(void) cvStartAppendToSeq( CvSeq* seq, CvSeqWriter* writer );
\r
1034 /* Combination of cvCreateSeq and cvStartAppendToSeq */
\r
1035 CVAPI(void) cvStartWriteSeq( int seq_flags, int header_size,
\r
1036 int elem_size, CvMemStorage* storage,
\r
1037 CvSeqWriter* writer );
\r
1039 /* Closes sequence writer, updates sequence header and returns pointer
\r
1040 to the resultant sequence
\r
1041 (which may be useful if the sequence was created using cvStartWriteSeq))
\r
1043 CVAPI(CvSeq*) cvEndWriteSeq( CvSeqWriter* writer );
\r
1046 /* Updates sequence header. May be useful to get access to some of previously
\r
1047 written elements via cvGetSeqElem or sequence reader */
\r
1048 CVAPI(void) cvFlushSeqWriter( CvSeqWriter* writer );
\r
1051 /* Initializes sequence reader.
\r
1052 The sequence can be read in forward or backward direction */
\r
1053 CVAPI(void) cvStartReadSeq( const CvSeq* seq, CvSeqReader* reader,
\r
1054 int reverse CV_DEFAULT(0) );
\r
1057 /* Returns current sequence reader position (currently observed sequence element) */
\r
1058 CVAPI(int) cvGetSeqReaderPos( CvSeqReader* reader );
\r
1061 /* Changes sequence reader position. It may seek to an absolute or
\r
1062 to relative to the current position */
\r
1063 CVAPI(void) cvSetSeqReaderPos( CvSeqReader* reader, int index,
\r
1064 int is_relative CV_DEFAULT(0));
\r
1066 /* Copies sequence content to a continuous piece of memory */
\r
1067 CVAPI(void*) cvCvtSeqToArray( const CvSeq* seq, void* elements,
\r
1068 CvSlice slice CV_DEFAULT(CV_WHOLE_SEQ) );
\r
1070 /* Creates sequence header for array.
\r
1071 After that all the operations on sequences that do not alter the content
\r
1072 can be applied to the resultant sequence */
\r
1073 CVAPI(CvSeq*) cvMakeSeqHeaderForArray( int seq_type, int header_size,
\r
1074 int elem_size, void* elements, int total,
\r
1075 CvSeq* seq, CvSeqBlock* block );
\r
1077 /* Extracts sequence slice (with or without copying sequence elements) */
\r
1078 CVAPI(CvSeq*) cvSeqSlice( const CvSeq* seq, CvSlice slice,
\r
1079 CvMemStorage* storage CV_DEFAULT(NULL),
\r
1080 int copy_data CV_DEFAULT(0));
\r
1082 CV_INLINE CvSeq* cvCloneSeq( const CvSeq* seq, CvMemStorage* storage CV_DEFAULT(NULL))
\r
1084 return cvSeqSlice( seq, CV_WHOLE_SEQ, storage, 1 );
\r
1087 /* Removes sequence slice */
\r
1088 CVAPI(void) cvSeqRemoveSlice( CvSeq* seq, CvSlice slice );
\r
1090 /* Inserts a sequence or array into another sequence */
\r
1091 CVAPI(void) cvSeqInsertSlice( CvSeq* seq, int before_index, const CvArr* from_arr );
\r
1093 /* a < b ? -1 : a > b ? 1 : 0 */
\r
1094 typedef int (CV_CDECL* CvCmpFunc)(const void* a, const void* b, void* userdata );
\r
1096 /* Sorts sequence in-place given element comparison function */
\r
1097 CVAPI(void) cvSeqSort( CvSeq* seq, CvCmpFunc func, void* userdata CV_DEFAULT(NULL) );
\r
1099 /* Finds element in a [sorted] sequence */
\r
1100 CVAPI(schar*) cvSeqSearch( CvSeq* seq, const void* elem, CvCmpFunc func,
\r
1101 int is_sorted, int* elem_idx,
\r
1102 void* userdata CV_DEFAULT(NULL) );
\r
1104 /* Reverses order of sequence elements in-place */
\r
1105 CVAPI(void) cvSeqInvert( CvSeq* seq );
\r
1107 /* Splits sequence into one or more equivalence classes using the specified criteria */
\r
1108 CVAPI(int) cvSeqPartition( const CvSeq* seq, CvMemStorage* storage,
\r
1109 CvSeq** labels, CvCmpFunc is_equal, void* userdata );
\r
1111 /************ Internal sequence functions ************/
\r
1112 CVAPI(void) cvChangeSeqBlock( void* reader, int direction );
\r
1113 CVAPI(void) cvCreateSeqBlock( CvSeqWriter* writer );
\r
1116 /* Creates a new set */
\r
1117 CVAPI(CvSet*) cvCreateSet( int set_flags, int header_size,
\r
1118 int elem_size, CvMemStorage* storage );
\r
1120 /* Adds new element to the set and returns pointer to it */
\r
1121 CVAPI(int) cvSetAdd( CvSet* set_header, CvSetElem* elem CV_DEFAULT(NULL),
\r
1122 CvSetElem** inserted_elem CV_DEFAULT(NULL) );
\r
1124 /* Fast variant of cvSetAdd */
\r
1125 CV_INLINE CvSetElem* cvSetNew( CvSet* set_header )
\r
1127 CvSetElem* elem = set_header->free_elems;
\r
1130 set_header->free_elems = elem->next_free;
\r
1131 elem->flags = elem->flags & CV_SET_ELEM_IDX_MASK;
\r
1132 set_header->active_count++;
\r
1135 cvSetAdd( set_header, NULL, (CvSetElem**)&elem );
\r
1139 /* Removes set element given its pointer */
\r
1140 CV_INLINE void cvSetRemoveByPtr( CvSet* set_header, void* elem )
\r
1142 CvSetElem* _elem = (CvSetElem*)elem;
\r
1143 assert( _elem->flags >= 0 /*&& (elem->flags & CV_SET_ELEM_IDX_MASK) < set_header->total*/ );
\r
1144 _elem->next_free = set_header->free_elems;
\r
1145 _elem->flags = (_elem->flags & CV_SET_ELEM_IDX_MASK) | CV_SET_ELEM_FREE_FLAG;
\r
1146 set_header->free_elems = _elem;
\r
1147 set_header->active_count--;
\r
1150 /* Removes element from the set by its index */
\r
1151 CVAPI(void) cvSetRemove( CvSet* set_header, int index );
\r
1153 /* Returns a set element by index. If the element doesn't belong to the set,
\r
1154 NULL is returned */
\r
1155 CV_INLINE CvSetElem* cvGetSetElem( const CvSet* set_header, int index )
\r
1157 CvSetElem* elem = (CvSetElem*)cvGetSeqElem( (CvSeq*)set_header, index );
\r
1158 return elem && CV_IS_SET_ELEM( elem ) ? elem : 0;
\r
1161 /* Removes all the elements from the set */
\r
1162 CVAPI(void) cvClearSet( CvSet* set_header );
\r
1164 /* Creates new graph */
\r
1165 CVAPI(CvGraph*) cvCreateGraph( int graph_flags, int header_size,
\r
1166 int vtx_size, int edge_size,
\r
1167 CvMemStorage* storage );
\r
1169 /* Adds new vertex to the graph */
\r
1170 CVAPI(int) cvGraphAddVtx( CvGraph* graph, const CvGraphVtx* vtx CV_DEFAULT(NULL),
\r
1171 CvGraphVtx** inserted_vtx CV_DEFAULT(NULL) );
\r
1174 /* Removes vertex from the graph together with all incident edges */
\r
1175 CVAPI(int) cvGraphRemoveVtx( CvGraph* graph, int index );
\r
1176 CVAPI(int) cvGraphRemoveVtxByPtr( CvGraph* graph, CvGraphVtx* vtx );
\r
1179 /* Link two vertices specifed by indices or pointers if they
\r
1180 are not connected or return pointer to already existing edge
\r
1181 connecting the vertices.
\r
1182 Functions return 1 if a new edge was created, 0 otherwise */
\r
1183 CVAPI(int) cvGraphAddEdge( CvGraph* graph,
\r
1184 int start_idx, int end_idx,
\r
1185 const CvGraphEdge* edge CV_DEFAULT(NULL),
\r
1186 CvGraphEdge** inserted_edge CV_DEFAULT(NULL) );
\r
1188 CVAPI(int) cvGraphAddEdgeByPtr( CvGraph* graph,
\r
1189 CvGraphVtx* start_vtx, CvGraphVtx* end_vtx,
\r
1190 const CvGraphEdge* edge CV_DEFAULT(NULL),
\r
1191 CvGraphEdge** inserted_edge CV_DEFAULT(NULL) );
\r
1193 /* Remove edge connecting two vertices */
\r
1194 CVAPI(void) cvGraphRemoveEdge( CvGraph* graph, int start_idx, int end_idx );
\r
1195 CVAPI(void) cvGraphRemoveEdgeByPtr( CvGraph* graph, CvGraphVtx* start_vtx,
\r
1196 CvGraphVtx* end_vtx );
\r
1198 /* Find edge connecting two vertices */
\r
1199 CVAPI(CvGraphEdge*) cvFindGraphEdge( const CvGraph* graph, int start_idx, int end_idx );
\r
1200 CVAPI(CvGraphEdge*) cvFindGraphEdgeByPtr( const CvGraph* graph,
\r
1201 const CvGraphVtx* start_vtx,
\r
1202 const CvGraphVtx* end_vtx );
\r
1203 #define cvGraphFindEdge cvFindGraphEdge
\r
1204 #define cvGraphFindEdgeByPtr cvFindGraphEdgeByPtr
\r
1206 /* Remove all vertices and edges from the graph */
\r
1207 CVAPI(void) cvClearGraph( CvGraph* graph );
\r
1210 /* Count number of edges incident to the vertex */
\r
1211 CVAPI(int) cvGraphVtxDegree( const CvGraph* graph, int vtx_idx );
\r
1212 CVAPI(int) cvGraphVtxDegreeByPtr( const CvGraph* graph, const CvGraphVtx* vtx );
\r
1215 /* Retrieves graph vertex by given index */
\r
1216 #define cvGetGraphVtx( graph, idx ) (CvGraphVtx*)cvGetSetElem((CvSet*)(graph), (idx))
\r
1218 /* Retrieves index of a graph vertex given its pointer */
\r
1219 #define cvGraphVtxIdx( graph, vtx ) ((vtx)->flags & CV_SET_ELEM_IDX_MASK)
\r
1221 /* Retrieves index of a graph edge given its pointer */
\r
1222 #define cvGraphEdgeIdx( graph, edge ) ((edge)->flags & CV_SET_ELEM_IDX_MASK)
\r
1224 #define cvGraphGetVtxCount( graph ) ((graph)->active_count)
\r
1225 #define cvGraphGetEdgeCount( graph ) ((graph)->edges->active_count)
\r
1227 #define CV_GRAPH_VERTEX 1
\r
1228 #define CV_GRAPH_TREE_EDGE 2
\r
1229 #define CV_GRAPH_BACK_EDGE 4
\r
1230 #define CV_GRAPH_FORWARD_EDGE 8
\r
1231 #define CV_GRAPH_CROSS_EDGE 16
\r
1232 #define CV_GRAPH_ANY_EDGE 30
\r
1233 #define CV_GRAPH_NEW_TREE 32
\r
1234 #define CV_GRAPH_BACKTRACKING 64
\r
1235 #define CV_GRAPH_OVER -1
\r
1237 #define CV_GRAPH_ALL_ITEMS -1
\r
1239 /* flags for graph vertices and edges */
\r
1240 #define CV_GRAPH_ITEM_VISITED_FLAG (1 << 30)
\r
1241 #define CV_IS_GRAPH_VERTEX_VISITED(vtx) \
\r
1242 (((CvGraphVtx*)(vtx))->flags & CV_GRAPH_ITEM_VISITED_FLAG)
\r
1243 #define CV_IS_GRAPH_EDGE_VISITED(edge) \
\r
1244 (((CvGraphEdge*)(edge))->flags & CV_GRAPH_ITEM_VISITED_FLAG)
\r
1245 #define CV_GRAPH_SEARCH_TREE_NODE_FLAG (1 << 29)
\r
1246 #define CV_GRAPH_FORWARD_EDGE_FLAG (1 << 28)
\r
1248 typedef struct CvGraphScanner
\r
1250 CvGraphVtx* vtx; /* current graph vertex (or current edge origin) */
\r
1251 CvGraphVtx* dst; /* current graph edge destination vertex */
\r
1252 CvGraphEdge* edge; /* current edge */
\r
1254 CvGraph* graph; /* the graph */
\r
1255 CvSeq* stack; /* the graph vertex stack */
\r
1256 int index; /* the lower bound of certainly visited vertices */
\r
1257 int mask; /* event mask */
\r
1261 /* Creates new graph scanner. */
\r
1262 CVAPI(CvGraphScanner*) cvCreateGraphScanner( CvGraph* graph,
\r
1263 CvGraphVtx* vtx CV_DEFAULT(NULL),
\r
1264 int mask CV_DEFAULT(CV_GRAPH_ALL_ITEMS));
\r
1266 /* Releases graph scanner. */
\r
1267 CVAPI(void) cvReleaseGraphScanner( CvGraphScanner** scanner );
\r
1269 /* Get next graph element */
\r
1270 CVAPI(int) cvNextGraphItem( CvGraphScanner* scanner );
\r
1272 /* Creates a copy of graph */
\r
1273 CVAPI(CvGraph*) cvCloneGraph( const CvGraph* graph, CvMemStorage* storage );
\r
1275 /****************************************************************************************\
\r
1277 \****************************************************************************************/
\r
1279 /****************************************************************************************\
\r
1280 * Drawing functions work with images/matrices of arbitrary type. *
\r
1281 * For color images the channel order is BGR[A] *
\r
1282 * Antialiasing is supported only for 8-bit image now. *
\r
1283 * All the functions include parameter color that means rgb value (that may be *
\r
1284 * constructed with CV_RGB macro) for color images and brightness *
\r
1285 * for grayscale images. *
\r
1286 * If a drawn figure is partially or completely outside of the image, it is clipped.*
\r
1287 \****************************************************************************************/
\r
1289 #define CV_RGB( r, g, b ) cvScalar( (b), (g), (r), 0 )
\r
1290 #define CV_FILLED -1
\r
1294 /* Draws 4-connected, 8-connected or antialiased line segment connecting two points */
\r
1295 CVAPI(void) cvLine( CvArr* img, CvPoint pt1, CvPoint pt2,
\r
1296 CvScalar color, int thickness CV_DEFAULT(1),
\r
1297 int line_type CV_DEFAULT(8), int shift CV_DEFAULT(0) );
\r
1299 /* Draws a rectangle given two opposite corners of the rectangle (pt1 & pt2),
\r
1300 if thickness<0 (e.g. thickness == CV_FILLED), the filled box is drawn */
\r
1301 CVAPI(void) cvRectangle( CvArr* img, CvPoint pt1, CvPoint pt2,
\r
1302 CvScalar color, int thickness CV_DEFAULT(1),
\r
1303 int line_type CV_DEFAULT(8),
\r
1304 int shift CV_DEFAULT(0));
\r
1306 /* Draws a circle with specified center and radius.
\r
1307 Thickness works in the same way as with cvRectangle */
\r
1308 CVAPI(void) cvCircle( CvArr* img, CvPoint center, int radius,
\r
1309 CvScalar color, int thickness CV_DEFAULT(1),
\r
1310 int line_type CV_DEFAULT(8), int shift CV_DEFAULT(0));
\r
1312 /* Draws ellipse outline, filled ellipse, elliptic arc or filled elliptic sector,
\r
1313 depending on <thickness>, <start_angle> and <end_angle> parameters. The resultant figure
\r
1314 is rotated by <angle>. All the angles are in degrees */
\r
1315 CVAPI(void) cvEllipse( CvArr* img, CvPoint center, CvSize axes,
\r
1316 double angle, double start_angle, double end_angle,
\r
1317 CvScalar color, int thickness CV_DEFAULT(1),
\r
1318 int line_type CV_DEFAULT(8), int shift CV_DEFAULT(0));
\r
1320 CV_INLINE void cvEllipseBox( CvArr* img, CvBox2D box, CvScalar color,
\r
1321 int thickness CV_DEFAULT(1),
\r
1322 int line_type CV_DEFAULT(8), int shift CV_DEFAULT(0) )
\r
1325 axes.width = cvRound(box.size.height*0.5);
\r
1326 axes.height = cvRound(box.size.width*0.5);
\r
1328 cvEllipse( img, cvPointFrom32f( box.center ), axes, box.angle,
\r
1329 0, 360, color, thickness, line_type, shift );
\r
1332 /* Fills convex or monotonous polygon. */
\r
1333 CVAPI(void) cvFillConvexPoly( CvArr* img, const CvPoint* pts, int npts, CvScalar color,
\r
1334 int line_type CV_DEFAULT(8), int shift CV_DEFAULT(0));
\r
1336 /* Fills an area bounded by one or more arbitrary polygons */
\r
1337 CVAPI(void) cvFillPoly( CvArr* img, CvPoint** pts, const int* npts,
\r
1338 int contours, CvScalar color,
\r
1339 int line_type CV_DEFAULT(8), int shift CV_DEFAULT(0) );
\r
1341 /* Draws one or more polygonal curves */
\r
1342 CVAPI(void) cvPolyLine( CvArr* img, CvPoint** pts, const int* npts, int contours,
\r
1343 int is_closed, CvScalar color, int thickness CV_DEFAULT(1),
\r
1344 int line_type CV_DEFAULT(8), int shift CV_DEFAULT(0) );
\r
1346 #define cvDrawRect cvRectangle
\r
1347 #define cvDrawLine cvLine
\r
1348 #define cvDrawCircle cvCircle
\r
1349 #define cvDrawEllipse cvEllipse
\r
1350 #define cvDrawPolyLine cvPolyLine
\r
1352 /* Clips the line segment connecting *pt1 and *pt2
\r
1353 by the rectangular window
\r
1354 (0<=x<img_size.width, 0<=y<img_size.height). */
\r
1355 CVAPI(int) cvClipLine( CvSize img_size, CvPoint* pt1, CvPoint* pt2 );
\r
1357 /* Initializes line iterator. Initially, line_iterator->ptr will point
\r
1358 to pt1 (or pt2, see left_to_right description) location in the image.
\r
1359 Returns the number of pixels on the line between the ending points. */
\r
1360 CVAPI(int) cvInitLineIterator( const CvArr* image, CvPoint pt1, CvPoint pt2,
\r
1361 CvLineIterator* line_iterator,
\r
1362 int connectivity CV_DEFAULT(8),
\r
1363 int left_to_right CV_DEFAULT(0));
\r
1365 /* Moves iterator to the next line point */
\r
1366 #define CV_NEXT_LINE_POINT( line_iterator ) \
\r
1368 int _line_iterator_mask = (line_iterator).err < 0 ? -1 : 0; \
\r
1369 (line_iterator).err += (line_iterator).minus_delta + \
\r
1370 ((line_iterator).plus_delta & _line_iterator_mask); \
\r
1371 (line_iterator).ptr += (line_iterator).minus_step + \
\r
1372 ((line_iterator).plus_step & _line_iterator_mask); \
\r
1376 /* basic font types */
\r
1377 #define CV_FONT_HERSHEY_SIMPLEX 0
\r
1378 #define CV_FONT_HERSHEY_PLAIN 1
\r
1379 #define CV_FONT_HERSHEY_DUPLEX 2
\r
1380 #define CV_FONT_HERSHEY_COMPLEX 3
\r
1381 #define CV_FONT_HERSHEY_TRIPLEX 4
\r
1382 #define CV_FONT_HERSHEY_COMPLEX_SMALL 5
\r
1383 #define CV_FONT_HERSHEY_SCRIPT_SIMPLEX 6
\r
1384 #define CV_FONT_HERSHEY_SCRIPT_COMPLEX 7
\r
1387 #define CV_FONT_ITALIC 16
\r
1389 #define CV_FONT_VECTOR0 CV_FONT_HERSHEY_SIMPLEX
\r
1391 /* Font structure */
\r
1392 typedef struct CvFont
\r
1394 int font_face; /* =CV_FONT_* */
\r
1395 const int* ascii; /* font data and metrics */
\r
1397 const int* cyrillic;
\r
1398 float hscale, vscale;
\r
1399 float shear; /* slope coefficient: 0 - normal, >0 - italic */
\r
1400 int thickness; /* letters thickness */
\r
1401 float dx; /* horizontal interval between letters */
\r
1406 /* Initializes font structure used further in cvPutText */
\r
1407 CVAPI(void) cvInitFont( CvFont* font, int font_face,
\r
1408 double hscale, double vscale,
\r
1409 double shear CV_DEFAULT(0),
\r
1410 int thickness CV_DEFAULT(1),
\r
1411 int line_type CV_DEFAULT(8));
\r
1413 CV_INLINE CvFont cvFont( double scale, int thickness CV_DEFAULT(1) )
\r
1416 cvInitFont( &font, CV_FONT_HERSHEY_PLAIN, scale, scale, 0, thickness, CV_AA );
\r
1420 /* Renders text stroke with specified font and color at specified location.
\r
1421 CvFont should be initialized with cvInitFont */
\r
1422 CVAPI(void) cvPutText( CvArr* img, const char* text, CvPoint org,
\r
1423 const CvFont* font, CvScalar color );
\r
1425 /* Calculates bounding box of text stroke (useful for alignment) */
\r
1426 CVAPI(void) cvGetTextSize( const char* text_string, const CvFont* font,
\r
1427 CvSize* text_size, int* baseline );
\r
1429 /* Unpacks color value, if arrtype is CV_8UC?, <color> is treated as
\r
1430 packed color value, otherwise the first channels (depending on arrtype)
\r
1431 of destination scalar are set to the same value = <color> */
\r
1432 CVAPI(CvScalar) cvColorToScalar( double packed_color, int arrtype );
\r
1434 /* Returns the polygon points which make up the given ellipse. The ellipse is define by
\r
1435 the box of size 'axes' rotated 'angle' around the 'center'. A partial sweep
\r
1436 of the ellipse arc can be done by spcifying arc_start and arc_end to be something
\r
1437 other than 0 and 360, respectively. The input array 'pts' must be large enough to
\r
1438 hold the result. The total number of points stored into 'pts' is returned by this
\r
1440 CVAPI(int) cvEllipse2Poly( CvPoint center, CvSize axes,
\r
1441 int angle, int arc_start, int arc_end, CvPoint * pts, int delta );
\r
1443 /* Draws contour outlines or filled interiors on the image */
\r
1444 CVAPI(void) cvDrawContours( CvArr *img, CvSeq* contour,
\r
1445 CvScalar external_color, CvScalar hole_color,
\r
1446 int max_level, int thickness CV_DEFAULT(1),
\r
1447 int line_type CV_DEFAULT(8),
\r
1448 CvPoint offset CV_DEFAULT(cvPoint(0,0)));
\r
1450 /* Does look-up transformation. Elements of the source array
\r
1451 (that should be 8uC1 or 8sC1) are used as indexes in lutarr 256-element table */
\r
1452 CVAPI(void) cvLUT( const CvArr* src, CvArr* dst, const CvArr* lut );
\r
1455 /******************* Iteration through the sequence tree *****************/
\r
1456 typedef struct CvTreeNodeIterator
\r
1462 CvTreeNodeIterator;
\r
1464 CVAPI(void) cvInitTreeNodeIterator( CvTreeNodeIterator* tree_iterator,
\r
1465 const void* first, int max_level );
\r
1466 CVAPI(void*) cvNextTreeNode( CvTreeNodeIterator* tree_iterator );
\r
1467 CVAPI(void*) cvPrevTreeNode( CvTreeNodeIterator* tree_iterator );
\r
1469 /* Inserts sequence into tree with specified "parent" sequence.
\r
1470 If parent is equal to frame (e.g. the most external contour),
\r
1471 then added contour will have null pointer to parent. */
\r
1472 CVAPI(void) cvInsertNodeIntoTree( void* node, void* parent, void* frame );
\r
1474 /* Removes contour from tree (together with the contour children). */
\r
1475 CVAPI(void) cvRemoveNodeFromTree( void* node, void* frame );
\r
1477 /* Gathers pointers to all the sequences,
\r
1478 accessible from the <first>, to the single sequence */
\r
1479 CVAPI(CvSeq*) cvTreeToNodeSeq( const void* first, int header_size,
\r
1480 CvMemStorage* storage );
\r
1482 /* The function implements the K-means algorithm for clustering an array of sample
\r
1483 vectors in a specified number of classes */
\r
1484 #define CV_KMEANS_USE_INITIAL_LABELS 1
\r
1485 CVAPI(int) cvKMeans2( const CvArr* samples, int cluster_count, CvArr* labels,
\r
1486 CvTermCriteria termcrit, int attempts CV_DEFAULT(1),
\r
1487 CvRNG* rng CV_DEFAULT(0), int flags CV_DEFAULT(0),
\r
1488 CvArr* _centers CV_DEFAULT(0), double* compactness CV_DEFAULT(0) );
\r
1490 /****************************************************************************************\
\r
1491 * System functions *
\r
1492 \****************************************************************************************/
\r
1494 /* Add the function pointers table with associated information to the IPP primitives list */
\r
1495 CVAPI(int) cvRegisterModule( const CvModuleInfo* module_info );
\r
1497 /* Loads optimized functions from IPP, MKL etc. or switches back to pure C code */
\r
1498 CVAPI(int) cvUseOptimized( int on_off );
\r
1500 /* Retrieves information about the registered modules and loaded optimized plugins */
\r
1501 CVAPI(void) cvGetModuleInfo( const char* module_name,
\r
1502 const char** version,
\r
1503 const char** loaded_addon_plugins );
\r
1505 /* Get current OpenCV error status */
\r
1506 CVAPI(int) cvGetErrStatus( void );
\r
1508 /* Sets error status silently */
\r
1509 CVAPI(void) cvSetErrStatus( int status );
\r
1511 #define CV_ErrModeLeaf 0 /* Print error and exit program */
\r
1512 #define CV_ErrModeParent 1 /* Print error and continue */
\r
1513 #define CV_ErrModeSilent 2 /* Don't print and continue */
\r
1515 /* Retrives current error processing mode */
\r
1516 CVAPI(int) cvGetErrMode( void );
\r
1518 /* Sets error processing mode, returns previously used mode */
\r
1519 CVAPI(int) cvSetErrMode( int mode );
\r
1521 /* Sets error status and performs some additonal actions (displaying message box,
\r
1522 writing message to stderr, terminating application etc.)
\r
1523 depending on the current error mode */
\r
1524 CVAPI(void) cvError( int status, const char* func_name,
\r
1525 const char* err_msg, const char* file_name, int line );
\r
1527 /* Retrieves textual description of the error given its code */
\r
1528 CVAPI(const char*) cvErrorStr( int status );
\r
1530 /* Retrieves detailed information about the last error occured */
\r
1531 CVAPI(int) cvGetErrInfo( const char** errcode_desc, const char** description,
\r
1532 const char** filename, int* line );
\r
1534 /* Maps IPP error codes to the counterparts from OpenCV */
\r
1535 CVAPI(int) cvErrorFromIppStatus( int ipp_status );
\r
1537 typedef int (CV_CDECL *CvErrorCallback)( int status, const char* func_name,
\r
1538 const char* err_msg, const char* file_name, int line, void* userdata );
\r
1540 /* Assigns a new error-handling function */
\r
1541 CVAPI(CvErrorCallback) cvRedirectError( CvErrorCallback error_handler,
\r
1542 void* userdata CV_DEFAULT(NULL),
\r
1543 void** prev_userdata CV_DEFAULT(NULL) );
\r
1547 cvNulDevReport - nothing
\r
1548 cvStdErrReport - console(fprintf(stderr,...))
\r
1549 cvGuiBoxReport - MessageBox(WIN32)
\r
1551 CVAPI(int) cvNulDevReport( int status, const char* func_name, const char* err_msg,
\r
1552 const char* file_name, int line, void* userdata );
\r
1554 CVAPI(int) cvStdErrReport( int status, const char* func_name, const char* err_msg,
\r
1555 const char* file_name, int line, void* userdata );
\r
1557 CVAPI(int) cvGuiBoxReport( int status, const char* func_name, const char* err_msg,
\r
1558 const char* file_name, int line, void* userdata );
\r
1560 typedef void* (CV_CDECL *CvAllocFunc)(size_t size, void* userdata);
\r
1561 typedef int (CV_CDECL *CvFreeFunc)(void* pptr, void* userdata);
\r
1563 /* Set user-defined memory managment functions (substitutors for malloc and free) that
\r
1564 will be called by cvAlloc, cvFree and higher-level functions (e.g. cvCreateImage) */
\r
1565 CVAPI(void) cvSetMemoryManager( CvAllocFunc alloc_func CV_DEFAULT(NULL),
\r
1566 CvFreeFunc free_func CV_DEFAULT(NULL),
\r
1567 void* userdata CV_DEFAULT(NULL));
\r
1570 typedef IplImage* (CV_STDCALL* Cv_iplCreateImageHeader)
\r
1571 (int,int,int,char*,char*,int,int,int,int,int,
\r
1572 IplROI*,IplImage*,void*,IplTileInfo*);
\r
1573 typedef void (CV_STDCALL* Cv_iplAllocateImageData)(IplImage*,int,int);
\r
1574 typedef void (CV_STDCALL* Cv_iplDeallocate)(IplImage*,int);
\r
1575 typedef IplROI* (CV_STDCALL* Cv_iplCreateROI)(int,int,int,int,int);
\r
1576 typedef IplImage* (CV_STDCALL* Cv_iplCloneImage)(const IplImage*);
\r
1578 /* Makes OpenCV use IPL functions for IplImage allocation/deallocation */
\r
1579 CVAPI(void) cvSetIPLAllocators( Cv_iplCreateImageHeader create_header,
\r
1580 Cv_iplAllocateImageData allocate_data,
\r
1581 Cv_iplDeallocate deallocate,
\r
1582 Cv_iplCreateROI create_roi,
\r
1583 Cv_iplCloneImage clone_image );
\r
1585 #define CV_TURN_ON_IPL_COMPATIBILITY() \
\r
1586 cvSetIPLAllocators( iplCreateImageHeader, iplAllocateImage, \
\r
1587 iplDeallocate, iplCreateROI, iplCloneImage )
\r
1589 /****************************************************************************************\
\r
1590 * Data Persistence *
\r
1591 \****************************************************************************************/
\r
1593 /********************************** High-level functions ********************************/
\r
1595 /* opens existing or creates new file storage */
\r
1596 CVAPI(CvFileStorage*) cvOpenFileStorage( const char* filename,
\r
1597 CvMemStorage* memstorage,
\r
1600 /* closes file storage and deallocates buffers */
\r
1601 CVAPI(void) cvReleaseFileStorage( CvFileStorage** fs );
\r
1603 /* returns attribute value or 0 (NULL) if there is no such attribute */
\r
1604 CVAPI(const char*) cvAttrValue( const CvAttrList* attr, const char* attr_name );
\r
1606 /* starts writing compound structure (map or sequence) */
\r
1607 CVAPI(void) cvStartWriteStruct( CvFileStorage* fs, const char* name,
\r
1608 int struct_flags, const char* type_name CV_DEFAULT(NULL),
\r
1609 CvAttrList attributes CV_DEFAULT(cvAttrList()));
\r
1611 /* finishes writing compound structure */
\r
1612 CVAPI(void) cvEndWriteStruct( CvFileStorage* fs );
\r
1614 /* writes an integer */
\r
1615 CVAPI(void) cvWriteInt( CvFileStorage* fs, const char* name, int value );
\r
1617 /* writes a floating-point number */
\r
1618 CVAPI(void) cvWriteReal( CvFileStorage* fs, const char* name, double value );
\r
1620 /* writes a string */
\r
1621 CVAPI(void) cvWriteString( CvFileStorage* fs, const char* name,
\r
1622 const char* str, int quote CV_DEFAULT(0) );
\r
1624 /* writes a comment */
\r
1625 CVAPI(void) cvWriteComment( CvFileStorage* fs, const char* comment,
\r
1626 int eol_comment );
\r
1628 /* writes instance of a standard type (matrix, image, sequence, graph etc.)
\r
1629 or user-defined type */
\r
1630 CVAPI(void) cvWrite( CvFileStorage* fs, const char* name, const void* ptr,
\r
1631 CvAttrList attributes CV_DEFAULT(cvAttrList()));
\r
1633 /* starts the next stream */
\r
1634 CVAPI(void) cvStartNextStream( CvFileStorage* fs );
\r
1636 /* helper function: writes multiple integer or floating-point numbers */
\r
1637 CVAPI(void) cvWriteRawData( CvFileStorage* fs, const void* src,
\r
1638 int len, const char* dt );
\r
1640 /* returns the hash entry corresponding to the specified literal key string or 0
\r
1641 if there is no such a key in the storage */
\r
1642 CVAPI(CvStringHashNode*) cvGetHashedKey( CvFileStorage* fs, const char* name,
\r
1643 int len CV_DEFAULT(-1),
\r
1644 int create_missing CV_DEFAULT(0));
\r
1646 /* returns file node with the specified key within the specified map
\r
1647 (collection of named nodes) */
\r
1648 CVAPI(CvFileNode*) cvGetRootFileNode( const CvFileStorage* fs,
\r
1649 int stream_index CV_DEFAULT(0) );
\r
1651 /* returns file node with the specified key within the specified map
\r
1652 (collection of named nodes) */
\r
1653 CVAPI(CvFileNode*) cvGetFileNode( CvFileStorage* fs, CvFileNode* map,
\r
1654 const CvStringHashNode* key,
\r
1655 int create_missing CV_DEFAULT(0) );
\r
1657 /* this is a slower version of cvGetFileNode that takes the key as a literal string */
\r
1658 CVAPI(CvFileNode*) cvGetFileNodeByName( const CvFileStorage* fs,
\r
1659 const CvFileNode* map,
\r
1660 const char* name );
\r
1662 CV_INLINE int cvReadInt( const CvFileNode* node, int default_value CV_DEFAULT(0) )
\r
1664 return !node ? default_value :
\r
1665 CV_NODE_IS_INT(node->tag) ? node->data.i :
\r
1666 CV_NODE_IS_REAL(node->tag) ? cvRound(node->data.f) : 0x7fffffff;
\r
1670 CV_INLINE int cvReadIntByName( const CvFileStorage* fs, const CvFileNode* map,
\r
1671 const char* name, int default_value CV_DEFAULT(0) )
\r
1673 return cvReadInt( cvGetFileNodeByName( fs, map, name ), default_value );
\r
1677 CV_INLINE double cvReadReal( const CvFileNode* node, double default_value CV_DEFAULT(0.) )
\r
1679 return !node ? default_value :
\r
1680 CV_NODE_IS_INT(node->tag) ? (double)node->data.i :
\r
1681 CV_NODE_IS_REAL(node->tag) ? node->data.f : 1e300;
\r
1685 CV_INLINE double cvReadRealByName( const CvFileStorage* fs, const CvFileNode* map,
\r
1686 const char* name, double default_value CV_DEFAULT(0.) )
\r
1688 return cvReadReal( cvGetFileNodeByName( fs, map, name ), default_value );
\r
1692 CV_INLINE const char* cvReadString( const CvFileNode* node,
\r
1693 const char* default_value CV_DEFAULT(NULL) )
\r
1695 return !node ? default_value : CV_NODE_IS_STRING(node->tag) ? node->data.str.ptr : 0;
\r
1699 CV_INLINE const char* cvReadStringByName( const CvFileStorage* fs, const CvFileNode* map,
\r
1700 const char* name, const char* default_value CV_DEFAULT(NULL) )
\r
1702 return cvReadString( cvGetFileNodeByName( fs, map, name ), default_value );
\r
1706 /* decodes standard or user-defined object and returns it */
\r
1707 CVAPI(void*) cvRead( CvFileStorage* fs, CvFileNode* node,
\r
1708 CvAttrList* attributes CV_DEFAULT(NULL));
\r
1710 /* decodes standard or user-defined object and returns it */
\r
1711 CV_INLINE void* cvReadByName( CvFileStorage* fs, const CvFileNode* map,
\r
1712 const char* name, CvAttrList* attributes CV_DEFAULT(NULL) )
\r
1714 return cvRead( fs, cvGetFileNodeByName( fs, map, name ), attributes );
\r
1718 /* starts reading data from sequence or scalar numeric node */
\r
1719 CVAPI(void) cvStartReadRawData( const CvFileStorage* fs, const CvFileNode* src,
\r
1720 CvSeqReader* reader );
\r
1722 /* reads multiple numbers and stores them to array */
\r
1723 CVAPI(void) cvReadRawDataSlice( const CvFileStorage* fs, CvSeqReader* reader,
\r
1724 int count, void* dst, const char* dt );
\r
1726 /* combination of two previous functions for easier reading of whole sequences */
\r
1727 CVAPI(void) cvReadRawData( const CvFileStorage* fs, const CvFileNode* src,
\r
1728 void* dst, const char* dt );
\r
1730 /* writes a copy of file node to file storage */
\r
1731 CVAPI(void) cvWriteFileNode( CvFileStorage* fs, const char* new_node_name,
\r
1732 const CvFileNode* node, int embed );
\r
1734 /* returns name of file node */
\r
1735 CVAPI(const char*) cvGetFileNodeName( const CvFileNode* node );
\r
1737 /*********************************** Adding own types ***********************************/
\r
1739 CVAPI(void) cvRegisterType( const CvTypeInfo* info );
\r
1740 CVAPI(void) cvUnregisterType( const char* type_name );
\r
1741 CVAPI(CvTypeInfo*) cvFirstType(void);
\r
1742 CVAPI(CvTypeInfo*) cvFindType( const char* type_name );
\r
1743 CVAPI(CvTypeInfo*) cvTypeOf( const void* struct_ptr );
\r
1745 /* universal functions */
\r
1746 CVAPI(void) cvRelease( void** struct_ptr );
\r
1747 CVAPI(void*) cvClone( const void* struct_ptr );
\r
1749 /* simple API for reading/writing data */
\r
1750 CVAPI(void) cvSave( const char* filename, const void* struct_ptr,
\r
1751 const char* name CV_DEFAULT(NULL),
\r
1752 const char* comment CV_DEFAULT(NULL),
\r
1753 CvAttrList attributes CV_DEFAULT(cvAttrList()));
\r
1754 CVAPI(void*) cvLoad( const char* filename,
\r
1755 CvMemStorage* memstorage CV_DEFAULT(NULL),
\r
1756 const char* name CV_DEFAULT(NULL),
\r
1757 const char** real_name CV_DEFAULT(NULL) );
\r
1759 /*********************************** Measuring Execution Time ***************************/
\r
1761 /* helper functions for RNG initialization and accurate time measurement:
\r
1762 uses internal clock counter on x86 */
\r
1763 CVAPI(int64) cvGetTickCount( void );
\r
1764 CVAPI(double) cvGetTickFrequency( void );
\r
1766 /*********************************** Multi-Threading ************************************/
\r
1768 /* retrieve/set the number of threads used in OpenMP implementations */
\r
1769 CVAPI(int) cvGetNumThreads( void );
\r
1770 CVAPI(void) cvSetNumThreads( int threads CV_DEFAULT(0) );
\r
1771 /* get index of the thread being executed */
\r
1772 CVAPI(int) cvGetThreadNum( void );
\r
1774 /*************** Convenience functions for better interaction with HighGUI **************/
\r
1776 typedef IplImage* (CV_CDECL * CvLoadImageFunc)( const char* filename, int colorness );
\r
1777 typedef CvMat* (CV_CDECL * CvLoadImageMFunc)( const char* filename, int colorness );
\r
1778 typedef int (CV_CDECL * CvSaveImageFunc)( const char* filename, const CvArr* image,
\r
1779 const int* params );
\r
1780 typedef void (CV_CDECL * CvShowImageFunc)( const char* windowname, const CvArr* image );
\r
1782 CVAPI(int) cvSetImageIOFunctions( CvLoadImageFunc _load_image, CvLoadImageMFunc _load_image_m,
\r
1783 CvSaveImageFunc _save_image, CvShowImageFunc _show_image );
\r
1785 #define CV_SET_IMAGE_IO_FUNCTIONS() \
\r
1786 cvSetImageIOFunctions( cvLoadImage, cvLoadImageM, cvSaveImage, cvShowImage )
\r
1788 #ifdef __cplusplus
\r
1791 class CV_EXPORTS CvImage
\r
1794 CvImage() : image(0), refcount(0) {}
\r
1795 CvImage( CvSize size, int depth, int channels )
\r
1797 image = cvCreateImage( size, depth, channels );
\r
1798 refcount = image ? new int(1) : 0;
\r
1801 CvImage( IplImage* img ) : image(img)
\r
1803 refcount = image ? new int(1) : 0;
\r
1806 CvImage( const CvImage& img ) : image(img.image), refcount(img.refcount)
\r
1808 if( refcount ) ++(*refcount);
\r
1811 CvImage( const char* filename, const char* imgname=0, int color=-1 ) : image(0), refcount(0)
\r
1812 { load( filename, imgname, color ); }
\r
1814 CvImage( CvFileStorage* fs, const char* mapname, const char* imgname ) : image(0), refcount(0)
\r
1815 { read( fs, mapname, imgname ); }
\r
1817 CvImage( CvFileStorage* fs, const char* seqname, int idx ) : image(0), refcount(0)
\r
1818 { read( fs, seqname, idx ); }
\r
1822 if( refcount && !(--*refcount) )
\r
1824 cvReleaseImage( &image );
\r
1829 CvImage clone() { return CvImage(image ? cvCloneImage(image) : 0); }
\r
1831 void create( CvSize size, int depth, int channels )
\r
1833 if( !image || !refcount ||
\r
1834 image->width != size.width || image->height != size.height ||
\r
1835 image->depth != depth || image->nChannels != channels )
\r
1836 attach( cvCreateImage( size, depth, channels ));
\r
1839 void release() { detach(); }
\r
1840 void clear() { detach(); }
\r
1842 void attach( IplImage* img, bool use_refcount=true )
\r
1844 if( refcount && --*refcount == 0 )
\r
1846 cvReleaseImage( &image );
\r
1850 refcount = use_refcount && image ? new int(1) : 0;
\r
1855 if( refcount && --*refcount == 0 )
\r
1857 cvReleaseImage( &image );
\r
1864 bool load( const char* filename, const char* imgname=0, int color=-1 );
\r
1865 bool read( CvFileStorage* fs, const char* mapname, const char* imgname );
\r
1866 bool read( CvFileStorage* fs, const char* seqname, int idx );
\r
1867 void save( const char* filename, const char* imgname, const int* params=0 );
\r
1868 void write( CvFileStorage* fs, const char* imgname );
\r
1870 void show( const char* window_name );
\r
1871 bool is_valid() { return image != 0; }
\r
1873 int width() const { return image ? image->width : 0; }
\r
1874 int height() const { return image ? image->height : 0; }
\r
1876 CvSize size() const { return image ? cvSize(image->width, image->height) : cvSize(0,0); }
\r
1878 CvSize roi_size() const
\r
1880 return !image ? cvSize(0,0) :
\r
1881 !image->roi ? cvSize(image->width,image->height) :
\r
1882 cvSize(image->roi->width, image->roi->height);
\r
1885 CvRect roi() const
\r
1887 return !image ? cvRect(0,0,0,0) :
\r
1888 !image->roi ? cvRect(0,0,image->width,image->height) :
\r
1889 cvRect(image->roi->xOffset,image->roi->yOffset,
\r
1890 image->roi->width,image->roi->height);
\r
1893 int coi() const { return !image || !image->roi ? 0 : image->roi->coi; }
\r
1895 void set_roi(CvRect roi) { cvSetImageROI(image,roi); }
\r
1896 void reset_roi() { cvResetImageROI(image); }
\r
1897 void set_coi(int coi) { cvSetImageCOI(image,coi); }
\r
1898 int depth() const { return image ? image->depth : 0; }
\r
1899 int channels() const { return image ? image->nChannels : 0; }
\r
1900 int pix_size() const { return image ? ((image->depth & 255)>>3)*image->nChannels : 0; }
\r
1902 uchar* data() { return image ? (uchar*)image->imageData : 0; }
\r
1903 const uchar* data() const { return image ? (const uchar*)image->imageData : 0; }
\r
1904 int step() const { return image ? image->widthStep : 0; }
\r
1905 int origin() const { return image ? image->origin : 0; }
\r
1907 uchar* roi_row(int y)
\r
1912 y<image->roi->height : y<image->height);
\r
1914 return !image ? 0 :
\r
1916 (uchar*)(image->imageData + y*image->widthStep) :
\r
1917 (uchar*)(image->imageData + (y+image->roi->yOffset)*image->widthStep +
\r
1918 image->roi->xOffset*((image->depth & 255)>>3)*image->nChannels);
\r
1921 const uchar* roi_row(int y) const
\r
1926 y<image->roi->height : y<image->height);
\r
1928 return !image ? 0 :
\r
1930 (const uchar*)(image->imageData + y*image->widthStep) :
\r
1931 (const uchar*)(image->imageData + (y+image->roi->yOffset)*image->widthStep +
\r
1932 image->roi->xOffset*((image->depth & 255)>>3)*image->nChannels);
\r
1935 operator const IplImage* () const { return image; }
\r
1936 operator IplImage* () { return image; }
\r
1938 CvImage& operator = (const CvImage& img)
\r
1940 if( img.refcount )
\r
1942 if( refcount && !(--*refcount) )
\r
1943 cvReleaseImage( &image );
\r
1945 refcount=img.refcount;
\r
1955 class CV_EXPORTS CvMatrix
\r
1958 CvMatrix() : matrix(0) {}
\r
1959 CvMatrix( int rows, int cols, int type )
\r
1960 { matrix = cvCreateMat( rows, cols, type ); }
\r
1962 CvMatrix( int rows, int cols, int type, CvMat* hdr,
\r
1963 void* data=0, int step=CV_AUTOSTEP )
\r
1964 { matrix = cvInitMatHeader( hdr, rows, cols, type, data, step ); }
\r
1966 CvMatrix( int rows, int cols, int type, CvMemStorage* storage, bool alloc_data=true );
\r
1968 CvMatrix( int rows, int cols, int type, void* data, int step=CV_AUTOSTEP )
\r
1969 { matrix = cvCreateMatHeader( rows, cols, type );
\r
1970 cvSetData( matrix, data, step ); }
\r
1972 CvMatrix( CvMat* m )
\r
1975 CvMatrix( const CvMatrix& m )
\r
1977 matrix = m.matrix;
\r
1981 CvMatrix( const char* filename, const char* matname=0, int color=-1 ) : matrix(0)
\r
1982 { load( filename, matname, color ); }
\r
1984 CvMatrix( CvFileStorage* fs, const char* mapname, const char* matname ) : matrix(0)
\r
1985 { read( fs, mapname, matname ); }
\r
1987 CvMatrix( CvFileStorage* fs, const char* seqname, int idx ) : matrix(0)
\r
1988 { read( fs, seqname, idx ); }
\r
1995 CvMatrix clone() { return CvMatrix(matrix ? cvCloneMat(matrix) : 0); }
\r
1997 void set( CvMat* m, bool add_ref )
\r
2005 void create( int rows, int cols, int type )
\r
2007 if( !matrix || !matrix->refcount ||
\r
2008 matrix->rows != rows || matrix->cols != cols ||
\r
2009 CV_MAT_TYPE(matrix->type) != type )
\r
2010 set( cvCreateMat( rows, cols, type ), false );
\r
2013 void addref() const
\r
2017 if( matrix->hdr_refcount )
\r
2018 ++matrix->hdr_refcount;
\r
2019 else if( matrix->refcount )
\r
2020 ++*matrix->refcount;
\r
2028 if( matrix->hdr_refcount )
\r
2030 if( --matrix->hdr_refcount == 0 )
\r
2031 cvReleaseMat( &matrix );
\r
2033 else if( matrix->refcount )
\r
2035 if( --*matrix->refcount == 0 )
\r
2036 cvFree( &matrix->refcount );
\r
2047 bool load( const char* filename, const char* matname=0, int color=-1 );
\r
2048 bool read( CvFileStorage* fs, const char* mapname, const char* matname );
\r
2049 bool read( CvFileStorage* fs, const char* seqname, int idx );
\r
2050 void save( const char* filename, const char* matname, const int* params=0 );
\r
2051 void write( CvFileStorage* fs, const char* matname );
\r
2053 void show( const char* window_name );
\r
2055 bool is_valid() { return matrix != 0; }
\r
2057 int rows() const { return matrix ? matrix->rows : 0; }
\r
2058 int cols() const { return matrix ? matrix->cols : 0; }
\r
2060 CvSize size() const
\r
2062 return !matrix ? cvSize(0,0) : cvSize(matrix->rows,matrix->cols);
\r
2065 int type() const { return matrix ? CV_MAT_TYPE(matrix->type) : 0; }
\r
2066 int depth() const { return matrix ? CV_MAT_DEPTH(matrix->type) : 0; }
\r
2067 int channels() const { return matrix ? CV_MAT_CN(matrix->type) : 0; }
\r
2068 int pix_size() const { return matrix ? CV_ELEM_SIZE(matrix->type) : 0; }
\r
2070 uchar* data() { return matrix ? matrix->data.ptr : 0; }
\r
2071 const uchar* data() const { return matrix ? matrix->data.ptr : 0; }
\r
2072 int step() const { return matrix ? matrix->step : 0; }
\r
2074 void set_data( void* data, int step=CV_AUTOSTEP )
\r
2075 { cvSetData( matrix, data, step ); }
\r
2077 uchar* row(int i) { return !matrix ? 0 : matrix->data.ptr + i*matrix->step; }
\r
2078 const uchar* row(int i) const
\r
2079 { return !matrix ? 0 : matrix->data.ptr + i*matrix->step; }
\r
2081 operator const CvMat* () const { return matrix; }
\r
2082 operator CvMat* () { return matrix; }
\r
2084 CvMatrix& operator = (const CvMatrix& _m)
\r
2088 matrix = _m.matrix;
\r
2097 // classes for automatic module/RTTI data registration/unregistration
\r
2098 struct CV_EXPORTS CvModule
\r
2100 CvModule( CvModuleInfo* _info );
\r
2102 CvModuleInfo* info;
\r
2104 static CvModuleInfo* first;
\r
2105 static CvModuleInfo* last;
\r
2108 struct CV_EXPORTS CvType
\r
2110 CvType( const char* type_name,
\r
2111 CvIsInstanceFunc is_instance, CvReleaseFunc release=0,
\r
2112 CvReadFunc read=0, CvWriteFunc write=0, CvCloneFunc clone=0 );
\r
2116 static CvTypeInfo* first;
\r
2117 static CvTypeInfo* last;
\r
2122 #ifndef SKIP_INCLUDES // for now only expose old interface to swig
\r
2123 #include "cxcore.hpp"
\r
2124 #endif // SKIP_INCLUDES
\r
2126 #endif /*_CXCORE_H_*/
\r