--- /dev/null
+/*M///////////////////////////////////////////////////////////////////////////////////////\r
+//\r
+// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.\r
+//\r
+// By downloading, copying, installing or using the software you agree to this license.\r
+// If you do not agree to this license, do not download, install,\r
+// copy or use the software.\r
+//\r
+//\r
+// License Agreement\r
+// For Open Source Computer Vision Library\r
+//\r
+// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.\r
+// Copyright (C) 2009, Willow Garage Inc., all rights reserved.\r
+// Third party copyrights are property of their respective owners.\r
+//\r
+// Redistribution and use in source and binary forms, with or without modification,\r
+// are permitted provided that the following conditions are met:\r
+//\r
+// * Redistribution's of source code must retain the above copyright notice,\r
+// this list of conditions and the following disclaimer.\r
+//\r
+// * Redistribution's in binary form must reproduce the above copyright notice,\r
+// this list of conditions and the following disclaimer in the documentation\r
+// and/or other materials provided with the distribution.\r
+//\r
+// * The name of the copyright holders may not be used to endorse or promote products\r
+// derived from this software without specific prior written permission.\r
+//\r
+// This software is provided by the copyright holders and contributors "as is" and\r
+// any express or implied warranties, including, but not limited to, the implied\r
+// warranties of merchantability and fitness for a particular purpose are disclaimed.\r
+// In no event shall the Intel Corporation or contributors be liable for any direct,\r
+// indirect, incidental, special, exemplary, or consequential damages\r
+// (including, but not limited to, procurement of substitute goods or services;\r
+// loss of use, data, or profits; or business interruption) however caused\r
+// and on any theory of liability, whether in contract, strict liability,\r
+// or tort (including negligence or otherwise) arising in any way out of\r
+// the use of this software, even if advised of the possibility of such damage.\r
+//\r
+//M*/\r
+\r
+\r
+#ifndef _CXCORE_H_\r
+#define _CXCORE_H_\r
+\r
+#ifdef __IPL_H__\r
+#define HAVE_IPL\r
+#endif\r
+\r
+#ifndef SKIP_INCLUDES\r
+ #if defined HAVE_IPL && !defined __IPL_H__\r
+ #ifndef _INC_WINDOWS\r
+ #define CV_PRETEND_WINDOWS\r
+ #define _INC_WINDOWS\r
+ typedef struct tagBITMAPINFOHEADER BITMAPINFOHEADER;\r
+ typedef int BOOL;\r
+ #endif\r
+ #if defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64\r
+ #include "ipl.h"\r
+ #else\r
+ #include "ipl/ipl.h"\r
+ #endif\r
+ #ifdef CV_PRETEND_WINDOWS\r
+ #undef _INC_WINDOWS\r
+ #endif\r
+ #endif\r
+#endif // SKIP_INCLUDES\r
+\r
+#include "cxtypes.h"\r
+#include "cxerror.h"\r
+#include "cvver.h"\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/****************************************************************************************\\r
+* Array allocation, deallocation, initialization and access to elements *\r
+\****************************************************************************************/\r
+\r
+/* <malloc> wrapper.\r
+ If there is no enough memory, the function\r
+ (as well as other OpenCV functions that call cvAlloc)\r
+ raises an error. */\r
+CVAPI(void*) cvAlloc( size_t size );\r
+\r
+/* <free> wrapper.\r
+ Here and further all the memory releasing functions\r
+ (that all call cvFree) take double pointer in order to\r
+ to clear pointer to the data after releasing it.\r
+ Passing pointer to NULL pointer is Ok: nothing happens in this case\r
+*/\r
+CVAPI(void) cvFree_( void* ptr );\r
+#define cvFree(ptr) (cvFree_(*(ptr)), *(ptr)=0)\r
+\r
+/* Allocates and initializes IplImage header */\r
+CVAPI(IplImage*) cvCreateImageHeader( CvSize size, int depth, int channels );\r
+\r
+/* Inializes IplImage header */\r
+CVAPI(IplImage*) cvInitImageHeader( IplImage* image, CvSize size, int depth,\r
+ int channels, int origin CV_DEFAULT(0),\r
+ int align CV_DEFAULT(4));\r
+\r
+/* Creates IPL image (header and data) */\r
+CVAPI(IplImage*) cvCreateImage( CvSize size, int depth, int channels );\r
+\r
+/* Releases (i.e. deallocates) IPL image header */\r
+CVAPI(void) cvReleaseImageHeader( IplImage** image );\r
+\r
+/* Releases IPL image header and data */\r
+CVAPI(void) cvReleaseImage( IplImage** image );\r
+\r
+/* Creates a copy of IPL image (widthStep may differ) */\r
+CVAPI(IplImage*) cvCloneImage( const IplImage* image );\r
+\r
+/* Sets a Channel Of Interest (only a few functions support COI) -\r
+ use cvCopy to extract the selected channel and/or put it back */\r
+CVAPI(void) cvSetImageCOI( IplImage* image, int coi );\r
+\r
+/* Retrieves image Channel Of Interest */\r
+CVAPI(int) cvGetImageCOI( const IplImage* image );\r
+\r
+/* Sets image ROI (region of interest) (COI is not changed) */\r
+CVAPI(void) cvSetImageROI( IplImage* image, CvRect rect );\r
+\r
+/* Resets image ROI and COI */\r
+CVAPI(void) cvResetImageROI( IplImage* image );\r
+\r
+/* Retrieves image ROI */\r
+CVAPI(CvRect) cvGetImageROI( const IplImage* image );\r
+\r
+/* Allocates and initalizes CvMat header */\r
+CVAPI(CvMat*) cvCreateMatHeader( int rows, int cols, int type );\r
+\r
+#define CV_AUTOSTEP 0x7fffffff\r
+\r
+/* Initializes CvMat header */\r
+CVAPI(CvMat*) cvInitMatHeader( CvMat* mat, int rows, int cols,\r
+ int type, void* data CV_DEFAULT(NULL),\r
+ int step CV_DEFAULT(CV_AUTOSTEP) );\r
+\r
+/* Allocates and initializes CvMat header and allocates data */\r
+CVAPI(CvMat*) cvCreateMat( int rows, int cols, int type );\r
+\r
+/* Releases CvMat header and deallocates matrix data\r
+ (reference counting is used for data) */\r
+CVAPI(void) cvReleaseMat( CvMat** mat );\r
+\r
+/* Decrements CvMat data reference counter and deallocates the data if\r
+ it reaches 0 */\r
+CV_INLINE void cvDecRefData( CvArr* arr )\r
+{\r
+ if( CV_IS_MAT( arr ))\r
+ {\r
+ CvMat* mat = (CvMat*)arr;\r
+ mat->data.ptr = NULL;\r
+ if( mat->refcount != NULL && --*mat->refcount == 0 )\r
+ cvFree( &mat->refcount );\r
+ mat->refcount = NULL;\r
+ }\r
+ else if( CV_IS_MATND( arr ))\r
+ {\r
+ CvMatND* mat = (CvMatND*)arr;\r
+ mat->data.ptr = NULL;\r
+ if( mat->refcount != NULL && --*mat->refcount == 0 )\r
+ cvFree( &mat->refcount );\r
+ mat->refcount = NULL;\r
+ }\r
+}\r
+\r
+/* Increments CvMat data reference counter */\r
+CV_INLINE int cvIncRefData( CvArr* arr )\r
+{\r
+ int refcount = 0;\r
+ if( CV_IS_MAT( arr ))\r
+ {\r
+ CvMat* mat = (CvMat*)arr;\r
+ if( mat->refcount != NULL )\r
+ refcount = ++*mat->refcount;\r
+ }\r
+ else if( CV_IS_MATND( arr ))\r
+ {\r
+ CvMatND* mat = (CvMatND*)arr;\r
+ if( mat->refcount != NULL )\r
+ refcount = ++*mat->refcount;\r
+ }\r
+ return refcount;\r
+}\r
+\r
+\r
+/* Creates an exact copy of the input matrix (except, may be, step value) */\r
+CVAPI(CvMat*) cvCloneMat( const CvMat* mat );\r
+\r
+\r
+/* Makes a new matrix from <rect> subrectangle of input array.\r
+ No data is copied */\r
+CVAPI(CvMat*) cvGetSubRect( const CvArr* arr, CvMat* submat, CvRect rect );\r
+#define cvGetSubArr cvGetSubRect\r
+\r
+/* Selects row span of the input array: arr(start_row:delta_row:end_row,:)\r
+ (end_row is not included into the span). */\r
+CVAPI(CvMat*) cvGetRows( const CvArr* arr, CvMat* submat,\r
+ int start_row, int end_row,\r
+ int delta_row CV_DEFAULT(1));\r
+\r
+CV_INLINE CvMat* cvGetRow( const CvArr* arr, CvMat* submat, int row )\r
+{\r
+ return cvGetRows( arr, submat, row, row + 1, 1 );\r
+}\r
+\r
+\r
+/* Selects column span of the input array: arr(:,start_col:end_col)\r
+ (end_col is not included into the span) */\r
+CVAPI(CvMat*) cvGetCols( const CvArr* arr, CvMat* submat,\r
+ int start_col, int end_col );\r
+\r
+CV_INLINE CvMat* cvGetCol( const CvArr* arr, CvMat* submat, int col )\r
+{\r
+ return cvGetCols( arr, submat, col, col + 1 );\r
+}\r
+\r
+/* Select a diagonal of the input array.\r
+ (diag = 0 means the main diagonal, >0 means a diagonal above the main one,\r
+ <0 - below the main one).\r
+ The diagonal will be represented as a column (nx1 matrix). */\r
+CVAPI(CvMat*) cvGetDiag( const CvArr* arr, CvMat* submat,\r
+ int diag CV_DEFAULT(0));\r
+\r
+/* low-level scalar <-> raw data conversion functions */\r
+CVAPI(void) cvScalarToRawData( const CvScalar* scalar, void* data, int type,\r
+ int extend_to_12 CV_DEFAULT(0) );\r
+\r
+CVAPI(void) cvRawDataToScalar( const void* data, int type, CvScalar* scalar );\r
+\r
+/* Allocates and initializes CvMatND header */\r
+CVAPI(CvMatND*) cvCreateMatNDHeader( int dims, const int* sizes, int type );\r
+\r
+/* Allocates and initializes CvMatND header and allocates data */\r
+CVAPI(CvMatND*) cvCreateMatND( int dims, const int* sizes, int type );\r
+\r
+/* Initializes preallocated CvMatND header */\r
+CVAPI(CvMatND*) cvInitMatNDHeader( CvMatND* mat, int dims, const int* sizes,\r
+ int type, void* data CV_DEFAULT(NULL) );\r
+\r
+/* Releases CvMatND */\r
+CV_INLINE void cvReleaseMatND( CvMatND** mat )\r
+{\r
+ cvReleaseMat( (CvMat**)mat );\r
+}\r
+\r
+/* Creates a copy of CvMatND (except, may be, steps) */\r
+CVAPI(CvMatND*) cvCloneMatND( const CvMatND* mat );\r
+\r
+/* Allocates and initializes CvSparseMat header and allocates data */\r
+CVAPI(CvSparseMat*) cvCreateSparseMat( int dims, const int* sizes, int type );\r
+\r
+/* Releases CvSparseMat */\r
+CVAPI(void) cvReleaseSparseMat( CvSparseMat** mat );\r
+\r
+/* Creates a copy of CvSparseMat (except, may be, zero items) */\r
+CVAPI(CvSparseMat*) cvCloneSparseMat( const CvSparseMat* mat );\r
+\r
+/* Initializes sparse array iterator\r
+ (returns the first node or NULL if the array is empty) */\r
+CVAPI(CvSparseNode*) cvInitSparseMatIterator( const CvSparseMat* mat,\r
+ CvSparseMatIterator* mat_iterator );\r
+\r
+// returns next sparse array node (or NULL if there is no more nodes)\r
+CV_INLINE CvSparseNode* cvGetNextSparseNode( CvSparseMatIterator* mat_iterator )\r
+{\r
+ if( mat_iterator->node->next )\r
+ return mat_iterator->node = mat_iterator->node->next;\r
+ else\r
+ {\r
+ int idx;\r
+ for( idx = ++mat_iterator->curidx; idx < mat_iterator->mat->hashsize; idx++ )\r
+ {\r
+ CvSparseNode* node = (CvSparseNode*)mat_iterator->mat->hashtable[idx];\r
+ if( node )\r
+ {\r
+ mat_iterator->curidx = idx;\r
+ return mat_iterator->node = node;\r
+ }\r
+ }\r
+ return NULL;\r
+ }\r
+}\r
+\r
+/**************** matrix iterator: used for n-ary operations on dense arrays *********/\r
+\r
+#define CV_MAX_ARR 10\r
+\r
+typedef struct CvNArrayIterator\r
+{\r
+ int count; /* number of arrays */\r
+ int dims; /* number of dimensions to iterate */\r
+ CvSize size; /* maximal common linear size: { width = size, height = 1 } */\r
+ uchar* ptr[CV_MAX_ARR]; /* pointers to the array slices */\r
+ int stack[CV_MAX_DIM]; /* for internal use */\r
+ CvMatND* hdr[CV_MAX_ARR]; /* pointers to the headers of the\r
+ matrices that are processed */\r
+}\r
+CvNArrayIterator;\r
+\r
+#define CV_NO_DEPTH_CHECK 1\r
+#define CV_NO_CN_CHECK 2\r
+#define CV_NO_SIZE_CHECK 4\r
+\r
+/* initializes iterator that traverses through several arrays simulteneously\r
+ (the function together with cvNextArraySlice is used for\r
+ N-ari element-wise operations) */\r
+CVAPI(int) cvInitNArrayIterator( int count, CvArr** arrs,\r
+ const CvArr* mask, CvMatND* stubs,\r
+ CvNArrayIterator* array_iterator,\r
+ int flags CV_DEFAULT(0) );\r
+\r
+/* returns zero value if iteration is finished, non-zero (slice length) otherwise */\r
+CVAPI(int) cvNextNArraySlice( CvNArrayIterator* array_iterator );\r
+\r
+\r
+/* Returns type of array elements:\r
+ CV_8UC1 ... CV_64FC4 ... */\r
+CVAPI(int) cvGetElemType( const CvArr* arr );\r
+\r
+/* Retrieves number of an array dimensions and\r
+ optionally sizes of the dimensions */\r
+CVAPI(int) cvGetDims( const CvArr* arr, int* sizes CV_DEFAULT(NULL) );\r
+\r
+\r
+/* Retrieves size of a particular array dimension.\r
+ For 2d arrays cvGetDimSize(arr,0) returns number of rows (image height)\r
+ and cvGetDimSize(arr,1) returns number of columns (image width) */\r
+CVAPI(int) cvGetDimSize( const CvArr* arr, int index );\r
+\r
+\r
+/* ptr = &arr(idx0,idx1,...). All indexes are zero-based,\r
+ the major dimensions go first (e.g. (y,x) for 2D, (z,y,x) for 3D */\r
+CVAPI(uchar*) cvPtr1D( const CvArr* arr, int idx0, int* type CV_DEFAULT(NULL));\r
+CVAPI(uchar*) cvPtr2D( const CvArr* arr, int idx0, int idx1, int* type CV_DEFAULT(NULL) );\r
+CVAPI(uchar*) cvPtr3D( const CvArr* arr, int idx0, int idx1, int idx2,\r
+ int* type CV_DEFAULT(NULL));\r
+\r
+/* For CvMat or IplImage number of indices should be 2\r
+ (row index (y) goes first, column index (x) goes next).\r
+ For CvMatND or CvSparseMat number of infices should match number of <dims> and\r
+ indices order should match the array dimension order. */\r
+CVAPI(uchar*) cvPtrND( const CvArr* arr, const int* idx, int* type CV_DEFAULT(NULL),\r
+ int create_node CV_DEFAULT(1),\r
+ unsigned* precalc_hashval CV_DEFAULT(NULL));\r
+\r
+/* value = arr(idx0,idx1,...) */\r
+CVAPI(CvScalar) cvGet1D( const CvArr* arr, int idx0 );\r
+CVAPI(CvScalar) cvGet2D( const CvArr* arr, int idx0, int idx1 );\r
+CVAPI(CvScalar) cvGet3D( const CvArr* arr, int idx0, int idx1, int idx2 );\r
+CVAPI(CvScalar) cvGetND( const CvArr* arr, const int* idx );\r
+\r
+/* for 1-channel arrays */\r
+CVAPI(double) cvGetReal1D( const CvArr* arr, int idx0 );\r
+CVAPI(double) cvGetReal2D( const CvArr* arr, int idx0, int idx1 );\r
+CVAPI(double) cvGetReal3D( const CvArr* arr, int idx0, int idx1, int idx2 );\r
+CVAPI(double) cvGetRealND( const CvArr* arr, const int* idx );\r
+\r
+/* arr(idx0,idx1,...) = value */\r
+CVAPI(void) cvSet1D( CvArr* arr, int idx0, CvScalar value );\r
+CVAPI(void) cvSet2D( CvArr* arr, int idx0, int idx1, CvScalar value );\r
+CVAPI(void) cvSet3D( CvArr* arr, int idx0, int idx1, int idx2, CvScalar value );\r
+CVAPI(void) cvSetND( CvArr* arr, const int* idx, CvScalar value );\r
+\r
+/* for 1-channel arrays */\r
+CVAPI(void) cvSetReal1D( CvArr* arr, int idx0, double value );\r
+CVAPI(void) cvSetReal2D( CvArr* arr, int idx0, int idx1, double value );\r
+CVAPI(void) cvSetReal3D( CvArr* arr, int idx0,\r
+ int idx1, int idx2, double value );\r
+CVAPI(void) cvSetRealND( CvArr* arr, const int* idx, double value );\r
+\r
+/* clears element of ND dense array,\r
+ in case of sparse arrays it deletes the specified node */\r
+CVAPI(void) cvClearND( CvArr* arr, const int* idx );\r
+\r
+/* Converts CvArr (IplImage or CvMat,...) to CvMat.\r
+ If the last parameter is non-zero, function can\r
+ convert multi(>2)-dimensional array to CvMat as long as\r
+ the last array's dimension is continous. The resultant\r
+ matrix will be have appropriate (a huge) number of rows */\r
+CVAPI(CvMat*) cvGetMat( const CvArr* arr, CvMat* header,\r
+ int* coi CV_DEFAULT(NULL),\r
+ int allowND CV_DEFAULT(0));\r
+\r
+/* Converts CvArr (IplImage or CvMat) to IplImage */\r
+CVAPI(IplImage*) cvGetImage( const CvArr* arr, IplImage* image_header );\r
+\r
+\r
+/* Changes a shape of multi-dimensional array.\r
+ new_cn == 0 means that number of channels remains unchanged.\r
+ new_dims == 0 means that number and sizes of dimensions remain the same\r
+ (unless they need to be changed to set the new number of channels)\r
+ if new_dims == 1, there is no need to specify new dimension sizes\r
+ The resultant configuration should be achievable w/o data copying.\r
+ If the resultant array is sparse, CvSparseMat header should be passed\r
+ to the function else if the result is 1 or 2 dimensional,\r
+ CvMat header should be passed to the function\r
+ else CvMatND header should be passed */\r
+CVAPI(CvArr*) cvReshapeMatND( const CvArr* arr,\r
+ int sizeof_header, CvArr* header,\r
+ int new_cn, int new_dims, int* new_sizes );\r
+\r
+#define cvReshapeND( arr, header, new_cn, new_dims, new_sizes ) \\r
+ cvReshapeMatND( (arr), sizeof(*(header)), (header), \\r
+ (new_cn), (new_dims), (new_sizes))\r
+\r
+CVAPI(CvMat*) cvReshape( const CvArr* arr, CvMat* header,\r
+ int new_cn, int new_rows CV_DEFAULT(0) );\r
+\r
+/* Repeats source 2d array several times in both horizontal and\r
+ vertical direction to fill destination array */\r
+CVAPI(void) cvRepeat( const CvArr* src, CvArr* dst );\r
+\r
+/* Allocates array data */\r
+CVAPI(void) cvCreateData( CvArr* arr );\r
+\r
+/* Releases array data */\r
+CVAPI(void) cvReleaseData( CvArr* arr );\r
+\r
+/* Attaches user data to the array header. The step is reffered to\r
+ the pre-last dimension. That is, all the planes of the array\r
+ must be joint (w/o gaps) */\r
+CVAPI(void) cvSetData( CvArr* arr, void* data, int step );\r
+\r
+/* Retrieves raw data of CvMat, IplImage or CvMatND.\r
+ In the latter case the function raises an error if\r
+ the array can not be represented as a matrix */\r
+CVAPI(void) cvGetRawData( const CvArr* arr, uchar** data,\r
+ int* step CV_DEFAULT(NULL),\r
+ CvSize* roi_size CV_DEFAULT(NULL));\r
+\r
+/* Returns width and height of array in elements */\r
+CVAPI(CvSize) cvGetSize( const CvArr* arr );\r
+\r
+/* Copies source array to destination array */\r
+CVAPI(void) cvCopy( const CvArr* src, CvArr* dst,\r
+ const CvArr* mask CV_DEFAULT(NULL) );\r
+\r
+/* Sets all or "masked" elements of input array\r
+ to the same value*/\r
+CVAPI(void) cvSet( CvArr* arr, CvScalar value,\r
+ const CvArr* mask CV_DEFAULT(NULL) );\r
+\r
+/* Clears all the array elements (sets them to 0) */\r
+CVAPI(void) cvSetZero( CvArr* arr );\r
+#define cvZero cvSetZero\r
+\r
+\r
+/* Splits a multi-channel array into the set of single-channel arrays or\r
+ extracts particular [color] plane */\r
+CVAPI(void) cvSplit( const CvArr* src, CvArr* dst0, CvArr* dst1,\r
+ CvArr* dst2, CvArr* dst3 );\r
+\r
+/* Merges a set of single-channel arrays into the single multi-channel array\r
+ or inserts one particular [color] plane to the array */\r
+CVAPI(void) cvMerge( const CvArr* src0, const CvArr* src1,\r
+ const CvArr* src2, const CvArr* src3,\r
+ CvArr* dst );\r
+\r
+/* Copies several channels from input arrays to\r
+ certain channels of output arrays */\r
+CVAPI(void) cvMixChannels( const CvArr** src, int src_count,\r
+ CvArr** dst, int dst_count,\r
+ const int* from_to, int pair_count );\r
+\r
+/* Performs linear transformation on every source array element:\r
+ dst(x,y,c) = scale*src(x,y,c)+shift.\r
+ Arbitrary combination of input and output array depths are allowed\r
+ (number of channels must be the same), thus the function can be used\r
+ for type conversion */\r
+CVAPI(void) cvConvertScale( const CvArr* src, CvArr* dst,\r
+ double scale CV_DEFAULT(1),\r
+ double shift CV_DEFAULT(0) );\r
+#define cvCvtScale cvConvertScale\r
+#define cvScale cvConvertScale\r
+#define cvConvert( src, dst ) cvConvertScale( (src), (dst), 1, 0 )\r
+\r
+\r
+/* Performs linear transformation on every source array element,\r
+ stores absolute value of the result:\r
+ dst(x,y,c) = abs(scale*src(x,y,c)+shift).\r
+ destination array must have 8u type.\r
+ In other cases one may use cvConvertScale + cvAbsDiffS */\r
+CVAPI(void) cvConvertScaleAbs( const CvArr* src, CvArr* dst,\r
+ double scale CV_DEFAULT(1),\r
+ double shift CV_DEFAULT(0) );\r
+#define cvCvtScaleAbs cvConvertScaleAbs\r
+\r
+\r
+/* checks termination criteria validity and\r
+ sets eps to default_eps (if it is not set),\r
+ max_iter to default_max_iters (if it is not set)\r
+*/\r
+CVAPI(CvTermCriteria) cvCheckTermCriteria( CvTermCriteria criteria,\r
+ double default_eps,\r
+ int default_max_iters );\r
+\r
+/****************************************************************************************\\r
+* Arithmetic, logic and comparison operations *\r
+\****************************************************************************************/\r
+\r
+/* dst(mask) = src1(mask) + src2(mask) */\r
+CVAPI(void) cvAdd( const CvArr* src1, const CvArr* src2, CvArr* dst,\r
+ const CvArr* mask CV_DEFAULT(NULL));\r
+\r
+/* dst(mask) = src(mask) + value */\r
+CVAPI(void) cvAddS( const CvArr* src, CvScalar value, CvArr* dst,\r
+ const CvArr* mask CV_DEFAULT(NULL));\r
+\r
+/* dst(mask) = src1(mask) - src2(mask) */\r
+CVAPI(void) cvSub( const CvArr* src1, const CvArr* src2, CvArr* dst,\r
+ const CvArr* mask CV_DEFAULT(NULL));\r
+\r
+/* dst(mask) = src(mask) - value = src(mask) + (-value) */\r
+CV_INLINE void cvSubS( const CvArr* src, CvScalar value, CvArr* dst,\r
+ const CvArr* mask CV_DEFAULT(NULL))\r
+{\r
+ cvAddS( src, cvScalar( -value.val[0], -value.val[1], -value.val[2], -value.val[3]),\r
+ dst, mask );\r
+}\r
+\r
+/* dst(mask) = value - src(mask) */\r
+CVAPI(void) cvSubRS( const CvArr* src, CvScalar value, CvArr* dst,\r
+ const CvArr* mask CV_DEFAULT(NULL));\r
+\r
+/* dst(idx) = src1(idx) * src2(idx) * scale\r
+ (scaled element-wise multiplication of 2 arrays) */\r
+CVAPI(void) cvMul( const CvArr* src1, const CvArr* src2,\r
+ CvArr* dst, double scale CV_DEFAULT(1) );\r
+\r
+/* element-wise division/inversion with scaling:\r
+ dst(idx) = src1(idx) * scale / src2(idx)\r
+ or dst(idx) = scale / src2(idx) if src1 == 0 */\r
+CVAPI(void) cvDiv( const CvArr* src1, const CvArr* src2,\r
+ CvArr* dst, double scale CV_DEFAULT(1));\r
+\r
+/* dst = src1 * scale + src2 */\r
+CVAPI(void) cvScaleAdd( const CvArr* src1, CvScalar scale,\r
+ const CvArr* src2, CvArr* dst );\r
+#define cvAXPY( A, real_scalar, B, C ) cvScaleAdd(A, cvRealScalar(real_scalar), B, C)\r
+\r
+/* dst = src1 * alpha + src2 * beta + gamma */\r
+CVAPI(void) cvAddWeighted( const CvArr* src1, double alpha,\r
+ const CvArr* src2, double beta,\r
+ double gamma, CvArr* dst );\r
+\r
+/* result = sum_i(src1(i) * src2(i)) (results for all channels are accumulated together) */\r
+CVAPI(double) cvDotProduct( const CvArr* src1, const CvArr* src2 );\r
+\r
+/* dst(idx) = src1(idx) & src2(idx) */\r
+CVAPI(void) cvAnd( const CvArr* src1, const CvArr* src2,\r
+ CvArr* dst, const CvArr* mask CV_DEFAULT(NULL));\r
+\r
+/* dst(idx) = src(idx) & value */\r
+CVAPI(void) cvAndS( const CvArr* src, CvScalar value,\r
+ CvArr* dst, const CvArr* mask CV_DEFAULT(NULL));\r
+\r
+/* dst(idx) = src1(idx) | src2(idx) */\r
+CVAPI(void) cvOr( const CvArr* src1, const CvArr* src2,\r
+ CvArr* dst, const CvArr* mask CV_DEFAULT(NULL));\r
+\r
+/* dst(idx) = src(idx) | value */\r
+CVAPI(void) cvOrS( const CvArr* src, CvScalar value,\r
+ CvArr* dst, const CvArr* mask CV_DEFAULT(NULL));\r
+\r
+/* dst(idx) = src1(idx) ^ src2(idx) */\r
+CVAPI(void) cvXor( const CvArr* src1, const CvArr* src2,\r
+ CvArr* dst, const CvArr* mask CV_DEFAULT(NULL));\r
+\r
+/* dst(idx) = src(idx) ^ value */\r
+CVAPI(void) cvXorS( const CvArr* src, CvScalar value,\r
+ CvArr* dst, const CvArr* mask CV_DEFAULT(NULL));\r
+\r
+/* dst(idx) = ~src(idx) */\r
+CVAPI(void) cvNot( const CvArr* src, CvArr* dst );\r
+\r
+/* dst(idx) = lower(idx) <= src(idx) < upper(idx) */\r
+CVAPI(void) cvInRange( const CvArr* src, const CvArr* lower,\r
+ const CvArr* upper, CvArr* dst );\r
+\r
+/* dst(idx) = lower <= src(idx) < upper */\r
+CVAPI(void) cvInRangeS( const CvArr* src, CvScalar lower,\r
+ CvScalar upper, CvArr* dst );\r
+\r
+#define CV_CMP_EQ 0\r
+#define CV_CMP_GT 1\r
+#define CV_CMP_GE 2\r
+#define CV_CMP_LT 3\r
+#define CV_CMP_LE 4\r
+#define CV_CMP_NE 5\r
+\r
+/* The comparison operation support single-channel arrays only.\r
+ Destination image should be 8uC1 or 8sC1 */\r
+\r
+/* dst(idx) = src1(idx) _cmp_op_ src2(idx) */\r
+CVAPI(void) cvCmp( const CvArr* src1, const CvArr* src2, CvArr* dst, int cmp_op );\r
+\r
+/* dst(idx) = src1(idx) _cmp_op_ value */\r
+CVAPI(void) cvCmpS( const CvArr* src, double value, CvArr* dst, int cmp_op );\r
+\r
+/* dst(idx) = min(src1(idx),src2(idx)) */\r
+CVAPI(void) cvMin( const CvArr* src1, const CvArr* src2, CvArr* dst );\r
+\r
+/* dst(idx) = max(src1(idx),src2(idx)) */\r
+CVAPI(void) cvMax( const CvArr* src1, const CvArr* src2, CvArr* dst );\r
+\r
+/* dst(idx) = min(src(idx),value) */\r
+CVAPI(void) cvMinS( const CvArr* src, double value, CvArr* dst );\r
+\r
+/* dst(idx) = max(src(idx),value) */\r
+CVAPI(void) cvMaxS( const CvArr* src, double value, CvArr* dst );\r
+\r
+/* dst(x,y,c) = abs(src1(x,y,c) - src2(x,y,c)) */\r
+CVAPI(void) cvAbsDiff( const CvArr* src1, const CvArr* src2, CvArr* dst );\r
+\r
+/* dst(x,y,c) = abs(src(x,y,c) - value(c)) */\r
+CVAPI(void) cvAbsDiffS( const CvArr* src, CvArr* dst, CvScalar value );\r
+#define cvAbs( src, dst ) cvAbsDiffS( (src), (dst), cvScalarAll(0))\r
+\r
+/****************************************************************************************\\r
+* Math operations *\r
+\****************************************************************************************/\r
+\r
+/* Does cartesian->polar coordinates conversion.\r
+ Either of output components (magnitude or angle) is optional */\r
+CVAPI(void) cvCartToPolar( const CvArr* x, const CvArr* y,\r
+ CvArr* magnitude, CvArr* angle CV_DEFAULT(NULL),\r
+ int angle_in_degrees CV_DEFAULT(0));\r
+\r
+/* Does polar->cartesian coordinates conversion.\r
+ Either of output components (magnitude or angle) is optional.\r
+ If magnitude is missing it is assumed to be all 1's */\r
+CVAPI(void) cvPolarToCart( const CvArr* magnitude, const CvArr* angle,\r
+ CvArr* x, CvArr* y,\r
+ int angle_in_degrees CV_DEFAULT(0));\r
+\r
+/* Does powering: dst(idx) = src(idx)^power */\r
+CVAPI(void) cvPow( const CvArr* src, CvArr* dst, double power );\r
+\r
+/* Does exponention: dst(idx) = exp(src(idx)).\r
+ Overflow is not handled yet. Underflow is handled.\r
+ Maximal relative error is ~7e-6 for single-precision input */\r
+CVAPI(void) cvExp( const CvArr* src, CvArr* dst );\r
+\r
+/* Calculates natural logarithms: dst(idx) = log(abs(src(idx))).\r
+ Logarithm of 0 gives large negative number(~-700)\r
+ Maximal relative error is ~3e-7 for single-precision output\r
+*/\r
+CVAPI(void) cvLog( const CvArr* src, CvArr* dst );\r
+\r
+/* Fast arctangent calculation */\r
+CVAPI(float) cvFastArctan( float y, float x );\r
+\r
+/* Fast cubic root calculation */\r
+CVAPI(float) cvCbrt( float value );\r
+\r
+/* Checks array values for NaNs, Infs or simply for too large numbers\r
+ (if CV_CHECK_RANGE is set). If CV_CHECK_QUIET is set,\r
+ no runtime errors is raised (function returns zero value in case of "bad" values).\r
+ Otherwise cvError is called */\r
+#define CV_CHECK_RANGE 1\r
+#define CV_CHECK_QUIET 2\r
+CVAPI(int) cvCheckArr( const CvArr* arr, int flags CV_DEFAULT(0),\r
+ double min_val CV_DEFAULT(0), double max_val CV_DEFAULT(0));\r
+#define cvCheckArray cvCheckArr\r
+\r
+#define CV_RAND_UNI 0\r
+#define CV_RAND_NORMAL 1\r
+CVAPI(void) cvRandArr( CvRNG* rng, CvArr* arr, int dist_type,\r
+ CvScalar param1, CvScalar param2 );\r
+\r
+CVAPI(void) cvRandShuffle( CvArr* mat, CvRNG* rng,\r
+ double iter_factor CV_DEFAULT(1.));\r
+\r
+#define CV_SORT_EVERY_ROW 0\r
+#define CV_SORT_EVERY_COLUMN 1\r
+#define CV_SORT_ASCENDING 0\r
+#define CV_SORT_DESCENDING 16\r
+\r
+CVAPI(void) cvSort( const CvArr* src, CvArr* dst CV_DEFAULT(NULL),\r
+ CvArr* idxmat CV_DEFAULT(NULL),\r
+ int flags CV_DEFAULT(0));\r
+\r
+/* Finds real roots of a cubic equation */\r
+CVAPI(int) cvSolveCubic( const CvMat* coeffs, CvMat* roots );\r
+\r
+/* Finds all real and complex roots of a polynomial equation */\r
+CVAPI(void) cvSolvePoly(const CvMat* coeffs, CvMat *roots2,\r
+ int maxiter CV_DEFAULT(20), int fig CV_DEFAULT(100));\r
+\r
+/****************************************************************************************\\r
+* Matrix operations *\r
+\****************************************************************************************/\r
+\r
+/* Calculates cross product of two 3d vectors */\r
+CVAPI(void) cvCrossProduct( const CvArr* src1, const CvArr* src2, CvArr* dst );\r
+\r
+/* Matrix transform: dst = A*B + C, C is optional */\r
+#define cvMatMulAdd( src1, src2, src3, dst ) cvGEMM( (src1), (src2), 1., (src3), 1., (dst), 0 )\r
+#define cvMatMul( src1, src2, dst ) cvMatMulAdd( (src1), (src2), NULL, (dst))\r
+\r
+#define CV_GEMM_A_T 1\r
+#define CV_GEMM_B_T 2\r
+#define CV_GEMM_C_T 4\r
+/* Extended matrix transform:\r
+ dst = alpha*op(A)*op(B) + beta*op(C), where op(X) is X or X^T */\r
+CVAPI(void) cvGEMM( const CvArr* src1, const CvArr* src2, double alpha,\r
+ const CvArr* src3, double beta, CvArr* dst,\r
+ int tABC CV_DEFAULT(0));\r
+#define cvMatMulAddEx cvGEMM\r
+\r
+/* Transforms each element of source array and stores\r
+ resultant vectors in destination array */\r
+CVAPI(void) cvTransform( const CvArr* src, CvArr* dst,\r
+ const CvMat* transmat,\r
+ const CvMat* shiftvec CV_DEFAULT(NULL));\r
+#define cvMatMulAddS cvTransform\r
+\r
+/* Does perspective transform on every element of input array */\r
+CVAPI(void) cvPerspectiveTransform( const CvArr* src, CvArr* dst,\r
+ const CvMat* mat );\r
+\r
+/* Calculates (A-delta)*(A-delta)^T (order=0) or (A-delta)^T*(A-delta) (order=1) */\r
+CVAPI(void) cvMulTransposed( const CvArr* src, CvArr* dst, int order,\r
+ const CvArr* delta CV_DEFAULT(NULL),\r
+ double scale CV_DEFAULT(1.) );\r
+\r
+/* Tranposes matrix. Square matrices can be transposed in-place */\r
+CVAPI(void) cvTranspose( const CvArr* src, CvArr* dst );\r
+#define cvT cvTranspose\r
+\r
+/* Completes the symmetric matrix from the lower (LtoR=0) or from the upper (LtoR!=0) part */\r
+CVAPI(void) cvCompleteSymm( CvMat* matrix, int LtoR CV_DEFAULT(0) );\r
+\r
+/* Mirror array data around horizontal (flip=0),\r
+ vertical (flip=1) or both(flip=-1) axises:\r
+ cvFlip(src) flips images vertically and sequences horizontally (inplace) */\r
+CVAPI(void) cvFlip( const CvArr* src, CvArr* dst CV_DEFAULT(NULL),\r
+ int flip_mode CV_DEFAULT(0));\r
+#define cvMirror cvFlip\r
+\r
+\r
+#define CV_SVD_MODIFY_A 1\r
+#define CV_SVD_U_T 2\r
+#define CV_SVD_V_T 4\r
+\r
+/* Performs Singular Value Decomposition of a matrix */\r
+CVAPI(void) cvSVD( CvArr* A, CvArr* W, CvArr* U CV_DEFAULT(NULL),\r
+ CvArr* V CV_DEFAULT(NULL), int flags CV_DEFAULT(0));\r
+\r
+/* Performs Singular Value Back Substitution (solves A*X = B):\r
+ flags must be the same as in cvSVD */\r
+CVAPI(void) cvSVBkSb( const CvArr* W, const CvArr* U,\r
+ const CvArr* V, const CvArr* B,\r
+ CvArr* X, int flags );\r
+\r
+#define CV_LU 0\r
+#define CV_SVD 1\r
+#define CV_SVD_SYM 2\r
+#define CV_CHOLESKY 3\r
+#define CV_QR 4\r
+#define CV_NORMAL 16\r
+\r
+/* Inverts matrix */\r
+CVAPI(double) cvInvert( const CvArr* src, CvArr* dst,\r
+ int method CV_DEFAULT(CV_LU));\r
+#define cvInv cvInvert\r
+\r
+/* Solves linear system (src1)*(dst) = (src2)\r
+ (returns 0 if src1 is a singular and CV_LU method is used) */\r
+CVAPI(int) cvSolve( const CvArr* src1, const CvArr* src2, CvArr* dst,\r
+ int method CV_DEFAULT(CV_LU));\r
+\r
+/* Calculates determinant of input matrix */\r
+CVAPI(double) cvDet( const CvArr* mat );\r
+\r
+/* Calculates trace of the matrix (sum of elements on the main diagonal) */\r
+CVAPI(CvScalar) cvTrace( const CvArr* mat );\r
+\r
+/* Finds eigen values and vectors of a symmetric matrix */\r
+CVAPI(void) cvEigenVV( CvArr* mat, CvArr* evects, CvArr* evals,\r
+ double eps CV_DEFAULT(0),\r
+ int lowindex CV_DEFAULT(-1),\r
+ int highindex CV_DEFAULT(-1));\r
+\r
+///* Finds selected eigen values and vectors of a symmetric matrix */\r
+//CVAPI(void) cvSelectedEigenVV( CvArr* mat, CvArr* evects, CvArr* evals,\r
+// int lowindex, int highindex );\r
+\r
+/* Makes an identity matrix (mat_ij = i == j) */\r
+CVAPI(void) cvSetIdentity( CvArr* mat, CvScalar value CV_DEFAULT(cvRealScalar(1)) );\r
+\r
+/* Fills matrix with given range of numbers */\r
+CVAPI(CvArr*) cvRange( CvArr* mat, double start, double end );\r
+\r
+/* Calculates covariation matrix for a set of vectors */\r
+/* transpose([v1-avg, v2-avg,...]) * [v1-avg,v2-avg,...] */\r
+#define CV_COVAR_SCRAMBLED 0\r
+\r
+/* [v1-avg, v2-avg,...] * transpose([v1-avg,v2-avg,...]) */\r
+#define CV_COVAR_NORMAL 1\r
+\r
+/* do not calc average (i.e. mean vector) - use the input vector instead\r
+ (useful for calculating covariance matrix by parts) */\r
+#define CV_COVAR_USE_AVG 2\r
+\r
+/* scale the covariance matrix coefficients by number of the vectors */\r
+#define CV_COVAR_SCALE 4\r
+\r
+/* all the input vectors are stored in a single matrix, as its rows */\r
+#define CV_COVAR_ROWS 8\r
+\r
+/* all the input vectors are stored in a single matrix, as its columns */\r
+#define CV_COVAR_COLS 16\r
+\r
+CVAPI(void) cvCalcCovarMatrix( const CvArr** vects, int count,\r
+ CvArr* cov_mat, CvArr* avg, int flags );\r
+\r
+#define CV_PCA_DATA_AS_ROW 0\r
+#define CV_PCA_DATA_AS_COL 1\r
+#define CV_PCA_USE_AVG 2\r
+CVAPI(void) cvCalcPCA( const CvArr* data, CvArr* mean,\r
+ CvArr* eigenvals, CvArr* eigenvects, int flags );\r
+\r
+CVAPI(void) cvProjectPCA( const CvArr* data, const CvArr* mean,\r
+ const CvArr* eigenvects, CvArr* result );\r
+\r
+CVAPI(void) cvBackProjectPCA( const CvArr* proj, const CvArr* mean,\r
+ const CvArr* eigenvects, CvArr* result );\r
+\r
+/* Calculates Mahalanobis(weighted) distance */\r
+CVAPI(double) cvMahalanobis( const CvArr* vec1, const CvArr* vec2, const CvArr* mat );\r
+#define cvMahalonobis cvMahalanobis\r
+\r
+/****************************************************************************************\\r
+* Array Statistics *\r
+\****************************************************************************************/\r
+\r
+/* Finds sum of array elements */\r
+CVAPI(CvScalar) cvSum( const CvArr* arr );\r
+\r
+/* Calculates number of non-zero pixels */\r
+CVAPI(int) cvCountNonZero( const CvArr* arr );\r
+\r
+/* Calculates mean value of array elements */\r
+CVAPI(CvScalar) cvAvg( const CvArr* arr, const CvArr* mask CV_DEFAULT(NULL) );\r
+\r
+/* Calculates mean and standard deviation of pixel values */\r
+CVAPI(void) cvAvgSdv( const CvArr* arr, CvScalar* mean, CvScalar* std_dev,\r
+ const CvArr* mask CV_DEFAULT(NULL) );\r
+\r
+/* Finds global minimum, maximum and their positions */\r
+CVAPI(void) cvMinMaxLoc( const CvArr* arr, double* min_val, double* max_val,\r
+ CvPoint* min_loc CV_DEFAULT(NULL),\r
+ CvPoint* max_loc CV_DEFAULT(NULL),\r
+ const CvArr* mask CV_DEFAULT(NULL) );\r
+\r
+/* types of array norm */\r
+#define CV_C 1\r
+#define CV_L1 2\r
+#define CV_L2 4\r
+#define CV_NORM_MASK 7\r
+#define CV_RELATIVE 8\r
+#define CV_DIFF 16\r
+#define CV_MINMAX 32\r
+\r
+#define CV_DIFF_C (CV_DIFF | CV_C)\r
+#define CV_DIFF_L1 (CV_DIFF | CV_L1)\r
+#define CV_DIFF_L2 (CV_DIFF | CV_L2)\r
+#define CV_RELATIVE_C (CV_RELATIVE | CV_C)\r
+#define CV_RELATIVE_L1 (CV_RELATIVE | CV_L1)\r
+#define CV_RELATIVE_L2 (CV_RELATIVE | CV_L2)\r
+\r
+/* Finds norm, difference norm or relative difference norm for an array (or two arrays) */\r
+CVAPI(double) cvNorm( const CvArr* arr1, const CvArr* arr2 CV_DEFAULT(NULL),\r
+ int norm_type CV_DEFAULT(CV_L2),\r
+ const CvArr* mask CV_DEFAULT(NULL) );\r
+\r
+CVAPI(void) cvNormalize( const CvArr* src, CvArr* dst,\r
+ double a CV_DEFAULT(1.), double b CV_DEFAULT(0.),\r
+ int norm_type CV_DEFAULT(CV_L2),\r
+ const CvArr* mask CV_DEFAULT(NULL) );\r
+\r
+\r
+#define CV_REDUCE_SUM 0\r
+#define CV_REDUCE_AVG 1\r
+#define CV_REDUCE_MAX 2\r
+#define CV_REDUCE_MIN 3\r
+\r
+CVAPI(void) cvReduce( const CvArr* src, CvArr* dst, int dim CV_DEFAULT(-1),\r
+ int op CV_DEFAULT(CV_REDUCE_SUM) );\r
+\r
+/****************************************************************************************\\r
+* Discrete Linear Transforms and Related Functions *\r
+\****************************************************************************************/\r
+\r
+#define CV_DXT_FORWARD 0\r
+#define CV_DXT_INVERSE 1\r
+#define CV_DXT_SCALE 2 /* divide result by size of array */\r
+#define CV_DXT_INV_SCALE (CV_DXT_INVERSE + CV_DXT_SCALE)\r
+#define CV_DXT_INVERSE_SCALE CV_DXT_INV_SCALE\r
+#define CV_DXT_ROWS 4 /* transform each row individually */\r
+#define CV_DXT_MUL_CONJ 8 /* conjugate the second argument of cvMulSpectrums */\r
+\r
+/* Discrete Fourier Transform:\r
+ complex->complex,\r
+ real->ccs (forward),\r
+ ccs->real (inverse) */\r
+CVAPI(void) cvDFT( const CvArr* src, CvArr* dst, int flags,\r
+ int nonzero_rows CV_DEFAULT(0) );\r
+#define cvFFT cvDFT\r
+\r
+/* Multiply results of DFTs: DFT(X)*DFT(Y) or DFT(X)*conj(DFT(Y)) */\r
+CVAPI(void) cvMulSpectrums( const CvArr* src1, const CvArr* src2,\r
+ CvArr* dst, int flags );\r
+\r
+/* Finds optimal DFT vector size >= size0 */\r
+CVAPI(int) cvGetOptimalDFTSize( int size0 );\r
+\r
+/* Discrete Cosine Transform */\r
+CVAPI(void) cvDCT( const CvArr* src, CvArr* dst, int flags );\r
+\r
+/****************************************************************************************\\r
+* Dynamic data structures *\r
+\****************************************************************************************/\r
+\r
+/* Calculates length of sequence slice (with support of negative indices). */\r
+CVAPI(int) cvSliceLength( CvSlice slice, const CvSeq* seq );\r
+\r
+\r
+/* Creates new memory storage.\r
+ block_size == 0 means that default,\r
+ somewhat optimal size, is used (currently, it is 64K) */\r
+CVAPI(CvMemStorage*) cvCreateMemStorage( int block_size CV_DEFAULT(0));\r
+\r
+\r
+/* Creates a memory storage that will borrow memory blocks from parent storage */\r
+CVAPI(CvMemStorage*) cvCreateChildMemStorage( CvMemStorage* parent );\r
+\r
+\r
+/* Releases memory storage. All the children of a parent must be released before\r
+ the parent. A child storage returns all the blocks to parent when it is released */\r
+CVAPI(void) cvReleaseMemStorage( CvMemStorage** storage );\r
+\r
+\r
+/* Clears memory storage. This is the only way(!!!) (besides cvRestoreMemStoragePos)\r
+ to reuse memory allocated for the storage - cvClearSeq,cvClearSet ...\r
+ do not free any memory.\r
+ A child storage returns all the blocks to the parent when it is cleared */\r
+CVAPI(void) cvClearMemStorage( CvMemStorage* storage );\r
+\r
+/* Remember a storage "free memory" position */\r
+CVAPI(void) cvSaveMemStoragePos( const CvMemStorage* storage, CvMemStoragePos* pos );\r
+\r
+/* Restore a storage "free memory" position */\r
+CVAPI(void) cvRestoreMemStoragePos( CvMemStorage* storage, CvMemStoragePos* pos );\r
+\r
+/* Allocates continuous buffer of the specified size in the storage */\r
+CVAPI(void*) cvMemStorageAlloc( CvMemStorage* storage, size_t size );\r
+\r
+/* Allocates string in memory storage */\r
+CVAPI(CvString) cvMemStorageAllocString( CvMemStorage* storage, const char* ptr,\r
+ int len CV_DEFAULT(-1) );\r
+\r
+/* Creates new empty sequence that will reside in the specified storage */\r
+CVAPI(CvSeq*) cvCreateSeq( int seq_flags, int header_size,\r
+ int elem_size, CvMemStorage* storage );\r
+\r
+/* Changes default size (granularity) of sequence blocks.\r
+ The default size is ~1Kbyte */\r
+CVAPI(void) cvSetSeqBlockSize( CvSeq* seq, int delta_elems );\r
+\r
+\r
+/* Adds new element to the end of sequence. Returns pointer to the element */\r
+CVAPI(schar*) cvSeqPush( CvSeq* seq, const void* element CV_DEFAULT(NULL));\r
+\r
+\r
+/* Adds new element to the beginning of sequence. Returns pointer to it */\r
+CVAPI(schar*) cvSeqPushFront( CvSeq* seq, const void* element CV_DEFAULT(NULL));\r
+\r
+\r
+/* Removes the last element from sequence and optionally saves it */\r
+CVAPI(void) cvSeqPop( CvSeq* seq, void* element CV_DEFAULT(NULL));\r
+\r
+\r
+/* Removes the first element from sequence and optioanally saves it */\r
+CVAPI(void) cvSeqPopFront( CvSeq* seq, void* element CV_DEFAULT(NULL));\r
+\r
+\r
+#define CV_FRONT 1\r
+#define CV_BACK 0\r
+/* Adds several new elements to the end of sequence */\r
+CVAPI(void) cvSeqPushMulti( CvSeq* seq, const void* elements,\r
+ int count, int in_front CV_DEFAULT(0) );\r
+\r
+/* Removes several elements from the end of sequence and optionally saves them */\r
+CVAPI(void) cvSeqPopMulti( CvSeq* seq, void* elements,\r
+ int count, int in_front CV_DEFAULT(0) );\r
+\r
+/* Inserts a new element in the middle of sequence.\r
+ cvSeqInsert(seq,0,elem) == cvSeqPushFront(seq,elem) */\r
+CVAPI(schar*) cvSeqInsert( CvSeq* seq, int before_index,\r
+ const void* element CV_DEFAULT(NULL));\r
+\r
+/* Removes specified sequence element */\r
+CVAPI(void) cvSeqRemove( CvSeq* seq, int index );\r
+\r
+\r
+/* Removes all the elements from the sequence. The freed memory\r
+ can be reused later only by the same sequence unless cvClearMemStorage\r
+ or cvRestoreMemStoragePos is called */\r
+CVAPI(void) cvClearSeq( CvSeq* seq );\r
+\r
+\r
+/* Retrieves pointer to specified sequence element.\r
+ Negative indices are supported and mean counting from the end\r
+ (e.g -1 means the last sequence element) */\r
+CVAPI(schar*) cvGetSeqElem( const CvSeq* seq, int index );\r
+\r
+/* Calculates index of the specified sequence element.\r
+ Returns -1 if element does not belong to the sequence */\r
+CVAPI(int) cvSeqElemIdx( const CvSeq* seq, const void* element,\r
+ CvSeqBlock** block CV_DEFAULT(NULL) );\r
+\r
+/* Initializes sequence writer. The new elements will be added to the end of sequence */\r
+CVAPI(void) cvStartAppendToSeq( CvSeq* seq, CvSeqWriter* writer );\r
+\r
+\r
+/* Combination of cvCreateSeq and cvStartAppendToSeq */\r
+CVAPI(void) cvStartWriteSeq( int seq_flags, int header_size,\r
+ int elem_size, CvMemStorage* storage,\r
+ CvSeqWriter* writer );\r
+\r
+/* Closes sequence writer, updates sequence header and returns pointer\r
+ to the resultant sequence\r
+ (which may be useful if the sequence was created using cvStartWriteSeq))\r
+*/\r
+CVAPI(CvSeq*) cvEndWriteSeq( CvSeqWriter* writer );\r
+\r
+\r
+/* Updates sequence header. May be useful to get access to some of previously\r
+ written elements via cvGetSeqElem or sequence reader */\r
+CVAPI(void) cvFlushSeqWriter( CvSeqWriter* writer );\r
+\r
+\r
+/* Initializes sequence reader.\r
+ The sequence can be read in forward or backward direction */\r
+CVAPI(void) cvStartReadSeq( const CvSeq* seq, CvSeqReader* reader,\r
+ int reverse CV_DEFAULT(0) );\r
+\r
+\r
+/* Returns current sequence reader position (currently observed sequence element) */\r
+CVAPI(int) cvGetSeqReaderPos( CvSeqReader* reader );\r
+\r
+\r
+/* Changes sequence reader position. It may seek to an absolute or\r
+ to relative to the current position */\r
+CVAPI(void) cvSetSeqReaderPos( CvSeqReader* reader, int index,\r
+ int is_relative CV_DEFAULT(0));\r
+\r
+/* Copies sequence content to a continuous piece of memory */\r
+CVAPI(void*) cvCvtSeqToArray( const CvSeq* seq, void* elements,\r
+ CvSlice slice CV_DEFAULT(CV_WHOLE_SEQ) );\r
+\r
+/* Creates sequence header for array.\r
+ After that all the operations on sequences that do not alter the content\r
+ can be applied to the resultant sequence */\r
+CVAPI(CvSeq*) cvMakeSeqHeaderForArray( int seq_type, int header_size,\r
+ int elem_size, void* elements, int total,\r
+ CvSeq* seq, CvSeqBlock* block );\r
+\r
+/* Extracts sequence slice (with or without copying sequence elements) */\r
+CVAPI(CvSeq*) cvSeqSlice( const CvSeq* seq, CvSlice slice,\r
+ CvMemStorage* storage CV_DEFAULT(NULL),\r
+ int copy_data CV_DEFAULT(0));\r
+\r
+CV_INLINE CvSeq* cvCloneSeq( const CvSeq* seq, CvMemStorage* storage CV_DEFAULT(NULL))\r
+{\r
+ return cvSeqSlice( seq, CV_WHOLE_SEQ, storage, 1 );\r
+}\r
+\r
+/* Removes sequence slice */\r
+CVAPI(void) cvSeqRemoveSlice( CvSeq* seq, CvSlice slice );\r
+\r
+/* Inserts a sequence or array into another sequence */\r
+CVAPI(void) cvSeqInsertSlice( CvSeq* seq, int before_index, const CvArr* from_arr );\r
+\r
+/* a < b ? -1 : a > b ? 1 : 0 */\r
+typedef int (CV_CDECL* CvCmpFunc)(const void* a, const void* b, void* userdata );\r
+\r
+/* Sorts sequence in-place given element comparison function */\r
+CVAPI(void) cvSeqSort( CvSeq* seq, CvCmpFunc func, void* userdata CV_DEFAULT(NULL) );\r
+\r
+/* Finds element in a [sorted] sequence */\r
+CVAPI(schar*) cvSeqSearch( CvSeq* seq, const void* elem, CvCmpFunc func,\r
+ int is_sorted, int* elem_idx,\r
+ void* userdata CV_DEFAULT(NULL) );\r
+\r
+/* Reverses order of sequence elements in-place */\r
+CVAPI(void) cvSeqInvert( CvSeq* seq );\r
+\r
+/* Splits sequence into one or more equivalence classes using the specified criteria */\r
+CVAPI(int) cvSeqPartition( const CvSeq* seq, CvMemStorage* storage,\r
+ CvSeq** labels, CvCmpFunc is_equal, void* userdata );\r
+\r
+/************ Internal sequence functions ************/\r
+CVAPI(void) cvChangeSeqBlock( void* reader, int direction );\r
+CVAPI(void) cvCreateSeqBlock( CvSeqWriter* writer );\r
+\r
+\r
+/* Creates a new set */\r
+CVAPI(CvSet*) cvCreateSet( int set_flags, int header_size,\r
+ int elem_size, CvMemStorage* storage );\r
+\r
+/* Adds new element to the set and returns pointer to it */\r
+CVAPI(int) cvSetAdd( CvSet* set_header, CvSetElem* elem CV_DEFAULT(NULL),\r
+ CvSetElem** inserted_elem CV_DEFAULT(NULL) );\r
+\r
+/* Fast variant of cvSetAdd */\r
+CV_INLINE CvSetElem* cvSetNew( CvSet* set_header )\r
+{\r
+ CvSetElem* elem = set_header->free_elems;\r
+ if( elem )\r
+ {\r
+ set_header->free_elems = elem->next_free;\r
+ elem->flags = elem->flags & CV_SET_ELEM_IDX_MASK;\r
+ set_header->active_count++;\r
+ }\r
+ else\r
+ cvSetAdd( set_header, NULL, (CvSetElem**)&elem );\r
+ return elem;\r
+}\r
+\r
+/* Removes set element given its pointer */\r
+CV_INLINE void cvSetRemoveByPtr( CvSet* set_header, void* elem )\r
+{\r
+ CvSetElem* _elem = (CvSetElem*)elem;\r
+ assert( _elem->flags >= 0 /*&& (elem->flags & CV_SET_ELEM_IDX_MASK) < set_header->total*/ );\r
+ _elem->next_free = set_header->free_elems;\r
+ _elem->flags = (_elem->flags & CV_SET_ELEM_IDX_MASK) | CV_SET_ELEM_FREE_FLAG;\r
+ set_header->free_elems = _elem;\r
+ set_header->active_count--;\r
+}\r
+\r
+/* Removes element from the set by its index */\r
+CVAPI(void) cvSetRemove( CvSet* set_header, int index );\r
+\r
+/* Returns a set element by index. If the element doesn't belong to the set,\r
+ NULL is returned */\r
+CV_INLINE CvSetElem* cvGetSetElem( const CvSet* set_header, int index )\r
+{\r
+ CvSetElem* elem = (CvSetElem*)cvGetSeqElem( (CvSeq*)set_header, index );\r
+ return elem && CV_IS_SET_ELEM( elem ) ? elem : 0;\r
+}\r
+\r
+/* Removes all the elements from the set */\r
+CVAPI(void) cvClearSet( CvSet* set_header );\r
+\r
+/* Creates new graph */\r
+CVAPI(CvGraph*) cvCreateGraph( int graph_flags, int header_size,\r
+ int vtx_size, int edge_size,\r
+ CvMemStorage* storage );\r
+\r
+/* Adds new vertex to the graph */\r
+CVAPI(int) cvGraphAddVtx( CvGraph* graph, const CvGraphVtx* vtx CV_DEFAULT(NULL),\r
+ CvGraphVtx** inserted_vtx CV_DEFAULT(NULL) );\r
+\r
+\r
+/* Removes vertex from the graph together with all incident edges */\r
+CVAPI(int) cvGraphRemoveVtx( CvGraph* graph, int index );\r
+CVAPI(int) cvGraphRemoveVtxByPtr( CvGraph* graph, CvGraphVtx* vtx );\r
+\r
+\r
+/* Link two vertices specifed by indices or pointers if they\r
+ are not connected or return pointer to already existing edge\r
+ connecting the vertices.\r
+ Functions return 1 if a new edge was created, 0 otherwise */\r
+CVAPI(int) cvGraphAddEdge( CvGraph* graph,\r
+ int start_idx, int end_idx,\r
+ const CvGraphEdge* edge CV_DEFAULT(NULL),\r
+ CvGraphEdge** inserted_edge CV_DEFAULT(NULL) );\r
+\r
+CVAPI(int) cvGraphAddEdgeByPtr( CvGraph* graph,\r
+ CvGraphVtx* start_vtx, CvGraphVtx* end_vtx,\r
+ const CvGraphEdge* edge CV_DEFAULT(NULL),\r
+ CvGraphEdge** inserted_edge CV_DEFAULT(NULL) );\r
+\r
+/* Remove edge connecting two vertices */\r
+CVAPI(void) cvGraphRemoveEdge( CvGraph* graph, int start_idx, int end_idx );\r
+CVAPI(void) cvGraphRemoveEdgeByPtr( CvGraph* graph, CvGraphVtx* start_vtx,\r
+ CvGraphVtx* end_vtx );\r
+\r
+/* Find edge connecting two vertices */\r
+CVAPI(CvGraphEdge*) cvFindGraphEdge( const CvGraph* graph, int start_idx, int end_idx );\r
+CVAPI(CvGraphEdge*) cvFindGraphEdgeByPtr( const CvGraph* graph,\r
+ const CvGraphVtx* start_vtx,\r
+ const CvGraphVtx* end_vtx );\r
+#define cvGraphFindEdge cvFindGraphEdge\r
+#define cvGraphFindEdgeByPtr cvFindGraphEdgeByPtr\r
+\r
+/* Remove all vertices and edges from the graph */\r
+CVAPI(void) cvClearGraph( CvGraph* graph );\r
+\r
+\r
+/* Count number of edges incident to the vertex */\r
+CVAPI(int) cvGraphVtxDegree( const CvGraph* graph, int vtx_idx );\r
+CVAPI(int) cvGraphVtxDegreeByPtr( const CvGraph* graph, const CvGraphVtx* vtx );\r
+\r
+\r
+/* Retrieves graph vertex by given index */\r
+#define cvGetGraphVtx( graph, idx ) (CvGraphVtx*)cvGetSetElem((CvSet*)(graph), (idx))\r
+\r
+/* Retrieves index of a graph vertex given its pointer */\r
+#define cvGraphVtxIdx( graph, vtx ) ((vtx)->flags & CV_SET_ELEM_IDX_MASK)\r
+\r
+/* Retrieves index of a graph edge given its pointer */\r
+#define cvGraphEdgeIdx( graph, edge ) ((edge)->flags & CV_SET_ELEM_IDX_MASK)\r
+\r
+#define cvGraphGetVtxCount( graph ) ((graph)->active_count)\r
+#define cvGraphGetEdgeCount( graph ) ((graph)->edges->active_count)\r
+\r
+#define CV_GRAPH_VERTEX 1\r
+#define CV_GRAPH_TREE_EDGE 2\r
+#define CV_GRAPH_BACK_EDGE 4\r
+#define CV_GRAPH_FORWARD_EDGE 8\r
+#define CV_GRAPH_CROSS_EDGE 16\r
+#define CV_GRAPH_ANY_EDGE 30\r
+#define CV_GRAPH_NEW_TREE 32\r
+#define CV_GRAPH_BACKTRACKING 64\r
+#define CV_GRAPH_OVER -1\r
+\r
+#define CV_GRAPH_ALL_ITEMS -1\r
+\r
+/* flags for graph vertices and edges */\r
+#define CV_GRAPH_ITEM_VISITED_FLAG (1 << 30)\r
+#define CV_IS_GRAPH_VERTEX_VISITED(vtx) \\r
+ (((CvGraphVtx*)(vtx))->flags & CV_GRAPH_ITEM_VISITED_FLAG)\r
+#define CV_IS_GRAPH_EDGE_VISITED(edge) \\r
+ (((CvGraphEdge*)(edge))->flags & CV_GRAPH_ITEM_VISITED_FLAG)\r
+#define CV_GRAPH_SEARCH_TREE_NODE_FLAG (1 << 29)\r
+#define CV_GRAPH_FORWARD_EDGE_FLAG (1 << 28)\r
+\r
+typedef struct CvGraphScanner\r
+{\r
+ CvGraphVtx* vtx; /* current graph vertex (or current edge origin) */\r
+ CvGraphVtx* dst; /* current graph edge destination vertex */\r
+ CvGraphEdge* edge; /* current edge */\r
+\r
+ CvGraph* graph; /* the graph */\r
+ CvSeq* stack; /* the graph vertex stack */\r
+ int index; /* the lower bound of certainly visited vertices */\r
+ int mask; /* event mask */\r
+}\r
+CvGraphScanner;\r
+\r
+/* Creates new graph scanner. */\r
+CVAPI(CvGraphScanner*) cvCreateGraphScanner( CvGraph* graph,\r
+ CvGraphVtx* vtx CV_DEFAULT(NULL),\r
+ int mask CV_DEFAULT(CV_GRAPH_ALL_ITEMS));\r
+\r
+/* Releases graph scanner. */\r
+CVAPI(void) cvReleaseGraphScanner( CvGraphScanner** scanner );\r
+\r
+/* Get next graph element */\r
+CVAPI(int) cvNextGraphItem( CvGraphScanner* scanner );\r
+\r
+/* Creates a copy of graph */\r
+CVAPI(CvGraph*) cvCloneGraph( const CvGraph* graph, CvMemStorage* storage );\r
+\r
+/****************************************************************************************\\r
+* Drawing *\r
+\****************************************************************************************/\r
+\r
+/****************************************************************************************\\r
+* Drawing functions work with images/matrices of arbitrary type. *\r
+* For color images the channel order is BGR[A] *\r
+* Antialiasing is supported only for 8-bit image now. *\r
+* All the functions include parameter color that means rgb value (that may be *\r
+* constructed with CV_RGB macro) for color images and brightness *\r
+* for grayscale images. *\r
+* If a drawn figure is partially or completely outside of the image, it is clipped.*\r
+\****************************************************************************************/\r
+\r
+#define CV_RGB( r, g, b ) cvScalar( (b), (g), (r), 0 )\r
+#define CV_FILLED -1\r
+\r
+#define CV_AA 16\r
+\r
+/* Draws 4-connected, 8-connected or antialiased line segment connecting two points */\r
+CVAPI(void) cvLine( CvArr* img, CvPoint pt1, CvPoint pt2,\r
+ CvScalar color, int thickness CV_DEFAULT(1),\r
+ int line_type CV_DEFAULT(8), int shift CV_DEFAULT(0) );\r
+\r
+/* Draws a rectangle given two opposite corners of the rectangle (pt1 & pt2),\r
+ if thickness<0 (e.g. thickness == CV_FILLED), the filled box is drawn */\r
+CVAPI(void) cvRectangle( CvArr* img, CvPoint pt1, CvPoint pt2,\r
+ CvScalar color, int thickness CV_DEFAULT(1),\r
+ int line_type CV_DEFAULT(8),\r
+ int shift CV_DEFAULT(0));\r
+\r
+/* Draws a circle with specified center and radius.\r
+ Thickness works in the same way as with cvRectangle */\r
+CVAPI(void) cvCircle( CvArr* img, CvPoint center, int radius,\r
+ CvScalar color, int thickness CV_DEFAULT(1),\r
+ int line_type CV_DEFAULT(8), int shift CV_DEFAULT(0));\r
+\r
+/* Draws ellipse outline, filled ellipse, elliptic arc or filled elliptic sector,\r
+ depending on <thickness>, <start_angle> and <end_angle> parameters. The resultant figure\r
+ is rotated by <angle>. All the angles are in degrees */\r
+CVAPI(void) cvEllipse( CvArr* img, CvPoint center, CvSize axes,\r
+ double angle, double start_angle, double end_angle,\r
+ CvScalar color, int thickness CV_DEFAULT(1),\r
+ int line_type CV_DEFAULT(8), int shift CV_DEFAULT(0));\r
+\r
+CV_INLINE void cvEllipseBox( CvArr* img, CvBox2D box, CvScalar color,\r
+ int thickness CV_DEFAULT(1),\r
+ int line_type CV_DEFAULT(8), int shift CV_DEFAULT(0) )\r
+{\r
+ CvSize axes;\r
+ axes.width = cvRound(box.size.height*0.5);\r
+ axes.height = cvRound(box.size.width*0.5);\r
+\r
+ cvEllipse( img, cvPointFrom32f( box.center ), axes, box.angle,\r
+ 0, 360, color, thickness, line_type, shift );\r
+}\r
+\r
+/* Fills convex or monotonous polygon. */\r
+CVAPI(void) cvFillConvexPoly( CvArr* img, const CvPoint* pts, int npts, CvScalar color,\r
+ int line_type CV_DEFAULT(8), int shift CV_DEFAULT(0));\r
+\r
+/* Fills an area bounded by one or more arbitrary polygons */\r
+CVAPI(void) cvFillPoly( CvArr* img, CvPoint** pts, const int* npts,\r
+ int contours, CvScalar color,\r
+ int line_type CV_DEFAULT(8), int shift CV_DEFAULT(0) );\r
+\r
+/* Draws one or more polygonal curves */\r
+CVAPI(void) cvPolyLine( CvArr* img, CvPoint** pts, const int* npts, int contours,\r
+ int is_closed, CvScalar color, int thickness CV_DEFAULT(1),\r
+ int line_type CV_DEFAULT(8), int shift CV_DEFAULT(0) );\r
+\r
+#define cvDrawRect cvRectangle\r
+#define cvDrawLine cvLine\r
+#define cvDrawCircle cvCircle\r
+#define cvDrawEllipse cvEllipse\r
+#define cvDrawPolyLine cvPolyLine\r
+\r
+/* Clips the line segment connecting *pt1 and *pt2\r
+ by the rectangular window\r
+ (0<=x<img_size.width, 0<=y<img_size.height). */\r
+CVAPI(int) cvClipLine( CvSize img_size, CvPoint* pt1, CvPoint* pt2 );\r
+\r
+/* Initializes line iterator. Initially, line_iterator->ptr will point\r
+ to pt1 (or pt2, see left_to_right description) location in the image.\r
+ Returns the number of pixels on the line between the ending points. */\r
+CVAPI(int) cvInitLineIterator( const CvArr* image, CvPoint pt1, CvPoint pt2,\r
+ CvLineIterator* line_iterator,\r
+ int connectivity CV_DEFAULT(8),\r
+ int left_to_right CV_DEFAULT(0));\r
+\r
+/* Moves iterator to the next line point */\r
+#define CV_NEXT_LINE_POINT( line_iterator ) \\r
+{ \\r
+ int _line_iterator_mask = (line_iterator).err < 0 ? -1 : 0; \\r
+ (line_iterator).err += (line_iterator).minus_delta + \\r
+ ((line_iterator).plus_delta & _line_iterator_mask); \\r
+ (line_iterator).ptr += (line_iterator).minus_step + \\r
+ ((line_iterator).plus_step & _line_iterator_mask); \\r
+}\r
+\r
+\r
+/* basic font types */\r
+#define CV_FONT_HERSHEY_SIMPLEX 0\r
+#define CV_FONT_HERSHEY_PLAIN 1\r
+#define CV_FONT_HERSHEY_DUPLEX 2\r
+#define CV_FONT_HERSHEY_COMPLEX 3\r
+#define CV_FONT_HERSHEY_TRIPLEX 4\r
+#define CV_FONT_HERSHEY_COMPLEX_SMALL 5\r
+#define CV_FONT_HERSHEY_SCRIPT_SIMPLEX 6\r
+#define CV_FONT_HERSHEY_SCRIPT_COMPLEX 7\r
+\r
+/* font flags */\r
+#define CV_FONT_ITALIC 16\r
+\r
+#define CV_FONT_VECTOR0 CV_FONT_HERSHEY_SIMPLEX\r
+\r
+/* Font structure */\r
+typedef struct CvFont\r
+{\r
+ int font_face; /* =CV_FONT_* */\r
+ const int* ascii; /* font data and metrics */\r
+ const int* greek;\r
+ const int* cyrillic;\r
+ float hscale, vscale;\r
+ float shear; /* slope coefficient: 0 - normal, >0 - italic */\r
+ int thickness; /* letters thickness */\r
+ float dx; /* horizontal interval between letters */\r
+ int line_type;\r
+}\r
+CvFont;\r
+\r
+/* Initializes font structure used further in cvPutText */\r
+CVAPI(void) cvInitFont( CvFont* font, int font_face,\r
+ double hscale, double vscale,\r
+ double shear CV_DEFAULT(0),\r
+ int thickness CV_DEFAULT(1),\r
+ int line_type CV_DEFAULT(8));\r
+\r
+CV_INLINE CvFont cvFont( double scale, int thickness CV_DEFAULT(1) )\r
+{\r
+ CvFont font;\r
+ cvInitFont( &font, CV_FONT_HERSHEY_PLAIN, scale, scale, 0, thickness, CV_AA );\r
+ return font;\r
+}\r
+\r
+/* Renders text stroke with specified font and color at specified location.\r
+ CvFont should be initialized with cvInitFont */\r
+CVAPI(void) cvPutText( CvArr* img, const char* text, CvPoint org,\r
+ const CvFont* font, CvScalar color );\r
+\r
+/* Calculates bounding box of text stroke (useful for alignment) */\r
+CVAPI(void) cvGetTextSize( const char* text_string, const CvFont* font,\r
+ CvSize* text_size, int* baseline );\r
+\r
+/* Unpacks color value, if arrtype is CV_8UC?, <color> is treated as\r
+ packed color value, otherwise the first channels (depending on arrtype)\r
+ of destination scalar are set to the same value = <color> */\r
+CVAPI(CvScalar) cvColorToScalar( double packed_color, int arrtype );\r
+\r
+/* Returns the polygon points which make up the given ellipse. The ellipse is define by\r
+ the box of size 'axes' rotated 'angle' around the 'center'. A partial sweep\r
+ of the ellipse arc can be done by spcifying arc_start and arc_end to be something\r
+ other than 0 and 360, respectively. The input array 'pts' must be large enough to\r
+ hold the result. The total number of points stored into 'pts' is returned by this\r
+ function. */\r
+CVAPI(int) cvEllipse2Poly( CvPoint center, CvSize axes,\r
+ int angle, int arc_start, int arc_end, CvPoint * pts, int delta );\r
+\r
+/* Draws contour outlines or filled interiors on the image */\r
+CVAPI(void) cvDrawContours( CvArr *img, CvSeq* contour,\r
+ CvScalar external_color, CvScalar hole_color,\r
+ int max_level, int thickness CV_DEFAULT(1),\r
+ int line_type CV_DEFAULT(8),\r
+ CvPoint offset CV_DEFAULT(cvPoint(0,0)));\r
+\r
+/* Does look-up transformation. Elements of the source array\r
+ (that should be 8uC1 or 8sC1) are used as indexes in lutarr 256-element table */\r
+CVAPI(void) cvLUT( const CvArr* src, CvArr* dst, const CvArr* lut );\r
+\r
+\r
+/******************* Iteration through the sequence tree *****************/\r
+typedef struct CvTreeNodeIterator\r
+{\r
+ const void* node;\r
+ int level;\r
+ int max_level;\r
+}\r
+CvTreeNodeIterator;\r
+\r
+CVAPI(void) cvInitTreeNodeIterator( CvTreeNodeIterator* tree_iterator,\r
+ const void* first, int max_level );\r
+CVAPI(void*) cvNextTreeNode( CvTreeNodeIterator* tree_iterator );\r
+CVAPI(void*) cvPrevTreeNode( CvTreeNodeIterator* tree_iterator );\r
+\r
+/* Inserts sequence into tree with specified "parent" sequence.\r
+ If parent is equal to frame (e.g. the most external contour),\r
+ then added contour will have null pointer to parent. */\r
+CVAPI(void) cvInsertNodeIntoTree( void* node, void* parent, void* frame );\r
+\r
+/* Removes contour from tree (together with the contour children). */\r
+CVAPI(void) cvRemoveNodeFromTree( void* node, void* frame );\r
+\r
+/* Gathers pointers to all the sequences,\r
+ accessible from the <first>, to the single sequence */\r
+CVAPI(CvSeq*) cvTreeToNodeSeq( const void* first, int header_size,\r
+ CvMemStorage* storage );\r
+\r
+/* The function implements the K-means algorithm for clustering an array of sample\r
+ vectors in a specified number of classes */\r
+#define CV_KMEANS_USE_INITIAL_LABELS 1\r
+CVAPI(int) cvKMeans2( const CvArr* samples, int cluster_count, CvArr* labels,\r
+ CvTermCriteria termcrit, int attempts CV_DEFAULT(1),\r
+ CvRNG* rng CV_DEFAULT(0), int flags CV_DEFAULT(0),\r
+ CvArr* _centers CV_DEFAULT(0), double* compactness CV_DEFAULT(0) );\r
+\r
+/****************************************************************************************\\r
+* System functions *\r
+\****************************************************************************************/\r
+\r
+/* Add the function pointers table with associated information to the IPP primitives list */\r
+CVAPI(int) cvRegisterModule( const CvModuleInfo* module_info );\r
+\r
+/* Loads optimized functions from IPP, MKL etc. or switches back to pure C code */\r
+CVAPI(int) cvUseOptimized( int on_off );\r
+\r
+/* Retrieves information about the registered modules and loaded optimized plugins */\r
+CVAPI(void) cvGetModuleInfo( const char* module_name,\r
+ const char** version,\r
+ const char** loaded_addon_plugins );\r
+\r
+/* Get current OpenCV error status */\r
+CVAPI(int) cvGetErrStatus( void );\r
+\r
+/* Sets error status silently */\r
+CVAPI(void) cvSetErrStatus( int status );\r
+\r
+#define CV_ErrModeLeaf 0 /* Print error and exit program */\r
+#define CV_ErrModeParent 1 /* Print error and continue */\r
+#define CV_ErrModeSilent 2 /* Don't print and continue */\r
+\r
+/* Retrives current error processing mode */\r
+CVAPI(int) cvGetErrMode( void );\r
+\r
+/* Sets error processing mode, returns previously used mode */\r
+CVAPI(int) cvSetErrMode( int mode );\r
+\r
+/* Sets error status and performs some additonal actions (displaying message box,\r
+ writing message to stderr, terminating application etc.)\r
+ depending on the current error mode */\r
+CVAPI(void) cvError( int status, const char* func_name,\r
+ const char* err_msg, const char* file_name, int line );\r
+\r
+/* Retrieves textual description of the error given its code */\r
+CVAPI(const char*) cvErrorStr( int status );\r
+\r
+/* Retrieves detailed information about the last error occured */\r
+CVAPI(int) cvGetErrInfo( const char** errcode_desc, const char** description,\r
+ const char** filename, int* line );\r
+\r
+/* Maps IPP error codes to the counterparts from OpenCV */\r
+CVAPI(int) cvErrorFromIppStatus( int ipp_status );\r
+\r
+typedef int (CV_CDECL *CvErrorCallback)( int status, const char* func_name,\r
+ const char* err_msg, const char* file_name, int line, void* userdata );\r
+\r
+/* Assigns a new error-handling function */\r
+CVAPI(CvErrorCallback) cvRedirectError( CvErrorCallback error_handler,\r
+ void* userdata CV_DEFAULT(NULL),\r
+ void** prev_userdata CV_DEFAULT(NULL) );\r
+\r
+/*\r
+ Output to:\r
+ cvNulDevReport - nothing\r
+ cvStdErrReport - console(fprintf(stderr,...))\r
+ cvGuiBoxReport - MessageBox(WIN32)\r
+*/\r
+CVAPI(int) cvNulDevReport( int status, const char* func_name, const char* err_msg,\r
+ const char* file_name, int line, void* userdata );\r
+\r
+CVAPI(int) cvStdErrReport( int status, const char* func_name, const char* err_msg,\r
+ const char* file_name, int line, void* userdata );\r
+\r
+CVAPI(int) cvGuiBoxReport( int status, const char* func_name, const char* err_msg,\r
+ const char* file_name, int line, void* userdata );\r
+\r
+typedef void* (CV_CDECL *CvAllocFunc)(size_t size, void* userdata);\r
+typedef int (CV_CDECL *CvFreeFunc)(void* pptr, void* userdata);\r
+\r
+/* Set user-defined memory managment functions (substitutors for malloc and free) that\r
+ will be called by cvAlloc, cvFree and higher-level functions (e.g. cvCreateImage) */\r
+CVAPI(void) cvSetMemoryManager( CvAllocFunc alloc_func CV_DEFAULT(NULL),\r
+ CvFreeFunc free_func CV_DEFAULT(NULL),\r
+ void* userdata CV_DEFAULT(NULL));\r
+\r
+\r
+typedef IplImage* (CV_STDCALL* Cv_iplCreateImageHeader)\r
+ (int,int,int,char*,char*,int,int,int,int,int,\r
+ IplROI*,IplImage*,void*,IplTileInfo*);\r
+typedef void (CV_STDCALL* Cv_iplAllocateImageData)(IplImage*,int,int);\r
+typedef void (CV_STDCALL* Cv_iplDeallocate)(IplImage*,int);\r
+typedef IplROI* (CV_STDCALL* Cv_iplCreateROI)(int,int,int,int,int);\r
+typedef IplImage* (CV_STDCALL* Cv_iplCloneImage)(const IplImage*);\r
+\r
+/* Makes OpenCV use IPL functions for IplImage allocation/deallocation */\r
+CVAPI(void) cvSetIPLAllocators( Cv_iplCreateImageHeader create_header,\r
+ Cv_iplAllocateImageData allocate_data,\r
+ Cv_iplDeallocate deallocate,\r
+ Cv_iplCreateROI create_roi,\r
+ Cv_iplCloneImage clone_image );\r
+\r
+#define CV_TURN_ON_IPL_COMPATIBILITY() \\r
+ cvSetIPLAllocators( iplCreateImageHeader, iplAllocateImage, \\r
+ iplDeallocate, iplCreateROI, iplCloneImage )\r
+\r
+/****************************************************************************************\\r
+* Data Persistence *\r
+\****************************************************************************************/\r
+\r
+/********************************** High-level functions ********************************/\r
+\r
+/* opens existing or creates new file storage */\r
+CVAPI(CvFileStorage*) cvOpenFileStorage( const char* filename,\r
+ CvMemStorage* memstorage,\r
+ int flags );\r
+\r
+/* closes file storage and deallocates buffers */\r
+CVAPI(void) cvReleaseFileStorage( CvFileStorage** fs );\r
+\r
+/* returns attribute value or 0 (NULL) if there is no such attribute */\r
+CVAPI(const char*) cvAttrValue( const CvAttrList* attr, const char* attr_name );\r
+\r
+/* starts writing compound structure (map or sequence) */\r
+CVAPI(void) cvStartWriteStruct( CvFileStorage* fs, const char* name,\r
+ int struct_flags, const char* type_name CV_DEFAULT(NULL),\r
+ CvAttrList attributes CV_DEFAULT(cvAttrList()));\r
+\r
+/* finishes writing compound structure */\r
+CVAPI(void) cvEndWriteStruct( CvFileStorage* fs );\r
+\r
+/* writes an integer */\r
+CVAPI(void) cvWriteInt( CvFileStorage* fs, const char* name, int value );\r
+\r
+/* writes a floating-point number */\r
+CVAPI(void) cvWriteReal( CvFileStorage* fs, const char* name, double value );\r
+\r
+/* writes a string */\r
+CVAPI(void) cvWriteString( CvFileStorage* fs, const char* name,\r
+ const char* str, int quote CV_DEFAULT(0) );\r
+\r
+/* writes a comment */\r
+CVAPI(void) cvWriteComment( CvFileStorage* fs, const char* comment,\r
+ int eol_comment );\r
+\r
+/* writes instance of a standard type (matrix, image, sequence, graph etc.)\r
+ or user-defined type */\r
+CVAPI(void) cvWrite( CvFileStorage* fs, const char* name, const void* ptr,\r
+ CvAttrList attributes CV_DEFAULT(cvAttrList()));\r
+\r
+/* starts the next stream */\r
+CVAPI(void) cvStartNextStream( CvFileStorage* fs );\r
+\r
+/* helper function: writes multiple integer or floating-point numbers */\r
+CVAPI(void) cvWriteRawData( CvFileStorage* fs, const void* src,\r
+ int len, const char* dt );\r
+\r
+/* returns the hash entry corresponding to the specified literal key string or 0\r
+ if there is no such a key in the storage */\r
+CVAPI(CvStringHashNode*) cvGetHashedKey( CvFileStorage* fs, const char* name,\r
+ int len CV_DEFAULT(-1),\r
+ int create_missing CV_DEFAULT(0));\r
+\r
+/* returns file node with the specified key within the specified map\r
+ (collection of named nodes) */\r
+CVAPI(CvFileNode*) cvGetRootFileNode( const CvFileStorage* fs,\r
+ int stream_index CV_DEFAULT(0) );\r
+\r
+/* returns file node with the specified key within the specified map\r
+ (collection of named nodes) */\r
+CVAPI(CvFileNode*) cvGetFileNode( CvFileStorage* fs, CvFileNode* map,\r
+ const CvStringHashNode* key,\r
+ int create_missing CV_DEFAULT(0) );\r
+\r
+/* this is a slower version of cvGetFileNode that takes the key as a literal string */\r
+CVAPI(CvFileNode*) cvGetFileNodeByName( const CvFileStorage* fs,\r
+ const CvFileNode* map,\r
+ const char* name );\r
+\r
+CV_INLINE int cvReadInt( const CvFileNode* node, int default_value CV_DEFAULT(0) )\r
+{\r
+ return !node ? default_value :\r
+ CV_NODE_IS_INT(node->tag) ? node->data.i :\r
+ CV_NODE_IS_REAL(node->tag) ? cvRound(node->data.f) : 0x7fffffff;\r
+}\r
+\r
+\r
+CV_INLINE int cvReadIntByName( const CvFileStorage* fs, const CvFileNode* map,\r
+ const char* name, int default_value CV_DEFAULT(0) )\r
+{\r
+ return cvReadInt( cvGetFileNodeByName( fs, map, name ), default_value );\r
+}\r
+\r
+\r
+CV_INLINE double cvReadReal( const CvFileNode* node, double default_value CV_DEFAULT(0.) )\r
+{\r
+ return !node ? default_value :\r
+ CV_NODE_IS_INT(node->tag) ? (double)node->data.i :\r
+ CV_NODE_IS_REAL(node->tag) ? node->data.f : 1e300;\r
+}\r
+\r
+\r
+CV_INLINE double cvReadRealByName( const CvFileStorage* fs, const CvFileNode* map,\r
+ const char* name, double default_value CV_DEFAULT(0.) )\r
+{\r
+ return cvReadReal( cvGetFileNodeByName( fs, map, name ), default_value );\r
+}\r
+\r
+\r
+CV_INLINE const char* cvReadString( const CvFileNode* node,\r
+ const char* default_value CV_DEFAULT(NULL) )\r
+{\r
+ return !node ? default_value : CV_NODE_IS_STRING(node->tag) ? node->data.str.ptr : 0;\r
+}\r
+\r
+\r
+CV_INLINE const char* cvReadStringByName( const CvFileStorage* fs, const CvFileNode* map,\r
+ const char* name, const char* default_value CV_DEFAULT(NULL) )\r
+{\r
+ return cvReadString( cvGetFileNodeByName( fs, map, name ), default_value );\r
+}\r
+\r
+\r
+/* decodes standard or user-defined object and returns it */\r
+CVAPI(void*) cvRead( CvFileStorage* fs, CvFileNode* node,\r
+ CvAttrList* attributes CV_DEFAULT(NULL));\r
+\r
+/* decodes standard or user-defined object and returns it */\r
+CV_INLINE void* cvReadByName( CvFileStorage* fs, const CvFileNode* map,\r
+ const char* name, CvAttrList* attributes CV_DEFAULT(NULL) )\r
+{\r
+ return cvRead( fs, cvGetFileNodeByName( fs, map, name ), attributes );\r
+}\r
+\r
+\r
+/* starts reading data from sequence or scalar numeric node */\r
+CVAPI(void) cvStartReadRawData( const CvFileStorage* fs, const CvFileNode* src,\r
+ CvSeqReader* reader );\r
+\r
+/* reads multiple numbers and stores them to array */\r
+CVAPI(void) cvReadRawDataSlice( const CvFileStorage* fs, CvSeqReader* reader,\r
+ int count, void* dst, const char* dt );\r
+\r
+/* combination of two previous functions for easier reading of whole sequences */\r
+CVAPI(void) cvReadRawData( const CvFileStorage* fs, const CvFileNode* src,\r
+ void* dst, const char* dt );\r
+\r
+/* writes a copy of file node to file storage */\r
+CVAPI(void) cvWriteFileNode( CvFileStorage* fs, const char* new_node_name,\r
+ const CvFileNode* node, int embed );\r
+\r
+/* returns name of file node */\r
+CVAPI(const char*) cvGetFileNodeName( const CvFileNode* node );\r
+\r
+/*********************************** Adding own types ***********************************/\r
+\r
+CVAPI(void) cvRegisterType( const CvTypeInfo* info );\r
+CVAPI(void) cvUnregisterType( const char* type_name );\r
+CVAPI(CvTypeInfo*) cvFirstType(void);\r
+CVAPI(CvTypeInfo*) cvFindType( const char* type_name );\r
+CVAPI(CvTypeInfo*) cvTypeOf( const void* struct_ptr );\r
+\r
+/* universal functions */\r
+CVAPI(void) cvRelease( void** struct_ptr );\r
+CVAPI(void*) cvClone( const void* struct_ptr );\r
+\r
+/* simple API for reading/writing data */\r
+CVAPI(void) cvSave( const char* filename, const void* struct_ptr,\r
+ const char* name CV_DEFAULT(NULL),\r
+ const char* comment CV_DEFAULT(NULL),\r
+ CvAttrList attributes CV_DEFAULT(cvAttrList()));\r
+CVAPI(void*) cvLoad( const char* filename,\r
+ CvMemStorage* memstorage CV_DEFAULT(NULL),\r
+ const char* name CV_DEFAULT(NULL),\r
+ const char** real_name CV_DEFAULT(NULL) );\r
+\r
+/*********************************** Measuring Execution Time ***************************/\r
+\r
+/* helper functions for RNG initialization and accurate time measurement:\r
+ uses internal clock counter on x86 */\r
+CVAPI(int64) cvGetTickCount( void );\r
+CVAPI(double) cvGetTickFrequency( void );\r
+\r
+/*********************************** Multi-Threading ************************************/\r
+\r
+/* retrieve/set the number of threads used in OpenMP implementations */\r
+CVAPI(int) cvGetNumThreads( void );\r
+CVAPI(void) cvSetNumThreads( int threads CV_DEFAULT(0) );\r
+/* get index of the thread being executed */\r
+CVAPI(int) cvGetThreadNum( void );\r
+\r
+/*************** Convenience functions for better interaction with HighGUI **************/\r
+\r
+typedef IplImage* (CV_CDECL * CvLoadImageFunc)( const char* filename, int colorness );\r
+typedef CvMat* (CV_CDECL * CvLoadImageMFunc)( const char* filename, int colorness );\r
+typedef int (CV_CDECL * CvSaveImageFunc)( const char* filename, const CvArr* image,\r
+ const int* params );\r
+typedef void (CV_CDECL * CvShowImageFunc)( const char* windowname, const CvArr* image );\r
+\r
+CVAPI(int) cvSetImageIOFunctions( CvLoadImageFunc _load_image, CvLoadImageMFunc _load_image_m,\r
+ CvSaveImageFunc _save_image, CvShowImageFunc _show_image );\r
+\r
+#define CV_SET_IMAGE_IO_FUNCTIONS() \\r
+ cvSetImageIOFunctions( cvLoadImage, cvLoadImageM, cvSaveImage, cvShowImage )\r
+\r
+#ifdef __cplusplus\r
+}\r
+\r
+class CV_EXPORTS CvImage\r
+{\r
+public:\r
+ CvImage() : image(0), refcount(0) {}\r
+ CvImage( CvSize size, int depth, int channels )\r
+ {\r
+ image = cvCreateImage( size, depth, channels );\r
+ refcount = image ? new int(1) : 0;\r
+ }\r
+\r
+ CvImage( IplImage* img ) : image(img)\r
+ {\r
+ refcount = image ? new int(1) : 0;\r
+ }\r
+\r
+ CvImage( const CvImage& img ) : image(img.image), refcount(img.refcount)\r
+ {\r
+ if( refcount ) ++(*refcount);\r
+ }\r
+\r
+ CvImage( const char* filename, const char* imgname=0, int color=-1 ) : image(0), refcount(0)\r
+ { load( filename, imgname, color ); }\r
+\r
+ CvImage( CvFileStorage* fs, const char* mapname, const char* imgname ) : image(0), refcount(0)\r
+ { read( fs, mapname, imgname ); }\r
+\r
+ CvImage( CvFileStorage* fs, const char* seqname, int idx ) : image(0), refcount(0)\r
+ { read( fs, seqname, idx ); }\r
+\r
+ ~CvImage()\r
+ {\r
+ if( refcount && !(--*refcount) )\r
+ {\r
+ cvReleaseImage( &image );\r
+ delete refcount;\r
+ }\r
+ }\r
+\r
+ CvImage clone() { return CvImage(image ? cvCloneImage(image) : 0); }\r
+\r
+ void create( CvSize size, int depth, int channels )\r
+ {\r
+ if( !image || !refcount ||\r
+ image->width != size.width || image->height != size.height ||\r
+ image->depth != depth || image->nChannels != channels )\r
+ attach( cvCreateImage( size, depth, channels ));\r
+ }\r
+\r
+ void release() { detach(); }\r
+ void clear() { detach(); }\r
+\r
+ void attach( IplImage* img, bool use_refcount=true )\r
+ {\r
+ if( refcount && --*refcount == 0 )\r
+ {\r
+ cvReleaseImage( &image );\r
+ delete refcount;\r
+ }\r
+ image = img;\r
+ refcount = use_refcount && image ? new int(1) : 0;\r
+ }\r
+\r
+ void detach()\r
+ {\r
+ if( refcount && --*refcount == 0 )\r
+ {\r
+ cvReleaseImage( &image );\r
+ delete refcount;\r
+ }\r
+ image = 0;\r
+ refcount = 0;\r
+ }\r
+\r
+ bool load( const char* filename, const char* imgname=0, int color=-1 );\r
+ bool read( CvFileStorage* fs, const char* mapname, const char* imgname );\r
+ bool read( CvFileStorage* fs, const char* seqname, int idx );\r
+ void save( const char* filename, const char* imgname, const int* params=0 );\r
+ void write( CvFileStorage* fs, const char* imgname );\r
+\r
+ void show( const char* window_name );\r
+ bool is_valid() { return image != 0; }\r
+\r
+ int width() const { return image ? image->width : 0; }\r
+ int height() const { return image ? image->height : 0; }\r
+\r
+ CvSize size() const { return image ? cvSize(image->width, image->height) : cvSize(0,0); }\r
+\r
+ CvSize roi_size() const\r
+ {\r
+ return !image ? cvSize(0,0) :\r
+ !image->roi ? cvSize(image->width,image->height) :\r
+ cvSize(image->roi->width, image->roi->height);\r
+ }\r
+\r
+ CvRect roi() const\r
+ {\r
+ return !image ? cvRect(0,0,0,0) :\r
+ !image->roi ? cvRect(0,0,image->width,image->height) :\r
+ cvRect(image->roi->xOffset,image->roi->yOffset,\r
+ image->roi->width,image->roi->height);\r
+ }\r
+\r
+ int coi() const { return !image || !image->roi ? 0 : image->roi->coi; }\r
+\r
+ void set_roi(CvRect roi) { cvSetImageROI(image,roi); }\r
+ void reset_roi() { cvResetImageROI(image); }\r
+ void set_coi(int coi) { cvSetImageCOI(image,coi); }\r
+ int depth() const { return image ? image->depth : 0; }\r
+ int channels() const { return image ? image->nChannels : 0; }\r
+ int pix_size() const { return image ? ((image->depth & 255)>>3)*image->nChannels : 0; }\r
+\r
+ uchar* data() { return image ? (uchar*)image->imageData : 0; }\r
+ const uchar* data() const { return image ? (const uchar*)image->imageData : 0; }\r
+ int step() const { return image ? image->widthStep : 0; }\r
+ int origin() const { return image ? image->origin : 0; }\r
+\r
+ uchar* roi_row(int y)\r
+ {\r
+ assert(0<=y);\r
+ assert(!image ?\r
+ 1 : image->roi ?\r
+ y<image->roi->height : y<image->height);\r
+ \r
+ return !image ? 0 :\r
+ !image->roi ?\r
+ (uchar*)(image->imageData + y*image->widthStep) :\r
+ (uchar*)(image->imageData + (y+image->roi->yOffset)*image->widthStep +\r
+ image->roi->xOffset*((image->depth & 255)>>3)*image->nChannels);\r
+ }\r
+\r
+ const uchar* roi_row(int y) const\r
+ {\r
+ assert(0<=y);\r
+ assert(!image ?\r
+ 1 : image->roi ?\r
+ y<image->roi->height : y<image->height); \r
+\r
+ return !image ? 0 :\r
+ !image->roi ?\r
+ (const uchar*)(image->imageData + y*image->widthStep) :\r
+ (const uchar*)(image->imageData + (y+image->roi->yOffset)*image->widthStep +\r
+ image->roi->xOffset*((image->depth & 255)>>3)*image->nChannels);\r
+ }\r
+\r
+ operator const IplImage* () const { return image; }\r
+ operator IplImage* () { return image; }\r
+\r
+ CvImage& operator = (const CvImage& img)\r
+ {\r
+ if( img.refcount )\r
+ ++*img.refcount;\r
+ if( refcount && !(--*refcount) )\r
+ cvReleaseImage( &image );\r
+ image=img.image;\r
+ refcount=img.refcount;\r
+ return *this;\r
+ }\r
+\r
+protected:\r
+ IplImage* image;\r
+ int* refcount;\r
+};\r
+\r
+\r
+class CV_EXPORTS CvMatrix\r
+{\r
+public:\r
+ CvMatrix() : matrix(0) {}\r
+ CvMatrix( int rows, int cols, int type )\r
+ { matrix = cvCreateMat( rows, cols, type ); }\r
+\r
+ CvMatrix( int rows, int cols, int type, CvMat* hdr,\r
+ void* data=0, int step=CV_AUTOSTEP )\r
+ { matrix = cvInitMatHeader( hdr, rows, cols, type, data, step ); }\r
+\r
+ CvMatrix( int rows, int cols, int type, CvMemStorage* storage, bool alloc_data=true );\r
+\r
+ CvMatrix( int rows, int cols, int type, void* data, int step=CV_AUTOSTEP )\r
+ { matrix = cvCreateMatHeader( rows, cols, type );\r
+ cvSetData( matrix, data, step ); }\r
+\r
+ CvMatrix( CvMat* m )\r
+ { matrix = m; }\r
+\r
+ CvMatrix( const CvMatrix& m )\r
+ {\r
+ matrix = m.matrix;\r
+ addref();\r
+ }\r
+\r
+ CvMatrix( const char* filename, const char* matname=0, int color=-1 ) : matrix(0)\r
+ { load( filename, matname, color ); }\r
+\r
+ CvMatrix( CvFileStorage* fs, const char* mapname, const char* matname ) : matrix(0)\r
+ { read( fs, mapname, matname ); }\r
+\r
+ CvMatrix( CvFileStorage* fs, const char* seqname, int idx ) : matrix(0)\r
+ { read( fs, seqname, idx ); }\r
+\r
+ ~CvMatrix()\r
+ {\r
+ release();\r
+ }\r
+\r
+ CvMatrix clone() { return CvMatrix(matrix ? cvCloneMat(matrix) : 0); }\r
+\r
+ void set( CvMat* m, bool add_ref )\r
+ {\r
+ release();\r
+ matrix = m;\r
+ if( add_ref )\r
+ addref();\r
+ }\r
+\r
+ void create( int rows, int cols, int type )\r
+ {\r
+ if( !matrix || !matrix->refcount ||\r
+ matrix->rows != rows || matrix->cols != cols ||\r
+ CV_MAT_TYPE(matrix->type) != type )\r
+ set( cvCreateMat( rows, cols, type ), false );\r
+ }\r
+\r
+ void addref() const\r
+ {\r
+ if( matrix )\r
+ {\r
+ if( matrix->hdr_refcount )\r
+ ++matrix->hdr_refcount;\r
+ else if( matrix->refcount )\r
+ ++*matrix->refcount;\r
+ }\r
+ }\r
+\r
+ void release()\r
+ {\r
+ if( matrix )\r
+ {\r
+ if( matrix->hdr_refcount )\r
+ {\r
+ if( --matrix->hdr_refcount == 0 )\r
+ cvReleaseMat( &matrix );\r
+ }\r
+ else if( matrix->refcount )\r
+ {\r
+ if( --*matrix->refcount == 0 )\r
+ cvFree( &matrix->refcount );\r
+ }\r
+ matrix = 0;\r
+ }\r
+ }\r
+\r
+ void clear()\r
+ {\r
+ release();\r
+ }\r
+\r
+ bool load( const char* filename, const char* matname=0, int color=-1 );\r
+ bool read( CvFileStorage* fs, const char* mapname, const char* matname );\r
+ bool read( CvFileStorage* fs, const char* seqname, int idx );\r
+ void save( const char* filename, const char* matname, const int* params=0 );\r
+ void write( CvFileStorage* fs, const char* matname );\r
+\r
+ void show( const char* window_name );\r
+\r
+ bool is_valid() { return matrix != 0; }\r
+\r
+ int rows() const { return matrix ? matrix->rows : 0; }\r
+ int cols() const { return matrix ? matrix->cols : 0; }\r
+\r
+ CvSize size() const\r
+ {\r
+ return !matrix ? cvSize(0,0) : cvSize(matrix->rows,matrix->cols);\r
+ }\r
+\r
+ int type() const { return matrix ? CV_MAT_TYPE(matrix->type) : 0; }\r
+ int depth() const { return matrix ? CV_MAT_DEPTH(matrix->type) : 0; }\r
+ int channels() const { return matrix ? CV_MAT_CN(matrix->type) : 0; }\r
+ int pix_size() const { return matrix ? CV_ELEM_SIZE(matrix->type) : 0; }\r
+\r
+ uchar* data() { return matrix ? matrix->data.ptr : 0; }\r
+ const uchar* data() const { return matrix ? matrix->data.ptr : 0; }\r
+ int step() const { return matrix ? matrix->step : 0; }\r
+\r
+ void set_data( void* data, int step=CV_AUTOSTEP )\r
+ { cvSetData( matrix, data, step ); }\r
+\r
+ uchar* row(int i) { return !matrix ? 0 : matrix->data.ptr + i*matrix->step; }\r
+ const uchar* row(int i) const\r
+ { return !matrix ? 0 : matrix->data.ptr + i*matrix->step; }\r
+\r
+ operator const CvMat* () const { return matrix; }\r
+ operator CvMat* () { return matrix; }\r
+\r
+ CvMatrix& operator = (const CvMatrix& _m)\r
+ {\r
+ _m.addref();\r
+ release();\r
+ matrix = _m.matrix;\r
+ return *this;\r
+ }\r
+\r
+protected:\r
+ CvMat* matrix;\r
+};\r
+\r
+\r
+// classes for automatic module/RTTI data registration/unregistration\r
+struct CV_EXPORTS CvModule\r
+{\r
+ CvModule( CvModuleInfo* _info );\r
+ ~CvModule();\r
+ CvModuleInfo* info;\r
+\r
+ static CvModuleInfo* first;\r
+ static CvModuleInfo* last;\r
+};\r
+\r
+struct CV_EXPORTS CvType\r
+{\r
+ CvType( const char* type_name,\r
+ CvIsInstanceFunc is_instance, CvReleaseFunc release=0,\r
+ CvReadFunc read=0, CvWriteFunc write=0, CvCloneFunc clone=0 );\r
+ ~CvType();\r
+ CvTypeInfo* info;\r
+\r
+ static CvTypeInfo* first;\r
+ static CvTypeInfo* last;\r
+};\r
+\r
+#endif\r
+\r
+#ifndef SKIP_INCLUDES // for now only expose old interface to swig\r
+#include "cxcore.hpp"\r
+#endif // SKIP_INCLUDES\r
+\r
+#endif /*_CXCORE_H_*/\r