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