00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #ifndef __OPENCV_CORE_TYPES_H__
00044 #define __OPENCV_CORE_TYPES_H__
00045
00046 #if !defined _CRT_SECURE_NO_DEPRECATE && _MSC_VER > 1300
00047 #define _CRT_SECURE_NO_DEPRECATE
00048 #endif
00049
00050
00051 #ifndef SKIP_INCLUDES
00052 #include <assert.h>
00053 #include <stdlib.h>
00054 #include <string.h>
00055 #include <float.h>
00056
00057 #if !defined _MSC_VER && !defined __BORLANDC__
00058 #include <stdint.h>
00059 #endif
00060
00061 #if defined __ICL
00062 #define CV_ICC __ICL
00063 #elif defined __ICC
00064 #define CV_ICC __ICC
00065 #elif defined __ECL
00066 #define CV_ICC __ECL
00067 #elif defined __ECC
00068 #define CV_ICC __ECC
00069 #elif defined __INTEL_COMPILER
00070 #define CV_ICC __INTEL_COMPILER
00071 #endif
00072
00073 #if (_MSC_VER >= 1400 && defined _M_X64) || (__GNUC__ >= 4 && defined __x86_64__)
00074 #if defined WIN32
00075 #include <intrin.h>
00076 #endif
00077 #include <emmintrin.h>
00078 #endif
00079
00080 #if defined __BORLANDC__
00081 #include <fastmath.h>
00082 #else
00083 #include <math.h>
00084 #endif
00085
00086 #ifdef HAVE_IPL
00087 #ifndef __IPL_H__
00088 #if defined WIN32 || defined _WIN32
00089 #include <ipl.h>
00090 #else
00091 #include <ipl/ipl.h>
00092 #endif
00093 #endif
00094 #elif defined __IPL_H__
00095 #define HAVE_IPL
00096 #endif
00097 #endif // SKIP_INCLUDES
00098
00099 #if defined WIN32 || defined _WIN32
00100 #define CV_CDECL __cdecl
00101 #define CV_STDCALL __stdcall
00102 #else
00103 #define CV_CDECL
00104 #define CV_STDCALL
00105 #endif
00106
00107 #ifndef CV_EXTERN_C
00108 #ifdef __cplusplus
00109 #define CV_EXTERN_C extern "C"
00110 #define CV_DEFAULT(val) = val
00111 #else
00112 #define CV_EXTERN_C
00113 #define CV_DEFAULT(val)
00114 #endif
00115 #endif
00116
00117 #ifndef CV_EXTERN_C_FUNCPTR
00118 #ifdef __cplusplus
00119 #define CV_EXTERN_C_FUNCPTR(x) extern "C" { typedef x; }
00120 #else
00121 #define CV_EXTERN_C_FUNCPTR(x) typedef x
00122 #endif
00123 #endif
00124
00125 #ifndef CV_INLINE
00126 #if defined __cplusplus
00127 #define CV_INLINE inline
00128 #elif (defined WIN32 || defined _WIN32 || defined WINCE) && !defined __GNUC__
00129 #define CV_INLINE __inline
00130 #else
00131 #define CV_INLINE static
00132 #endif
00133 #endif
00134
00135 #if (defined WIN32 || defined _WIN32 || defined WINCE) && defined CVAPI_EXPORTS
00136 #define CV_EXPORTS __declspec(dllexport)
00137 #else
00138 #define CV_EXPORTS
00139 #endif
00140
00141 #ifndef CVAPI
00142 #define CVAPI(rettype) CV_EXTERN_C CV_EXPORTS rettype CV_CDECL
00143 #endif
00144
00145 #if defined _MSC_VER || defined __BORLANDC__
00146 typedef __int64 int64;
00147 typedef unsigned __int64 uint64;
00148 #define CV_BIG_INT(n) n##I64
00149 #define CV_BIG_UINT(n) n##UI64
00150 #else
00151 typedef int64_t int64;
00152 typedef uint64_t uint64;
00153 #define CV_BIG_INT(n) n##LL
00154 #define CV_BIG_UINT(n) n##ULL
00155 #endif
00156
00157 #ifndef HAVE_IPL
00158 typedef unsigned char uchar;
00159 typedef unsigned short ushort;
00160 #endif
00161
00162 typedef signed char schar;
00163
00164
00165 #define CV_CARRAY(counter)
00166 #define CV_CUSTOM_CARRAY(args)
00167 #define CV_EXPORTS_W CV_EXPORTS
00168 #define CV_EXPORTS_W_SIMPLE CV_EXPORTS
00169 #define CV_EXPORTS_AS(synonym) CV_EXPORTS
00170 #define CV_EXPORTS_W_MAP CV_EXPORTS
00171 #define CV_IN_OUT
00172 #define CV_OUT
00173 #define CV_PROP
00174 #define CV_PROP_RW
00175 #define CV_WRAP
00176 #define CV_WRAP_AS(synonym)
00177 #define CV_WRAP_DEFAULT(value)
00178
00179
00180
00181
00182
00183
00184 typedef void CvArr;
00185
00186 typedef union Cv32suf
00187 {
00188 int i;
00189 unsigned u;
00190 float f;
00191 }
00192 Cv32suf;
00193
00194 typedef union Cv64suf
00195 {
00196 int64 i;
00197 uint64 u;
00198 double f;
00199 }
00200 Cv64suf;
00201
00202 typedef int CVStatus;
00203
00204 enum {
00205 CV_StsOk= 0,
00206 CV_StsBackTrace= -1,
00207 CV_StsError= -2,
00208 CV_StsInternal= -3,
00209 CV_StsNoMem= -4,
00210 CV_StsBadArg= -5,
00211 CV_StsBadFunc= -6,
00212 CV_StsNoConv= -7,
00213 CV_StsAutoTrace= -8,
00214 CV_HeaderIsNull= -9,
00215 CV_BadImageSize= -10,
00216 CV_BadOffset= -11,
00217 CV_BadDataPtr= -12,
00218 CV_BadStep= -13,
00219 CV_BadModelOrChSeq= -14,
00220 CV_BadNumChannels= -15,
00221 CV_BadNumChannel1U= -16,
00222 CV_BadDepth= -17,
00223 CV_BadAlphaChannel= -18,
00224 CV_BadOrder= -19,
00225 CV_BadOrigin= -20,
00226 CV_BadAlign= -21,
00227 CV_BadCallBack= -22,
00228 CV_BadTileSize= -23,
00229 CV_BadCOI= -24,
00230 CV_BadROISize= -25,
00231 CV_MaskIsTiled= -26,
00232 CV_StsNullPtr= -27,
00233 CV_StsVecLengthErr= -28,
00234 CV_StsFilterStructContentErr= -29,
00235 CV_StsKernelStructContentErr= -30,
00236 CV_StsFilterOffsetErr= -31,
00237 CV_StsBadSize= -201,
00238 CV_StsDivByZero= -202,
00239 CV_StsInplaceNotSupported= -203,
00240 CV_StsObjectNotFound= -204,
00241 CV_StsUnmatchedFormats= -205,
00242 CV_StsBadFlag= -206,
00243 CV_StsBadPoint= -207,
00244 CV_StsBadMask= -208,
00245 CV_StsUnmatchedSizes= -209,
00246 CV_StsUnsupportedFormat= -210,
00247 CV_StsOutOfRange= -211,
00248 CV_StsParseError= -212,
00249 CV_StsNotImplemented= -213,
00250 CV_StsBadMemBlock= -214,
00251 CV_StsAssert= -215,
00252 CV_GpuNotSupported= -216,
00253 CV_GpuApiCallError= -217,
00254 CV_GpuNppCallError= -218,
00255 CV_GpuCufftCallError= -219
00256 };
00257
00258
00259
00260
00261
00262 #define CV_PI 3.1415926535897932384626433832795
00263 #define CV_LOG2 0.69314718055994530941723212145818
00264
00265 #define CV_SWAP(a,b,t) ((t) = (a), (a) = (b), (b) = (t))
00266
00267 #ifndef MIN
00268 #define MIN(a,b) ((a) > (b) ? (b) : (a))
00269 #endif
00270
00271 #ifndef MAX
00272 #define MAX(a,b) ((a) < (b) ? (b) : (a))
00273 #endif
00274
00275
00276 #define CV_IMIN(a, b) ((a) ^ (((a)^(b)) & (((a) < (b)) - 1)))
00277
00278 #define CV_IMAX(a, b) ((a) ^ (((a)^(b)) & (((a) > (b)) - 1)))
00279
00280
00281 #ifndef __cplusplus
00282 #define CV_IABS(a) (((a) ^ ((a) < 0 ? -1 : 0)) - ((a) < 0 ? -1 : 0))
00283 #else
00284 #define CV_IABS(a) abs(a)
00285 #endif
00286 #define CV_CMP(a,b) (((a) > (b)) - ((a) < (b)))
00287 #define CV_SIGN(a) CV_CMP((a),0)
00288
00289 CV_INLINE int cvRound( double value )
00290 {
00291 #if (defined _MSC_VER && defined _M_X64) || (defined __GNUC__ && defined __x86_64__ && !defined __APPLE__)
00292 __m128d t = _mm_set_sd( value );
00293 return _mm_cvtsd_si32(t);
00294 #elif defined _MSC_VER && defined _M_IX86
00295 int t;
00296 __asm
00297 {
00298 fld value;
00299 fistp t;
00300 }
00301 return t;
00302 #elif defined HAVE_LRINT || defined CV_ICC || defined __GNUC__
00303 return (int)lrint(value);
00304 #else
00305
00306 return (int)(value + (value >= 0 ? 0.5 : -0.5));
00307 #endif
00308 }
00309
00310
00311 CV_INLINE int cvFloor( double value )
00312 {
00313 #ifdef __GNUC__
00314 int i = (int)value;
00315 return i - (i > value);
00316 #elif defined _MSC_VER && defined _M_X64
00317 __m128d t = _mm_set_sd( value );
00318 int i = _mm_cvtsd_si32(t);
00319 return i - _mm_movemask_pd(_mm_cmplt_sd(t, _mm_cvtsi32_sd(t,i)));
00320 #else
00321 int i = cvRound(value);
00322 Cv32suf diff;
00323 diff.f = (float)(value - i);
00324 return i - (diff.i < 0);
00325 #endif
00326 }
00327
00328
00329 CV_INLINE int cvCeil( double value )
00330 {
00331 #ifdef __GNUC__
00332 int i = (int)value;
00333 return i + (i < value);
00334 #elif defined _MSC_VER && defined _M_X64
00335 __m128d t = _mm_set_sd( value );
00336 int i = _mm_cvtsd_si32(t);
00337 return i + _mm_movemask_pd(_mm_cmplt_sd(_mm_cvtsi32_sd(t,i), t));
00338 #else
00339 int i = cvRound(value);
00340 Cv32suf diff;
00341 diff.f = (float)(i - value);
00342 return i + (diff.i < 0);
00343 #endif
00344 }
00345
00346 #define cvInvSqrt(value) ((float)(1./sqrt(value)))
00347 #define cvSqrt(value) ((float)sqrt(value))
00348
00349 CV_INLINE int cvIsNaN( double value )
00350 {
00351 #if 1
00352
00353
00354
00355
00356 Cv64suf ieee754;
00357 ieee754.f = value;
00358 return ((unsigned)(ieee754.u >> 32) & 0x7fffffff) +
00359 ((unsigned)ieee754.u != 0) > 0x7ff00000;
00360 #endif
00361 }
00362
00363
00364 CV_INLINE int cvIsInf( double value )
00365 {
00366 #if 1
00367
00368
00369
00370
00371 Cv64suf ieee754;
00372 ieee754.f = value;
00373 return ((unsigned)(ieee754.u >> 32) & 0x7fffffff) == 0x7ff00000 &&
00374 (unsigned)ieee754.u == 0;
00375 #endif
00376 }
00377
00378
00379
00380
00381 typedef uint64 CvRNG;
00382
00383 #define CV_RNG_COEFF 4164903690U
00384
00385 CV_INLINE CvRNG cvRNG( int64 seed CV_DEFAULT(-1))
00386 {
00387 CvRNG rng = seed ? (uint64)seed : (uint64)(int64)-1;
00388 return rng;
00389 }
00390
00391
00392 CV_INLINE unsigned cvRandInt( CvRNG* rng )
00393 {
00394 uint64 temp = *rng;
00395 temp = (uint64)(unsigned)temp*CV_RNG_COEFF + (temp >> 32);
00396 *rng = temp;
00397 return (unsigned)temp;
00398 }
00399
00400
00401 CV_INLINE double cvRandReal( CvRNG* rng )
00402 {
00403 return cvRandInt(rng)*2.3283064365386962890625e-10 ;
00404 }
00405
00406
00407
00408
00409
00410 #ifndef HAVE_IPL
00411
00412
00413
00414
00415
00416
00417 #define IPL_DEPTH_SIGN 0x80000000
00418
00419 #define IPL_DEPTH_1U 1
00420 #define IPL_DEPTH_8U 8
00421 #define IPL_DEPTH_16U 16
00422 #define IPL_DEPTH_32F 32
00423
00424 #define IPL_DEPTH_8S (IPL_DEPTH_SIGN| 8)
00425 #define IPL_DEPTH_16S (IPL_DEPTH_SIGN|16)
00426 #define IPL_DEPTH_32S (IPL_DEPTH_SIGN|32)
00427
00428 #define IPL_DATA_ORDER_PIXEL 0
00429 #define IPL_DATA_ORDER_PLANE 1
00430
00431 #define IPL_ORIGIN_TL 0
00432 #define IPL_ORIGIN_BL 1
00433
00434 #define IPL_ALIGN_4BYTES 4
00435 #define IPL_ALIGN_8BYTES 8
00436 #define IPL_ALIGN_16BYTES 16
00437 #define IPL_ALIGN_32BYTES 32
00438
00439 #define IPL_ALIGN_DWORD IPL_ALIGN_4BYTES
00440 #define IPL_ALIGN_QWORD IPL_ALIGN_8BYTES
00441
00442 #define IPL_BORDER_CONSTANT 0
00443 #define IPL_BORDER_REPLICATE 1
00444 #define IPL_BORDER_REFLECT 2
00445 #define IPL_BORDER_WRAP 3
00446
00447 typedef struct _IplImage
00448 {
00449 int nSize;
00450 int ID;
00451 int nChannels;
00452 int alphaChannel;
00453 int depth;
00454
00455 char colorModel[4];
00456 char channelSeq[4];
00457 int dataOrder;
00458
00459 int origin;
00460
00461 int align;
00462
00463 int width;
00464 int height;
00465 struct _IplROI *roi;
00466 struct _IplImage *maskROI;
00467 void *imageId;
00468 struct _IplTileInfo *tileInfo;
00469 int imageSize;
00470
00471
00472 char *imageData;
00473 int widthStep;
00474 int BorderMode[4];
00475 int BorderConst[4];
00476 char *imageDataOrigin;
00477
00478
00479 }
00480 IplImage;
00481
00482 typedef struct _IplTileInfo IplTileInfo;
00483
00484 typedef struct _IplROI
00485 {
00486 int coi;
00487 int xOffset;
00488 int yOffset;
00489 int width;
00490 int height;
00491 }
00492 IplROI;
00493
00494 typedef struct _IplConvKernel
00495 {
00496 int nCols;
00497 int nRows;
00498 int anchorX;
00499 int anchorY;
00500 int *values;
00501 int nShiftR;
00502 }
00503 IplConvKernel;
00504
00505 typedef struct _IplConvKernelFP
00506 {
00507 int nCols;
00508 int nRows;
00509 int anchorX;
00510 int anchorY;
00511 float *values;
00512 }
00513 IplConvKernelFP;
00514
00515 #define IPL_IMAGE_HEADER 1
00516 #define IPL_IMAGE_DATA 2
00517 #define IPL_IMAGE_ROI 4
00518
00519 #endif
00520
00521
00522 #define IPL_BORDER_REFLECT_101 4
00523 #define IPL_BORDER_TRANSPARENT 5
00524
00525 #define IPL_IMAGE_MAGIC_VAL ((int)sizeof(IplImage))
00526 #define CV_TYPE_NAME_IMAGE "opencv-image"
00527
00528 #define CV_IS_IMAGE_HDR(img) \
00529 ((img) != NULL && ((const IplImage*)(img))->nSize == sizeof(IplImage))
00530
00531 #define CV_IS_IMAGE(img) \
00532 (CV_IS_IMAGE_HDR(img) && ((IplImage*)img)->imageData != NULL)
00533
00534
00535
00536 #define IPL_DEPTH_64F 64
00537
00538
00539
00540 #define CV_IMAGE_ELEM( image, elemtype, row, col ) \
00541 (((elemtype*)((image)->imageData + (image)->widthStep*(row)))[(col)])
00542
00543
00544
00545
00546
00547 #define CV_CN_MAX 512
00548 #define CV_CN_SHIFT 3
00549 #define CV_DEPTH_MAX (1 << CV_CN_SHIFT)
00550
00551 #define CV_8U 0
00552 #define CV_8S 1
00553 #define CV_16U 2
00554 #define CV_16S 3
00555 #define CV_32S 4
00556 #define CV_32F 5
00557 #define CV_64F 6
00558 #define CV_USRTYPE1 7
00559
00560 #define CV_MAT_DEPTH_MASK (CV_DEPTH_MAX - 1)
00561 #define CV_MAT_DEPTH(flags) ((flags) & CV_MAT_DEPTH_MASK)
00562
00563 #define CV_MAKETYPE(depth,cn) (CV_MAT_DEPTH(depth) + (((cn)-1) << CV_CN_SHIFT))
00564 #define CV_MAKE_TYPE CV_MAKETYPE
00565
00566 #define CV_8UC1 CV_MAKETYPE(CV_8U,1)
00567 #define CV_8UC2 CV_MAKETYPE(CV_8U,2)
00568 #define CV_8UC3 CV_MAKETYPE(CV_8U,3)
00569 #define CV_8UC4 CV_MAKETYPE(CV_8U,4)
00570 #define CV_8UC(n) CV_MAKETYPE(CV_8U,(n))
00571
00572 #define CV_8SC1 CV_MAKETYPE(CV_8S,1)
00573 #define CV_8SC2 CV_MAKETYPE(CV_8S,2)
00574 #define CV_8SC3 CV_MAKETYPE(CV_8S,3)
00575 #define CV_8SC4 CV_MAKETYPE(CV_8S,4)
00576 #define CV_8SC(n) CV_MAKETYPE(CV_8S,(n))
00577
00578 #define CV_16UC1 CV_MAKETYPE(CV_16U,1)
00579 #define CV_16UC2 CV_MAKETYPE(CV_16U,2)
00580 #define CV_16UC3 CV_MAKETYPE(CV_16U,3)
00581 #define CV_16UC4 CV_MAKETYPE(CV_16U,4)
00582 #define CV_16UC(n) CV_MAKETYPE(CV_16U,(n))
00583
00584 #define CV_16SC1 CV_MAKETYPE(CV_16S,1)
00585 #define CV_16SC2 CV_MAKETYPE(CV_16S,2)
00586 #define CV_16SC3 CV_MAKETYPE(CV_16S,3)
00587 #define CV_16SC4 CV_MAKETYPE(CV_16S,4)
00588 #define CV_16SC(n) CV_MAKETYPE(CV_16S,(n))
00589
00590 #define CV_32SC1 CV_MAKETYPE(CV_32S,1)
00591 #define CV_32SC2 CV_MAKETYPE(CV_32S,2)
00592 #define CV_32SC3 CV_MAKETYPE(CV_32S,3)
00593 #define CV_32SC4 CV_MAKETYPE(CV_32S,4)
00594 #define CV_32SC(n) CV_MAKETYPE(CV_32S,(n))
00595
00596 #define CV_32FC1 CV_MAKETYPE(CV_32F,1)
00597 #define CV_32FC2 CV_MAKETYPE(CV_32F,2)
00598 #define CV_32FC3 CV_MAKETYPE(CV_32F,3)
00599 #define CV_32FC4 CV_MAKETYPE(CV_32F,4)
00600 #define CV_32FC(n) CV_MAKETYPE(CV_32F,(n))
00601
00602 #define CV_64FC1 CV_MAKETYPE(CV_64F,1)
00603 #define CV_64FC2 CV_MAKETYPE(CV_64F,2)
00604 #define CV_64FC3 CV_MAKETYPE(CV_64F,3)
00605 #define CV_64FC4 CV_MAKETYPE(CV_64F,4)
00606 #define CV_64FC(n) CV_MAKETYPE(CV_64F,(n))
00607
00608 #define CV_AUTO_STEP 0x7fffffff
00609 #define CV_WHOLE_ARR cvSlice( 0, 0x3fffffff )
00610
00611 #define CV_MAT_CN_MASK ((CV_CN_MAX - 1) << CV_CN_SHIFT)
00612 #define CV_MAT_CN(flags) ((((flags) & CV_MAT_CN_MASK) >> CV_CN_SHIFT) + 1)
00613 #define CV_MAT_TYPE_MASK (CV_DEPTH_MAX*CV_CN_MAX - 1)
00614 #define CV_MAT_TYPE(flags) ((flags) & CV_MAT_TYPE_MASK)
00615 #define CV_MAT_CONT_FLAG_SHIFT 14
00616 #define CV_MAT_CONT_FLAG (1 << CV_MAT_CONT_FLAG_SHIFT)
00617 #define CV_IS_MAT_CONT(flags) ((flags) & CV_MAT_CONT_FLAG)
00618 #define CV_IS_CONT_MAT CV_IS_MAT_CONT
00619 #define CV_SUBMAT_FLAG_SHIFT 15
00620 #define CV_SUBMAT_FLAG (1 << CV_SUBMAT_FLAG_SHIFT)
00621 #define CV_IS_SUBMAT(flags) ((flags) & CV_MAT_SUBMAT_FLAG)
00622
00623 #define CV_MAGIC_MASK 0xFFFF0000
00624 #define CV_MAT_MAGIC_VAL 0x42420000
00625 #define CV_TYPE_NAME_MAT "opencv-matrix"
00626
00627 typedef struct CvMat
00628 {
00629 int type;
00630 int step;
00631
00632
00633 int* refcount;
00634 int hdr_refcount;
00635
00636 union
00637 {
00638 uchar* ptr;
00639 short* s;
00640 int* i;
00641 float* fl;
00642 double* db;
00643 } data;
00644
00645 #ifdef __cplusplus
00646 union
00647 {
00648 int rows;
00649 int height;
00650 };
00651
00652 union
00653 {
00654 int cols;
00655 int width;
00656 };
00657 #else
00658 int rows;
00659 int cols;
00660 #endif
00661
00662 }
00663 CvMat;
00664
00665
00666 #define CV_IS_MAT_HDR(mat) \
00667 ((mat) != NULL && \
00668 (((const CvMat*)(mat))->type & CV_MAGIC_MASK) == CV_MAT_MAGIC_VAL && \
00669 ((const CvMat*)(mat))->cols > 0 && ((const CvMat*)(mat))->rows > 0)
00670
00671 #define CV_IS_MAT_HDR_Z(mat) \
00672 ((mat) != NULL && \
00673 (((const CvMat*)(mat))->type & CV_MAGIC_MASK) == CV_MAT_MAGIC_VAL && \
00674 ((const CvMat*)(mat))->cols >= 0 && ((const CvMat*)(mat))->rows >= 0)
00675
00676 #define CV_IS_MAT(mat) \
00677 (CV_IS_MAT_HDR(mat) && ((const CvMat*)(mat))->data.ptr != NULL)
00678
00679 #define CV_IS_MASK_ARR(mat) \
00680 (((mat)->type & (CV_MAT_TYPE_MASK & ~CV_8SC1)) == 0)
00681
00682 #define CV_ARE_TYPES_EQ(mat1, mat2) \
00683 ((((mat1)->type ^ (mat2)->type) & CV_MAT_TYPE_MASK) == 0)
00684
00685 #define CV_ARE_CNS_EQ(mat1, mat2) \
00686 ((((mat1)->type ^ (mat2)->type) & CV_MAT_CN_MASK) == 0)
00687
00688 #define CV_ARE_DEPTHS_EQ(mat1, mat2) \
00689 ((((mat1)->type ^ (mat2)->type) & CV_MAT_DEPTH_MASK) == 0)
00690
00691 #define CV_ARE_SIZES_EQ(mat1, mat2) \
00692 ((mat1)->rows == (mat2)->rows && (mat1)->cols == (mat2)->cols)
00693
00694 #define CV_IS_MAT_CONST(mat) \
00695 (((mat)->rows|(mat)->cols) == 1)
00696
00697
00698
00699 #define CV_ELEM_SIZE1(type) \
00700 ((((sizeof(size_t)<<28)|0x8442211) >> CV_MAT_DEPTH(type)*4) & 15)
00701
00702
00703 #define CV_ELEM_SIZE(type) \
00704 (CV_MAT_CN(type) << ((((sizeof(size_t)/4+1)*16384|0x3a50) >> CV_MAT_DEPTH(type)*2) & 3))
00705
00706 #define IPL2CV_DEPTH(depth) \
00707 ((((CV_8U)+(CV_16U<<4)+(CV_32F<<8)+(CV_64F<<16)+(CV_8S<<20)+ \
00708 (CV_16S<<24)+(CV_32S<<28)) >> ((((depth) & 0xF0) >> 2) + \
00709 (((depth) & IPL_DEPTH_SIGN) ? 20 : 0))) & 15)
00710
00711
00712
00713
00714
00715 CV_INLINE CvMat cvMat( int rows, int cols, int type, void* data CV_DEFAULT(NULL))
00716 {
00717 CvMat m;
00718
00719 assert( (unsigned)CV_MAT_DEPTH(type) <= CV_64F );
00720 type = CV_MAT_TYPE(type);
00721 m.type = CV_MAT_MAGIC_VAL | CV_MAT_CONT_FLAG | type;
00722 m.cols = cols;
00723 m.rows = rows;
00724 m.step = m.cols*CV_ELEM_SIZE(type);
00725 m.data.ptr = (uchar*)data;
00726 m.refcount = NULL;
00727 m.hdr_refcount = 0;
00728
00729 return m;
00730 }
00731
00732
00733 #define CV_MAT_ELEM_PTR_FAST( mat, row, col, pix_size ) \
00734 (assert( (unsigned)(row) < (unsigned)(mat).rows && \
00735 (unsigned)(col) < (unsigned)(mat).cols ), \
00736 (mat).data.ptr + (size_t)(mat).step*(row) + (pix_size)*(col))
00737
00738 #define CV_MAT_ELEM_PTR( mat, row, col ) \
00739 CV_MAT_ELEM_PTR_FAST( mat, row, col, CV_ELEM_SIZE((mat).type) )
00740
00741 #define CV_MAT_ELEM( mat, elemtype, row, col ) \
00742 (*(elemtype*)CV_MAT_ELEM_PTR_FAST( mat, row, col, sizeof(elemtype)))
00743
00744
00745 CV_INLINE double cvmGet( const CvMat* mat, int row, int col )
00746 {
00747 int type;
00748
00749 type = CV_MAT_TYPE(mat->type);
00750 assert( (unsigned)row < (unsigned)mat->rows &&
00751 (unsigned)col < (unsigned)mat->cols );
00752
00753 if( type == CV_32FC1 )
00754 return ((float*)(mat->data.ptr + (size_t)mat->step*row))[col];
00755 else
00756 {
00757 assert( type == CV_64FC1 );
00758 return ((double*)(mat->data.ptr + (size_t)mat->step*row))[col];
00759 }
00760 }
00761
00762
00763 CV_INLINE void cvmSet( CvMat* mat, int row, int col, double value )
00764 {
00765 int type;
00766 type = CV_MAT_TYPE(mat->type);
00767 assert( (unsigned)row < (unsigned)mat->rows &&
00768 (unsigned)col < (unsigned)mat->cols );
00769
00770 if( type == CV_32FC1 )
00771 ((float*)(mat->data.ptr + (size_t)mat->step*row))[col] = (float)value;
00772 else
00773 {
00774 assert( type == CV_64FC1 );
00775 ((double*)(mat->data.ptr + (size_t)mat->step*row))[col] = (double)value;
00776 }
00777 }
00778
00779
00780 CV_INLINE int cvIplDepth( int type )
00781 {
00782 int depth = CV_MAT_DEPTH(type);
00783 return CV_ELEM_SIZE1(depth)*8 | (depth == CV_8S || depth == CV_16S ||
00784 depth == CV_32S ? IPL_DEPTH_SIGN : 0);
00785 }
00786
00787
00788
00789
00790
00791
00792 #define CV_MATND_MAGIC_VAL 0x42430000
00793 #define CV_TYPE_NAME_MATND "opencv-nd-matrix"
00794
00795 #define CV_MAX_DIM 32
00796 #define CV_MAX_DIM_HEAP 1024
00797
00798 typedef struct CvMatND
00799 {
00800 int type;
00801 int dims;
00802
00803 int* refcount;
00804 int hdr_refcount;
00805
00806 union
00807 {
00808 uchar* ptr;
00809 float* fl;
00810 double* db;
00811 int* i;
00812 short* s;
00813 } data;
00814
00815 struct
00816 {
00817 int size;
00818 int step;
00819 }
00820 dim[CV_MAX_DIM];
00821 }
00822 CvMatND;
00823
00824 #define CV_IS_MATND_HDR(mat) \
00825 ((mat) != NULL && (((const CvMatND*)(mat))->type & CV_MAGIC_MASK) == CV_MATND_MAGIC_VAL)
00826
00827 #define CV_IS_MATND(mat) \
00828 (CV_IS_MATND_HDR(mat) && ((const CvMatND*)(mat))->data.ptr != NULL)
00829
00830
00831
00832
00833
00834
00835 #define CV_SPARSE_MAT_MAGIC_VAL 0x42440000
00836 #define CV_TYPE_NAME_SPARSE_MAT "opencv-sparse-matrix"
00837
00838 struct CvSet;
00839
00840 typedef struct CvSparseMat
00841 {
00842 int type;
00843 int dims;
00844 int* refcount;
00845 int hdr_refcount;
00846
00847 struct CvSet* heap;
00848 void** hashtable;
00849 int hashsize;
00850 int valoffset;
00851 int idxoffset;
00852 int size[CV_MAX_DIM];
00853 }
00854 CvSparseMat;
00855
00856 #define CV_IS_SPARSE_MAT_HDR(mat) \
00857 ((mat) != NULL && \
00858 (((const CvSparseMat*)(mat))->type & CV_MAGIC_MASK) == CV_SPARSE_MAT_MAGIC_VAL)
00859
00860 #define CV_IS_SPARSE_MAT(mat) \
00861 CV_IS_SPARSE_MAT_HDR(mat)
00862
00863
00864
00865 typedef struct CvSparseNode
00866 {
00867 unsigned hashval;
00868 struct CvSparseNode* next;
00869 }
00870 CvSparseNode;
00871
00872 typedef struct CvSparseMatIterator
00873 {
00874 CvSparseMat* mat;
00875 CvSparseNode* node;
00876 int curidx;
00877 }
00878 CvSparseMatIterator;
00879
00880 #define CV_NODE_VAL(mat,node) ((void*)((uchar*)(node) + (mat)->valoffset))
00881 #define CV_NODE_IDX(mat,node) ((int*)((uchar*)(node) + (mat)->idxoffset))
00882
00883
00884
00885
00886
00887 typedef int CvHistType;
00888
00889 #define CV_HIST_MAGIC_VAL 0x42450000
00890 #define CV_HIST_UNIFORM_FLAG (1 << 10)
00891
00892
00893 #define CV_HIST_RANGES_FLAG (1 << 11)
00894
00895 #define CV_HIST_ARRAY 0
00896 #define CV_HIST_SPARSE 1
00897 #define CV_HIST_TREE CV_HIST_SPARSE
00898
00899
00900
00901 #define CV_HIST_UNIFORM 1
00902
00903 typedef struct CvHistogram
00904 {
00905 int type;
00906 CvArr* bins;
00907 float thresh[CV_MAX_DIM][2];
00908 float** thresh2;
00909 CvMatND mat;
00910 }
00911 CvHistogram;
00912
00913 #define CV_IS_HIST( hist ) \
00914 ((hist) != NULL && \
00915 (((CvHistogram*)(hist))->type & CV_MAGIC_MASK) == CV_HIST_MAGIC_VAL && \
00916 (hist)->bins != NULL)
00917
00918 #define CV_IS_UNIFORM_HIST( hist ) \
00919 (((hist)->type & CV_HIST_UNIFORM_FLAG) != 0)
00920
00921 #define CV_IS_SPARSE_HIST( hist ) \
00922 CV_IS_SPARSE_MAT((hist)->bins)
00923
00924 #define CV_HIST_HAS_RANGES( hist ) \
00925 (((hist)->type & CV_HIST_RANGES_FLAG) != 0)
00926
00927
00928
00929
00930
00931
00932
00933 typedef struct CvRect
00934 {
00935 int x;
00936 int y;
00937 int width;
00938 int height;
00939 }
00940 CvRect;
00941
00942 CV_INLINE CvRect cvRect( int x, int y, int width, int height )
00943 {
00944 CvRect r;
00945
00946 r.x = x;
00947 r.y = y;
00948 r.width = width;
00949 r.height = height;
00950
00951 return r;
00952 }
00953
00954
00955 CV_INLINE IplROI cvRectToROI( CvRect rect, int coi )
00956 {
00957 IplROI roi;
00958 roi.xOffset = rect.x;
00959 roi.yOffset = rect.y;
00960 roi.width = rect.width;
00961 roi.height = rect.height;
00962 roi.coi = coi;
00963
00964 return roi;
00965 }
00966
00967
00968 CV_INLINE CvRect cvROIToRect( IplROI roi )
00969 {
00970 return cvRect( roi.xOffset, roi.yOffset, roi.width, roi.height );
00971 }
00972
00973
00974
00975 #define CV_TERMCRIT_ITER 1
00976 #define CV_TERMCRIT_NUMBER CV_TERMCRIT_ITER
00977 #define CV_TERMCRIT_EPS 2
00978
00979 typedef struct CvTermCriteria
00980 {
00981 int type;
00982
00983
00984 int max_iter;
00985 double epsilon;
00986 }
00987 CvTermCriteria;
00988
00989 CV_INLINE CvTermCriteria cvTermCriteria( int type, int max_iter, double epsilon )
00990 {
00991 CvTermCriteria t;
00992
00993 t.type = type;
00994 t.max_iter = max_iter;
00995 t.epsilon = (float)epsilon;
00996
00997 return t;
00998 }
00999
01000
01001
01002
01003 typedef struct CvPoint
01004 {
01005 int x;
01006 int y;
01007 }
01008 CvPoint;
01009
01010
01011 CV_INLINE CvPoint cvPoint( int x, int y )
01012 {
01013 CvPoint p;
01014
01015 p.x = x;
01016 p.y = y;
01017
01018 return p;
01019 }
01020
01021
01022 typedef struct CvPoint2D32f
01023 {
01024 float x;
01025 float y;
01026 }
01027 CvPoint2D32f;
01028
01029
01030 CV_INLINE CvPoint2D32f cvPoint2D32f( double x, double y )
01031 {
01032 CvPoint2D32f p;
01033
01034 p.x = (float)x;
01035 p.y = (float)y;
01036
01037 return p;
01038 }
01039
01040
01041 CV_INLINE CvPoint2D32f cvPointTo32f( CvPoint point )
01042 {
01043 return cvPoint2D32f( (float)point.x, (float)point.y );
01044 }
01045
01046
01047 CV_INLINE CvPoint cvPointFrom32f( CvPoint2D32f point )
01048 {
01049 CvPoint ipt;
01050 ipt.x = cvRound(point.x);
01051 ipt.y = cvRound(point.y);
01052
01053 return ipt;
01054 }
01055
01056
01057 typedef struct CvPoint3D32f
01058 {
01059 float x;
01060 float y;
01061 float z;
01062 }
01063 CvPoint3D32f;
01064
01065
01066 CV_INLINE CvPoint3D32f cvPoint3D32f( double x, double y, double z )
01067 {
01068 CvPoint3D32f p;
01069
01070 p.x = (float)x;
01071 p.y = (float)y;
01072 p.z = (float)z;
01073
01074 return p;
01075 }
01076
01077
01078 typedef struct CvPoint2D64f
01079 {
01080 double x;
01081 double y;
01082 }
01083 CvPoint2D64f;
01084
01085
01086 CV_INLINE CvPoint2D64f cvPoint2D64f( double x, double y )
01087 {
01088 CvPoint2D64f p;
01089
01090 p.x = x;
01091 p.y = y;
01092
01093 return p;
01094 }
01095
01096
01097 typedef struct CvPoint3D64f
01098 {
01099 double x;
01100 double y;
01101 double z;
01102 }
01103 CvPoint3D64f;
01104
01105
01106 CV_INLINE CvPoint3D64f cvPoint3D64f( double x, double y, double z )
01107 {
01108 CvPoint3D64f p;
01109
01110 p.x = x;
01111 p.y = y;
01112 p.z = z;
01113
01114 return p;
01115 }
01116
01117
01118
01119
01120 typedef struct
01121 {
01122 int width;
01123 int height;
01124 }
01125 CvSize;
01126
01127 CV_INLINE CvSize cvSize( int width, int height )
01128 {
01129 CvSize s;
01130
01131 s.width = width;
01132 s.height = height;
01133
01134 return s;
01135 }
01136
01137 typedef struct CvSize2D32f
01138 {
01139 float width;
01140 float height;
01141 }
01142 CvSize2D32f;
01143
01144
01145 CV_INLINE CvSize2D32f cvSize2D32f( double width, double height )
01146 {
01147 CvSize2D32f s;
01148
01149 s.width = (float)width;
01150 s.height = (float)height;
01151
01152 return s;
01153 }
01154
01155 typedef struct CvBox2D
01156 {
01157 CvPoint2D32f center;
01158 CvSize2D32f size;
01159 float angle;
01160
01161 }
01162 CvBox2D;
01163
01164
01165
01166 typedef struct CvLineIterator
01167 {
01168
01169 uchar* ptr;
01170
01171
01172 int err;
01173 int plus_delta;
01174 int minus_delta;
01175 int plus_step;
01176 int minus_step;
01177 }
01178 CvLineIterator;
01179
01180
01181
01182
01183
01184 typedef struct CvSlice
01185 {
01186 int start_index, end_index;
01187 }
01188 CvSlice;
01189
01190 CV_INLINE CvSlice cvSlice( int start, int end )
01191 {
01192 CvSlice slice;
01193 slice.start_index = start;
01194 slice.end_index = end;
01195
01196 return slice;
01197 }
01198
01199 #define CV_WHOLE_SEQ_END_INDEX 0x3fffffff
01200 #define CV_WHOLE_SEQ cvSlice(0, CV_WHOLE_SEQ_END_INDEX)
01201
01202
01203
01204
01205 typedef struct CvScalar
01206 {
01207 double val[4];
01208 }
01209 CvScalar;
01210
01211 CV_INLINE CvScalar cvScalar( double val0, double val1 CV_DEFAULT(0),
01212 double val2 CV_DEFAULT(0), double val3 CV_DEFAULT(0))
01213 {
01214 CvScalar scalar;
01215 scalar.val[0] = val0; scalar.val[1] = val1;
01216 scalar.val[2] = val2; scalar.val[3] = val3;
01217 return scalar;
01218 }
01219
01220
01221 CV_INLINE CvScalar cvRealScalar( double val0 )
01222 {
01223 CvScalar scalar;
01224 scalar.val[0] = val0;
01225 scalar.val[1] = scalar.val[2] = scalar.val[3] = 0;
01226 return scalar;
01227 }
01228
01229 CV_INLINE CvScalar cvScalarAll( double val0123 )
01230 {
01231 CvScalar scalar;
01232 scalar.val[0] = val0123;
01233 scalar.val[1] = val0123;
01234 scalar.val[2] = val0123;
01235 scalar.val[3] = val0123;
01236 return scalar;
01237 }
01238
01239
01240
01241
01242
01243
01244
01245 typedef struct CvMemBlock
01246 {
01247 struct CvMemBlock* prev;
01248 struct CvMemBlock* next;
01249 }
01250 CvMemBlock;
01251
01252 #define CV_STORAGE_MAGIC_VAL 0x42890000
01253
01254 typedef struct CvMemStorage
01255 {
01256 int signature;
01257 CvMemBlock* bottom;
01258 CvMemBlock* top;
01259 struct CvMemStorage* parent;
01260 int block_size;
01261 int free_space;
01262 }
01263 CvMemStorage;
01264
01265 #define CV_IS_STORAGE(storage) \
01266 ((storage) != NULL && \
01267 (((CvMemStorage*)(storage))->signature & CV_MAGIC_MASK) == CV_STORAGE_MAGIC_VAL)
01268
01269
01270 typedef struct CvMemStoragePos
01271 {
01272 CvMemBlock* top;
01273 int free_space;
01274 }
01275 CvMemStoragePos;
01276
01277
01278
01279
01280 typedef struct CvSeqBlock
01281 {
01282 struct CvSeqBlock* prev;
01283 struct CvSeqBlock* next;
01284 int start_index;
01285
01286 int count;
01287 schar* data;
01288 }
01289 CvSeqBlock;
01290
01291
01292 #define CV_TREE_NODE_FIELDS(node_type) \
01293 int flags; \
01294 int header_size; \
01295 struct node_type* h_prev; \
01296 struct node_type* h_next; \
01297 struct node_type* v_prev; \
01298 struct node_type* v_next
01299
01300
01301
01302
01303
01304 #define CV_SEQUENCE_FIELDS() \
01305 CV_TREE_NODE_FIELDS(CvSeq); \
01306 int total; \
01307 int elem_size; \
01308 schar* block_max; \
01309 schar* ptr; \
01310 int delta_elems; \
01311 CvMemStorage* storage; \
01312 CvSeqBlock* free_blocks; \
01313 CvSeqBlock* first;
01314
01315 typedef struct CvSeq
01316 {
01317 CV_SEQUENCE_FIELDS()
01318 }
01319 CvSeq;
01320
01321 #define CV_TYPE_NAME_SEQ "opencv-sequence"
01322 #define CV_TYPE_NAME_SEQ_TREE "opencv-sequence-tree"
01323
01324
01325
01326
01327
01328
01329
01330
01331 #define CV_SET_ELEM_FIELDS(elem_type) \
01332 int flags; \
01333 struct elem_type* next_free;
01334
01335 typedef struct CvSetElem
01336 {
01337 CV_SET_ELEM_FIELDS(CvSetElem)
01338 }
01339 CvSetElem;
01340
01341 #define CV_SET_FIELDS() \
01342 CV_SEQUENCE_FIELDS() \
01343 CvSetElem* free_elems; \
01344 int active_count;
01345
01346 typedef struct CvSet
01347 {
01348 CV_SET_FIELDS()
01349 }
01350 CvSet;
01351
01352
01353 #define CV_SET_ELEM_IDX_MASK ((1 << 26) - 1)
01354 #define CV_SET_ELEM_FREE_FLAG (1 << (sizeof(int)*8-1))
01355
01356
01357 #define CV_IS_SET_ELEM( ptr ) (((CvSetElem*)(ptr))->flags >= 0)
01358
01359
01360
01361
01362
01363
01364
01365
01366
01367
01368
01369
01370
01371
01372
01373
01374
01375
01376
01377
01378
01379 #define CV_GRAPH_EDGE_FIELDS() \
01380 int flags; \
01381 float weight; \
01382 struct CvGraphEdge* next[2]; \
01383 struct CvGraphVtx* vtx[2];
01384
01385
01386 #define CV_GRAPH_VERTEX_FIELDS() \
01387 int flags; \
01388 struct CvGraphEdge* first;
01389
01390
01391 typedef struct CvGraphEdge
01392 {
01393 CV_GRAPH_EDGE_FIELDS()
01394 }
01395 CvGraphEdge;
01396
01397 typedef struct CvGraphVtx
01398 {
01399 CV_GRAPH_VERTEX_FIELDS()
01400 }
01401 CvGraphVtx;
01402
01403 typedef struct CvGraphVtx2D
01404 {
01405 CV_GRAPH_VERTEX_FIELDS()
01406 CvPoint2D32f* ptr;
01407 }
01408 CvGraphVtx2D;
01409
01410
01411
01412
01413
01414 #define CV_GRAPH_FIELDS() \
01415 CV_SET_FIELDS() \
01416 CvSet* edges;
01417
01418 typedef struct CvGraph
01419 {
01420 CV_GRAPH_FIELDS()
01421 }
01422 CvGraph;
01423
01424 #define CV_TYPE_NAME_GRAPH "opencv-graph"
01425
01426
01427
01428 typedef struct CvChain
01429 {
01430 CV_SEQUENCE_FIELDS()
01431 CvPoint origin;
01432 }
01433 CvChain;
01434
01435 #define CV_CONTOUR_FIELDS() \
01436 CV_SEQUENCE_FIELDS() \
01437 CvRect rect; \
01438 int color; \
01439 int reserved[3];
01440
01441 typedef struct CvContour
01442 {
01443 CV_CONTOUR_FIELDS()
01444 }
01445 CvContour;
01446
01447 typedef CvContour CvPoint2DSeq;
01448
01449
01450
01451
01452
01453 #define CV_SEQ_MAGIC_VAL 0x42990000
01454
01455 #define CV_IS_SEQ(seq) \
01456 ((seq) != NULL && (((CvSeq*)(seq))->flags & CV_MAGIC_MASK) == CV_SEQ_MAGIC_VAL)
01457
01458 #define CV_SET_MAGIC_VAL 0x42980000
01459 #define CV_IS_SET(set) \
01460 ((set) != NULL && (((CvSeq*)(set))->flags & CV_MAGIC_MASK) == CV_SET_MAGIC_VAL)
01461
01462 #define CV_SEQ_ELTYPE_BITS 12
01463 #define CV_SEQ_ELTYPE_MASK ((1 << CV_SEQ_ELTYPE_BITS) - 1)
01464
01465 #define CV_SEQ_ELTYPE_POINT CV_32SC2
01466 #define CV_SEQ_ELTYPE_CODE CV_8UC1
01467 #define CV_SEQ_ELTYPE_GENERIC 0
01468 #define CV_SEQ_ELTYPE_PTR CV_USRTYPE1
01469 #define CV_SEQ_ELTYPE_PPOINT CV_SEQ_ELTYPE_PTR
01470 #define CV_SEQ_ELTYPE_INDEX CV_32SC1
01471 #define CV_SEQ_ELTYPE_GRAPH_EDGE 0
01472 #define CV_SEQ_ELTYPE_GRAPH_VERTEX 0
01473 #define CV_SEQ_ELTYPE_TRIAN_ATR 0
01474 #define CV_SEQ_ELTYPE_CONNECTED_COMP 0
01475 #define CV_SEQ_ELTYPE_POINT3D CV_32FC3
01476
01477 #define CV_SEQ_KIND_BITS 2
01478 #define CV_SEQ_KIND_MASK (((1 << CV_SEQ_KIND_BITS) - 1)<<CV_SEQ_ELTYPE_BITS)
01479
01480
01481 #define CV_SEQ_KIND_GENERIC (0 << CV_SEQ_ELTYPE_BITS)
01482 #define CV_SEQ_KIND_CURVE (1 << CV_SEQ_ELTYPE_BITS)
01483 #define CV_SEQ_KIND_BIN_TREE (2 << CV_SEQ_ELTYPE_BITS)
01484
01485
01486 #define CV_SEQ_KIND_GRAPH (1 << CV_SEQ_ELTYPE_BITS)
01487 #define CV_SEQ_KIND_SUBDIV2D (2 << CV_SEQ_ELTYPE_BITS)
01488
01489 #define CV_SEQ_FLAG_SHIFT (CV_SEQ_KIND_BITS + CV_SEQ_ELTYPE_BITS)
01490
01491
01492 #define CV_SEQ_FLAG_CLOSED (1 << CV_SEQ_FLAG_SHIFT)
01493 #define CV_SEQ_FLAG_SIMPLE (0 << CV_SEQ_FLAG_SHIFT)
01494 #define CV_SEQ_FLAG_CONVEX (0 << CV_SEQ_FLAG_SHIFT)
01495 #define CV_SEQ_FLAG_HOLE (2 << CV_SEQ_FLAG_SHIFT)
01496
01497
01498 #define CV_GRAPH_FLAG_ORIENTED (1 << CV_SEQ_FLAG_SHIFT)
01499
01500 #define CV_GRAPH CV_SEQ_KIND_GRAPH
01501 #define CV_ORIENTED_GRAPH (CV_SEQ_KIND_GRAPH|CV_GRAPH_FLAG_ORIENTED)
01502
01503
01504 #define CV_SEQ_POINT_SET (CV_SEQ_KIND_GENERIC| CV_SEQ_ELTYPE_POINT)
01505 #define CV_SEQ_POINT3D_SET (CV_SEQ_KIND_GENERIC| CV_SEQ_ELTYPE_POINT3D)
01506 #define CV_SEQ_POLYLINE (CV_SEQ_KIND_CURVE | CV_SEQ_ELTYPE_POINT)
01507 #define CV_SEQ_POLYGON (CV_SEQ_FLAG_CLOSED | CV_SEQ_POLYLINE )
01508 #define CV_SEQ_CONTOUR CV_SEQ_POLYGON
01509 #define CV_SEQ_SIMPLE_POLYGON (CV_SEQ_FLAG_SIMPLE | CV_SEQ_POLYGON )
01510
01511
01512 #define CV_SEQ_CHAIN (CV_SEQ_KIND_CURVE | CV_SEQ_ELTYPE_CODE)
01513 #define CV_SEQ_CHAIN_CONTOUR (CV_SEQ_FLAG_CLOSED | CV_SEQ_CHAIN)
01514
01515
01516 #define CV_SEQ_POLYGON_TREE (CV_SEQ_KIND_BIN_TREE | CV_SEQ_ELTYPE_TRIAN_ATR)
01517
01518
01519 #define CV_SEQ_CONNECTED_COMP (CV_SEQ_KIND_GENERIC | CV_SEQ_ELTYPE_CONNECTED_COMP)
01520
01521
01522 #define CV_SEQ_INDEX (CV_SEQ_KIND_GENERIC | CV_SEQ_ELTYPE_INDEX)
01523
01524 #define CV_SEQ_ELTYPE( seq ) ((seq)->flags & CV_SEQ_ELTYPE_MASK)
01525 #define CV_SEQ_KIND( seq ) ((seq)->flags & CV_SEQ_KIND_MASK )
01526
01527
01528 #define CV_IS_SEQ_INDEX( seq ) ((CV_SEQ_ELTYPE(seq) == CV_SEQ_ELTYPE_INDEX) && \
01529 (CV_SEQ_KIND(seq) == CV_SEQ_KIND_GENERIC))
01530
01531 #define CV_IS_SEQ_CURVE( seq ) (CV_SEQ_KIND(seq) == CV_SEQ_KIND_CURVE)
01532 #define CV_IS_SEQ_CLOSED( seq ) (((seq)->flags & CV_SEQ_FLAG_CLOSED) != 0)
01533 #define CV_IS_SEQ_CONVEX( seq ) 0
01534 #define CV_IS_SEQ_HOLE( seq ) (((seq)->flags & CV_SEQ_FLAG_HOLE) != 0)
01535 #define CV_IS_SEQ_SIMPLE( seq ) 1
01536
01537
01538 #define CV_IS_SEQ_POINT_SET( seq ) \
01539 ((CV_SEQ_ELTYPE(seq) == CV_32SC2 || CV_SEQ_ELTYPE(seq) == CV_32FC2))
01540
01541 #define CV_IS_SEQ_POINT_SUBSET( seq ) \
01542 (CV_IS_SEQ_INDEX( seq ) || CV_SEQ_ELTYPE(seq) == CV_SEQ_ELTYPE_PPOINT)
01543
01544 #define CV_IS_SEQ_POLYLINE( seq ) \
01545 (CV_SEQ_KIND(seq) == CV_SEQ_KIND_CURVE && CV_IS_SEQ_POINT_SET(seq))
01546
01547 #define CV_IS_SEQ_POLYGON( seq ) \
01548 (CV_IS_SEQ_POLYLINE(seq) && CV_IS_SEQ_CLOSED(seq))
01549
01550 #define CV_IS_SEQ_CHAIN( seq ) \
01551 (CV_SEQ_KIND(seq) == CV_SEQ_KIND_CURVE && (seq)->elem_size == 1)
01552
01553 #define CV_IS_SEQ_CONTOUR( seq ) \
01554 (CV_IS_SEQ_CLOSED(seq) && (CV_IS_SEQ_POLYLINE(seq) || CV_IS_SEQ_CHAIN(seq)))
01555
01556 #define CV_IS_SEQ_CHAIN_CONTOUR( seq ) \
01557 (CV_IS_SEQ_CHAIN( seq ) && CV_IS_SEQ_CLOSED( seq ))
01558
01559 #define CV_IS_SEQ_POLYGON_TREE( seq ) \
01560 (CV_SEQ_ELTYPE (seq) == CV_SEQ_ELTYPE_TRIAN_ATR && \
01561 CV_SEQ_KIND( seq ) == CV_SEQ_KIND_BIN_TREE )
01562
01563 #define CV_IS_GRAPH( seq ) \
01564 (CV_IS_SET(seq) && CV_SEQ_KIND((CvSet*)(seq)) == CV_SEQ_KIND_GRAPH)
01565
01566 #define CV_IS_GRAPH_ORIENTED( seq ) \
01567 (((seq)->flags & CV_GRAPH_FLAG_ORIENTED) != 0)
01568
01569 #define CV_IS_SUBDIV2D( seq ) \
01570 (CV_IS_SET(seq) && CV_SEQ_KIND((CvSet*)(seq)) == CV_SEQ_KIND_SUBDIV2D)
01571
01572
01573
01574
01575
01576 #define CV_SEQ_WRITER_FIELDS() \
01577 int header_size; \
01578 CvSeq* seq; \
01579 CvSeqBlock* block; \
01580 schar* ptr; \
01581 schar* block_min; \
01582 schar* block_max;
01583
01584 typedef struct CvSeqWriter
01585 {
01586 CV_SEQ_WRITER_FIELDS()
01587 }
01588 CvSeqWriter;
01589
01590
01591 #define CV_SEQ_READER_FIELDS() \
01592 int header_size; \
01593 CvSeq* seq; \
01594 CvSeqBlock* block; \
01595 schar* ptr; \
01596 schar* block_min; \
01597 schar* block_max; \
01598 int delta_index; \
01599 schar* prev_elem;
01600
01601
01602 typedef struct CvSeqReader
01603 {
01604 CV_SEQ_READER_FIELDS()
01605 }
01606 CvSeqReader;
01607
01608
01609
01610
01611
01612 #define CV_SEQ_ELEM( seq, elem_type, index ) \
01613 \
01614 ( assert(sizeof((seq)->first[0]) == sizeof(CvSeqBlock) && \
01615 (seq)->elem_size == sizeof(elem_type)), \
01616 (elem_type*)((seq)->first && (unsigned)index < \
01617 (unsigned)((seq)->first->count) ? \
01618 (seq)->first->data + (index) * sizeof(elem_type) : \
01619 cvGetSeqElem( (CvSeq*)(seq), (index) )))
01620 #define CV_GET_SEQ_ELEM( elem_type, seq, index ) CV_SEQ_ELEM( (seq), elem_type, (index) )
01621
01622
01623 #define CV_WRITE_SEQ_ELEM_VAR( elem_ptr, writer ) \
01624 { \
01625 if( (writer).ptr >= (writer).block_max ) \
01626 { \
01627 cvCreateSeqBlock( &writer); \
01628 } \
01629 memcpy((writer).ptr, elem_ptr, (writer).seq->elem_size);\
01630 (writer).ptr += (writer).seq->elem_size; \
01631 }
01632
01633 #define CV_WRITE_SEQ_ELEM( elem, writer ) \
01634 { \
01635 assert( (writer).seq->elem_size == sizeof(elem)); \
01636 if( (writer).ptr >= (writer).block_max ) \
01637 { \
01638 cvCreateSeqBlock( &writer); \
01639 } \
01640 assert( (writer).ptr <= (writer).block_max - sizeof(elem));\
01641 memcpy((writer).ptr, &(elem), sizeof(elem)); \
01642 (writer).ptr += sizeof(elem); \
01643 }
01644
01645
01646
01647 #define CV_NEXT_SEQ_ELEM( elem_size, reader ) \
01648 { \
01649 if( ((reader).ptr += (elem_size)) >= (reader).block_max ) \
01650 { \
01651 cvChangeSeqBlock( &(reader), 1 ); \
01652 } \
01653 }
01654
01655
01656
01657 #define CV_PREV_SEQ_ELEM( elem_size, reader ) \
01658 { \
01659 if( ((reader).ptr -= (elem_size)) < (reader).block_min ) \
01660 { \
01661 cvChangeSeqBlock( &(reader), -1 ); \
01662 } \
01663 }
01664
01665
01666 #define CV_READ_SEQ_ELEM( elem, reader ) \
01667 { \
01668 assert( (reader).seq->elem_size == sizeof(elem)); \
01669 memcpy( &(elem), (reader).ptr, sizeof((elem))); \
01670 CV_NEXT_SEQ_ELEM( sizeof(elem), reader ) \
01671 }
01672
01673
01674 #define CV_REV_READ_SEQ_ELEM( elem, reader ) \
01675 { \
01676 assert( (reader).seq->elem_size == sizeof(elem)); \
01677 memcpy(&(elem), (reader).ptr, sizeof((elem))); \
01678 CV_PREV_SEQ_ELEM( sizeof(elem), reader ) \
01679 }
01680
01681
01682 #define CV_READ_CHAIN_POINT( _pt, reader ) \
01683 { \
01684 (_pt) = (reader).pt; \
01685 if( (reader).ptr ) \
01686 { \
01687 CV_READ_SEQ_ELEM( (reader).code, (reader)); \
01688 assert( ((reader).code & ~7) == 0 ); \
01689 (reader).pt.x += (reader).deltas[(int)(reader).code][0]; \
01690 (reader).pt.y += (reader).deltas[(int)(reader).code][1]; \
01691 } \
01692 }
01693
01694 #define CV_CURRENT_POINT( reader ) (*((CvPoint*)((reader).ptr)))
01695 #define CV_PREV_POINT( reader ) (*((CvPoint*)((reader).prev_elem)))
01696
01697 #define CV_READ_EDGE( pt1, pt2, reader ) \
01698 { \
01699 assert( sizeof(pt1) == sizeof(CvPoint) && \
01700 sizeof(pt2) == sizeof(CvPoint) && \
01701 reader.seq->elem_size == sizeof(CvPoint)); \
01702 (pt1) = CV_PREV_POINT( reader ); \
01703 (pt2) = CV_CURRENT_POINT( reader ); \
01704 (reader).prev_elem = (reader).ptr; \
01705 CV_NEXT_SEQ_ELEM( sizeof(CvPoint), (reader)); \
01706 }
01707
01708
01709
01710
01711 #define CV_NEXT_GRAPH_EDGE( edge, vertex ) \
01712 (assert((edge)->vtx[0] == (vertex) || (edge)->vtx[1] == (vertex)), \
01713 (edge)->next[(edge)->vtx[1] == (vertex)])
01714
01715
01716
01717
01718
01719
01720
01721
01722 typedef struct CvFileStorage CvFileStorage;
01723
01724
01725 #define CV_STORAGE_READ 0
01726 #define CV_STORAGE_WRITE 1
01727 #define CV_STORAGE_WRITE_TEXT CV_STORAGE_WRITE
01728 #define CV_STORAGE_WRITE_BINARY CV_STORAGE_WRITE
01729 #define CV_STORAGE_APPEND 2
01730
01731
01732 typedef struct CvAttrList
01733 {
01734 const char** attr;
01735 struct CvAttrList* next;
01736 }
01737 CvAttrList;
01738
01739 CV_INLINE CvAttrList cvAttrList( const char** attr CV_DEFAULT(NULL),
01740 CvAttrList* next CV_DEFAULT(NULL) )
01741 {
01742 CvAttrList l;
01743 l.attr = attr;
01744 l.next = next;
01745
01746 return l;
01747 }
01748
01749 struct CvTypeInfo;
01750
01751 #define CV_NODE_NONE 0
01752 #define CV_NODE_INT 1
01753 #define CV_NODE_INTEGER CV_NODE_INT
01754 #define CV_NODE_REAL 2
01755 #define CV_NODE_FLOAT CV_NODE_REAL
01756 #define CV_NODE_STR 3
01757 #define CV_NODE_STRING CV_NODE_STR
01758 #define CV_NODE_REF 4
01759 #define CV_NODE_SEQ 5
01760 #define CV_NODE_MAP 6
01761 #define CV_NODE_TYPE_MASK 7
01762
01763 #define CV_NODE_TYPE(flags) ((flags) & CV_NODE_TYPE_MASK)
01764
01765
01766 #define CV_NODE_FLOW 8
01767 #define CV_NODE_USER 16
01768 #define CV_NODE_EMPTY 32
01769 #define CV_NODE_NAMED 64
01770
01771 #define CV_NODE_IS_INT(flags) (CV_NODE_TYPE(flags) == CV_NODE_INT)
01772 #define CV_NODE_IS_REAL(flags) (CV_NODE_TYPE(flags) == CV_NODE_REAL)
01773 #define CV_NODE_IS_STRING(flags) (CV_NODE_TYPE(flags) == CV_NODE_STRING)
01774 #define CV_NODE_IS_SEQ(flags) (CV_NODE_TYPE(flags) == CV_NODE_SEQ)
01775 #define CV_NODE_IS_MAP(flags) (CV_NODE_TYPE(flags) == CV_NODE_MAP)
01776 #define CV_NODE_IS_COLLECTION(flags) (CV_NODE_TYPE(flags) >= CV_NODE_SEQ)
01777 #define CV_NODE_IS_FLOW(flags) (((flags) & CV_NODE_FLOW) != 0)
01778 #define CV_NODE_IS_EMPTY(flags) (((flags) & CV_NODE_EMPTY) != 0)
01779 #define CV_NODE_IS_USER(flags) (((flags) & CV_NODE_USER) != 0)
01780 #define CV_NODE_HAS_NAME(flags) (((flags) & CV_NODE_NAMED) != 0)
01781
01782 #define CV_NODE_SEQ_SIMPLE 256
01783 #define CV_NODE_SEQ_IS_SIMPLE(seq) (((seq)->flags & CV_NODE_SEQ_SIMPLE) != 0)
01784
01785 typedef struct CvString
01786 {
01787 int len;
01788 char* ptr;
01789 }
01790 CvString;
01791
01792
01793
01794 typedef struct CvStringHashNode
01795 {
01796 unsigned hashval;
01797 CvString str;
01798 struct CvStringHashNode* next;
01799 }
01800 CvStringHashNode;
01801
01802 typedef struct CvGenericHash CvFileNodeHash;
01803
01804
01805 typedef struct CvFileNode
01806 {
01807 int tag;
01808 struct CvTypeInfo* info;
01809
01810 union
01811 {
01812 double f;
01813 int i;
01814 CvString str;
01815 CvSeq* seq;
01816 CvFileNodeHash* map;
01817 } data;
01818 }
01819 CvFileNode;
01820
01821 #ifdef __cplusplus
01822 extern "C" {
01823 #endif
01824 typedef int (CV_CDECL *CvIsInstanceFunc)( const void* struct_ptr );
01825 typedef void (CV_CDECL *CvReleaseFunc)( void** struct_dblptr );
01826 typedef void* (CV_CDECL *CvReadFunc)( CvFileStorage* storage, CvFileNode* node );
01827 typedef void (CV_CDECL *CvWriteFunc)( CvFileStorage* storage, const char* name,
01828 const void* struct_ptr, CvAttrList attributes );
01829 typedef void* (CV_CDECL *CvCloneFunc)( const void* struct_ptr );
01830 #ifdef __cplusplus
01831 }
01832 #endif
01833
01834 typedef struct CvTypeInfo
01835 {
01836 int flags;
01837 int header_size;
01838 struct CvTypeInfo* prev;
01839 struct CvTypeInfo* next;
01840 const char* type_name;
01841 CvIsInstanceFunc is_instance;
01842 CvReleaseFunc release;
01843 CvReadFunc read;
01844 CvWriteFunc write;
01845 CvCloneFunc clone;
01846 }
01847 CvTypeInfo;
01848
01849
01850
01851
01852 typedef struct CvPluginFuncInfo
01853 {
01854 void** func_addr;
01855 void* default_func_addr;
01856 const char* func_names;
01857 int search_modules;
01858 int loaded_from;
01859 }
01860 CvPluginFuncInfo;
01861
01862 typedef struct CvModuleInfo
01863 {
01864 struct CvModuleInfo* next;
01865 const char* name;
01866 const char* version;
01867 CvPluginFuncInfo* func_tab;
01868 }
01869 CvModuleInfo;
01870
01871 enum { CV_PARAM_TYPE_INT=0, CV_PARAM_TYPE_REAL=1, CV_PARAM_TYPE_STRING=2, CV_PARAM_TYPE_MAT=3 };
01872
01873 #endif
01874
01875