1 /*M/////////////////////////////////////////////////////////////////////////////////////// 2 // 3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 4 // 5 // By downloading, copying, installing or using the software you agree to this license. 6 // If you do not agree to this license, do not download, install, 7 // copy or use the software. 8 // 9 // 10 // License Agreement 11 // For Open Source Computer Vision Library 12 // 13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. 14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved. 15 // Copyright (C) 2013, OpenCV Foundation, all rights reserved. 16 // Third party copyrights are property of their respective owners. 17 // 18 // Redistribution and use in source and binary forms, with or without modification, 19 // are permitted provided that the following conditions are met: 20 // 21 // * Redistribution's of source code must retain the above copyright notice, 22 // this list of conditions and the following disclaimer. 23 // 24 // * Redistribution's in binary form must reproduce the above copyright notice, 25 // this list of conditions and the following disclaimer in the documentation 26 // and/or other materials provided with the distribution. 27 // 28 // * The name of the copyright holders may not be used to endorse or promote products 29 // derived from this software without specific prior written permission. 30 // 31 // This software is provided by the copyright holders and contributors "as is" and 32 // any express or implied warranties, including, but not limited to, the implied 33 // warranties of merchantability and fitness for a particular purpose are disclaimed. 34 // In no event shall the Intel Corporation or contributors be liable for any direct, 35 // indirect, incidental, special, exemplary, or consequential damages 36 // (including, but not limited to, procurement of substitute goods or services; 37 // loss of use, data, or profits; or business interruption) however caused 38 // and on any theory of liability, whether in contract, strict liability, 39 // or tort (including negligence or otherwise) arising in any way out of 40 // the use of this software, even if advised of the possibility of such damage. 41 // 42 //M*/ 43 44 #ifndef __OPENCV_CORE_TYPES_H__ 45 #define __OPENCV_CORE_TYPES_H__ 46 47 #ifdef HAVE_IPL 48 # ifndef __IPL_H__ 49 # if defined WIN32 || defined _WIN32 50 # include <ipl.h> 51 # else 52 # include <ipl/ipl.h> 53 # endif 54 # endif 55 #elif defined __IPL_H__ 56 # define HAVE_IPL 57 #endif 58 59 #include "opencv2/core/cvdef.h" 60 61 #ifndef SKIP_INCLUDES 62 #include <assert.h> 63 #include <stdlib.h> 64 #include <string.h> 65 #include <float.h> 66 #endif // SKIP_INCLUDES 67 68 #if defined WIN32 || defined _WIN32 69 # define CV_CDECL __cdecl 70 # define CV_STDCALL __stdcall 71 #else 72 # define CV_CDECL 73 # define CV_STDCALL 74 #endif 75 76 #ifndef CV_DEFAULT 77 # ifdef __cplusplus 78 # define CV_DEFAULT(val) = val 79 # else 80 # define CV_DEFAULT(val) 81 # endif 82 #endif 83 84 #ifndef CV_EXTERN_C_FUNCPTR 85 # ifdef __cplusplus 86 # define CV_EXTERN_C_FUNCPTR(x) extern "C" { typedef x; } 87 # else 88 # define CV_EXTERN_C_FUNCPTR(x) typedef x 89 # endif 90 #endif 91 92 #ifndef CVAPI 93 # define CVAPI(rettype) CV_EXTERN_C CV_EXPORTS rettype CV_CDECL 94 #endif 95 96 #ifndef CV_IMPL 97 # define CV_IMPL CV_EXTERN_C 98 #endif 99 100 #ifdef __cplusplus 101 # include "opencv2/core.hpp" 102 #endif 103 104 /** @addtogroup core_c 105 @{ 106 */ 107 108 /** @brief This is the "metatype" used *only* as a function parameter. 109 110 It denotes that the function accepts arrays of multiple types, such as IplImage*, CvMat* or even 111 CvSeq* sometimes. The particular array type is determined at runtime by analyzing the first 4 112 bytes of the header. In C++ interface the role of CvArr is played by InputArray and OutputArray. 113 */ 114 typedef void CvArr; 115 116 typedef int CVStatus; 117 118 /** @see cv::Error::Code */ 119 enum { 120 CV_StsOk= 0, /**< everything is ok */ 121 CV_StsBackTrace= -1, /**< pseudo error for back trace */ 122 CV_StsError= -2, /**< unknown /unspecified error */ 123 CV_StsInternal= -3, /**< internal error (bad state) */ 124 CV_StsNoMem= -4, /**< insufficient memory */ 125 CV_StsBadArg= -5, /**< function arg/param is bad */ 126 CV_StsBadFunc= -6, /**< unsupported function */ 127 CV_StsNoConv= -7, /**< iter. didn't converge */ 128 CV_StsAutoTrace= -8, /**< tracing */ 129 CV_HeaderIsNull= -9, /**< image header is NULL */ 130 CV_BadImageSize= -10, /**< image size is invalid */ 131 CV_BadOffset= -11, /**< offset is invalid */ 132 CV_BadDataPtr= -12, /**/ 133 CV_BadStep= -13, /**/ 134 CV_BadModelOrChSeq= -14, /**/ 135 CV_BadNumChannels= -15, /**/ 136 CV_BadNumChannel1U= -16, /**/ 137 CV_BadDepth= -17, /**/ 138 CV_BadAlphaChannel= -18, /**/ 139 CV_BadOrder= -19, /**/ 140 CV_BadOrigin= -20, /**/ 141 CV_BadAlign= -21, /**/ 142 CV_BadCallBack= -22, /**/ 143 CV_BadTileSize= -23, /**/ 144 CV_BadCOI= -24, /**/ 145 CV_BadROISize= -25, /**/ 146 CV_MaskIsTiled= -26, /**/ 147 CV_StsNullPtr= -27, /**< null pointer */ 148 CV_StsVecLengthErr= -28, /**< incorrect vector length */ 149 CV_StsFilterStructContentErr= -29, /**< incorr. filter structure content */ 150 CV_StsKernelStructContentErr= -30, /**< incorr. transform kernel content */ 151 CV_StsFilterOffsetErr= -31, /**< incorrect filter offset value */ 152 CV_StsBadSize= -201, /**< the input/output structure size is incorrect */ 153 CV_StsDivByZero= -202, /**< division by zero */ 154 CV_StsInplaceNotSupported= -203, /**< in-place operation is not supported */ 155 CV_StsObjectNotFound= -204, /**< request can't be completed */ 156 CV_StsUnmatchedFormats= -205, /**< formats of input/output arrays differ */ 157 CV_StsBadFlag= -206, /**< flag is wrong or not supported */ 158 CV_StsBadPoint= -207, /**< bad CvPoint */ 159 CV_StsBadMask= -208, /**< bad format of mask (neither 8uC1 nor 8sC1)*/ 160 CV_StsUnmatchedSizes= -209, /**< sizes of input/output structures do not match */ 161 CV_StsUnsupportedFormat= -210, /**< the data format/type is not supported by the function*/ 162 CV_StsOutOfRange= -211, /**< some of parameters are out of range */ 163 CV_StsParseError= -212, /**< invalid syntax/structure of the parsed file */ 164 CV_StsNotImplemented= -213, /**< the requested function/feature is not implemented */ 165 CV_StsBadMemBlock= -214, /**< an allocated block has been corrupted */ 166 CV_StsAssert= -215, /**< assertion failed */ 167 CV_GpuNotSupported= -216, 168 CV_GpuApiCallError= -217, 169 CV_OpenGlNotSupported= -218, 170 CV_OpenGlApiCallError= -219, 171 CV_OpenCLApiCallError= -220, 172 CV_OpenCLDoubleNotSupported= -221, 173 CV_OpenCLInitError= -222, 174 CV_OpenCLNoAMDBlasFft= -223 175 }; 176 177 /****************************************************************************************\ 178 * Common macros and inline functions * 179 \****************************************************************************************/ 180 181 #define CV_SWAP(a,b,t) ((t) = (a), (a) = (b), (b) = (t)) 182 183 /** min & max without jumps */ 184 #define CV_IMIN(a, b) ((a) ^ (((a)^(b)) & (((a) < (b)) - 1))) 185 186 #define CV_IMAX(a, b) ((a) ^ (((a)^(b)) & (((a) > (b)) - 1))) 187 188 /** absolute value without jumps */ 189 #ifndef __cplusplus 190 # define CV_IABS(a) (((a) ^ ((a) < 0 ? -1 : 0)) - ((a) < 0 ? -1 : 0)) 191 #else 192 # define CV_IABS(a) abs(a) 193 #endif 194 #define CV_CMP(a,b) (((a) > (b)) - ((a) < (b))) 195 #define CV_SIGN(a) CV_CMP((a),0) 196 197 #define cvInvSqrt(value) ((float)(1./sqrt(value))) 198 #define cvSqrt(value) ((float)sqrt(value)) 199 200 201 /*************** Random number generation *******************/ 202 203 typedef uint64 CvRNG; 204 205 #define CV_RNG_COEFF 4164903690U 206 207 /** @brief Initializes a random number generator state. 208 209 The function initializes a random number generator and returns the state. The pointer to the state 210 can be then passed to the cvRandInt, cvRandReal and cvRandArr functions. In the current 211 implementation a multiply-with-carry generator is used. 212 @param seed 64-bit value used to initiate a random sequence 213 @sa the C++ class RNG replaced CvRNG. 214 */ 215 CV_INLINE CvRNG cvRNG( int64 seed CV_DEFAULT(-1)) 216 { 217 CvRNG rng = seed ? (uint64)seed : (uint64)(int64)-1; 218 return rng; 219 } 220 221 /** @brief Returns a 32-bit unsigned integer and updates RNG. 222 223 The function returns a uniformly-distributed random 32-bit unsigned integer and updates the RNG 224 state. It is similar to the rand() function from the C runtime library, except that OpenCV functions 225 always generates a 32-bit random number, regardless of the platform. 226 @param rng CvRNG state initialized by cvRNG. 227 */ 228 CV_INLINE unsigned cvRandInt( CvRNG* rng ) 229 { 230 uint64 temp = *rng; 231 temp = (uint64)(unsigned)temp*CV_RNG_COEFF + (temp >> 32); 232 *rng = temp; 233 return (unsigned)temp; 234 } 235 236 /** @brief Returns a floating-point random number and updates RNG. 237 238 The function returns a uniformly-distributed random floating-point number between 0 and 1 (1 is not 239 included). 240 @param rng RNG state initialized by cvRNG 241 */ 242 CV_INLINE double cvRandReal( CvRNG* rng ) 243 { 244 return cvRandInt(rng)*2.3283064365386962890625e-10 /* 2^-32 */; 245 } 246 247 /****************************************************************************************\ 248 * Image type (IplImage) * 249 \****************************************************************************************/ 250 251 #ifndef HAVE_IPL 252 253 /* 254 * The following definitions (until #endif) 255 * is an extract from IPL headers. 256 * Copyright (c) 1995 Intel Corporation. 257 */ 258 #define IPL_DEPTH_SIGN 0x80000000 259 260 #define IPL_DEPTH_1U 1 261 #define IPL_DEPTH_8U 8 262 #define IPL_DEPTH_16U 16 263 #define IPL_DEPTH_32F 32 264 265 #define IPL_DEPTH_8S (IPL_DEPTH_SIGN| 8) 266 #define IPL_DEPTH_16S (IPL_DEPTH_SIGN|16) 267 #define IPL_DEPTH_32S (IPL_DEPTH_SIGN|32) 268 269 #define IPL_DATA_ORDER_PIXEL 0 270 #define IPL_DATA_ORDER_PLANE 1 271 272 #define IPL_ORIGIN_TL 0 273 #define IPL_ORIGIN_BL 1 274 275 #define IPL_ALIGN_4BYTES 4 276 #define IPL_ALIGN_8BYTES 8 277 #define IPL_ALIGN_16BYTES 16 278 #define IPL_ALIGN_32BYTES 32 279 280 #define IPL_ALIGN_DWORD IPL_ALIGN_4BYTES 281 #define IPL_ALIGN_QWORD IPL_ALIGN_8BYTES 282 283 #define IPL_BORDER_CONSTANT 0 284 #define IPL_BORDER_REPLICATE 1 285 #define IPL_BORDER_REFLECT 2 286 #define IPL_BORDER_WRAP 3 287 288 /** The IplImage is taken from the Intel Image Processing Library, in which the format is native. OpenCV 289 only supports a subset of possible IplImage formats, as outlined in the parameter list above. 290 291 In addition to the above restrictions, OpenCV handles ROIs differently. OpenCV functions require 292 that the image size or ROI size of all source and destination images match exactly. On the other 293 hand, the Intel Image Processing Library processes the area of intersection between the source and 294 destination images (or ROIs), allowing them to vary independently. 295 */ 296 typedef struct 297 #ifdef __cplusplus 298 CV_EXPORTS 299 #endif 300 _IplImage 301 { 302 int nSize; /**< sizeof(IplImage) */ 303 int ID; /**< version (=0)*/ 304 int nChannels; /**< Most of OpenCV functions support 1,2,3 or 4 channels */ 305 int alphaChannel; /**< Ignored by OpenCV */ 306 int depth; /**< Pixel depth in bits: IPL_DEPTH_8U, IPL_DEPTH_8S, IPL_DEPTH_16S, 307 IPL_DEPTH_32S, IPL_DEPTH_32F and IPL_DEPTH_64F are supported. */ 308 char colorModel[4]; /**< Ignored by OpenCV */ 309 char channelSeq[4]; /**< ditto */ 310 int dataOrder; /**< 0 - interleaved color channels, 1 - separate color channels. 311 cvCreateImage can only create interleaved images */ 312 int origin; /**< 0 - top-left origin, 313 1 - bottom-left origin (Windows bitmaps style). */ 314 int align; /**< Alignment of image rows (4 or 8). 315 OpenCV ignores it and uses widthStep instead. */ 316 int width; /**< Image width in pixels. */ 317 int height; /**< Image height in pixels. */ 318 struct _IplROI *roi; /**< Image ROI. If NULL, the whole image is selected. */ 319 struct _IplImage *maskROI; /**< Must be NULL. */ 320 void *imageId; /**< " " */ 321 struct _IplTileInfo *tileInfo; /**< " " */ 322 int imageSize; /**< Image data size in bytes 323 (==image->height*image->widthStep 324 in case of interleaved data)*/ 325 char *imageData; /**< Pointer to aligned image data. */ 326 int widthStep; /**< Size of aligned image row in bytes. */ 327 int BorderMode[4]; /**< Ignored by OpenCV. */ 328 int BorderConst[4]; /**< Ditto. */ 329 char *imageDataOrigin; /**< Pointer to very origin of image data 330 (not necessarily aligned) - 331 needed for correct deallocation */ 332 333 #ifdef __cplusplus 334 _IplImage() {} 335 _IplImage(const cv::Mat& m); 336 #endif 337 } 338 IplImage; 339 340 typedef struct _IplTileInfo IplTileInfo; 341 342 typedef struct _IplROI 343 { 344 int coi; /**< 0 - no COI (all channels are selected), 1 - 0th channel is selected ...*/ 345 int xOffset; 346 int yOffset; 347 int width; 348 int height; 349 } 350 IplROI; 351 352 typedef struct _IplConvKernel 353 { 354 int nCols; 355 int nRows; 356 int anchorX; 357 int anchorY; 358 int *values; 359 int nShiftR; 360 } 361 IplConvKernel; 362 363 typedef struct _IplConvKernelFP 364 { 365 int nCols; 366 int nRows; 367 int anchorX; 368 int anchorY; 369 float *values; 370 } 371 IplConvKernelFP; 372 373 #define IPL_IMAGE_HEADER 1 374 #define IPL_IMAGE_DATA 2 375 #define IPL_IMAGE_ROI 4 376 377 #endif/*HAVE_IPL*/ 378 379 /** extra border mode */ 380 #define IPL_BORDER_REFLECT_101 4 381 #define IPL_BORDER_TRANSPARENT 5 382 383 #define IPL_IMAGE_MAGIC_VAL ((int)sizeof(IplImage)) 384 #define CV_TYPE_NAME_IMAGE "opencv-image" 385 386 #define CV_IS_IMAGE_HDR(img) \ 387 ((img) != NULL && ((const IplImage*)(img))->nSize == sizeof(IplImage)) 388 389 #define CV_IS_IMAGE(img) \ 390 (CV_IS_IMAGE_HDR(img) && ((IplImage*)img)->imageData != NULL) 391 392 /** for storing double-precision 393 floating point data in IplImage's */ 394 #define IPL_DEPTH_64F 64 395 396 /** get reference to pixel at (col,row), 397 for multi-channel images (col) should be multiplied by number of channels */ 398 #define CV_IMAGE_ELEM( image, elemtype, row, col ) \ 399 (((elemtype*)((image)->imageData + (image)->widthStep*(row)))[(col)]) 400 401 /****************************************************************************************\ 402 * Matrix type (CvMat) * 403 \****************************************************************************************/ 404 405 #define CV_AUTO_STEP 0x7fffffff 406 #define CV_WHOLE_ARR cvSlice( 0, 0x3fffffff ) 407 408 #define CV_MAGIC_MASK 0xFFFF0000 409 #define CV_MAT_MAGIC_VAL 0x42420000 410 #define CV_TYPE_NAME_MAT "opencv-matrix" 411 412 /** Matrix elements are stored row by row. Element (i, j) (i - 0-based row index, j - 0-based column 413 index) of a matrix can be retrieved or modified using CV_MAT_ELEM macro: 414 415 uchar pixval = CV_MAT_ELEM(grayimg, uchar, i, j) 416 CV_MAT_ELEM(cameraMatrix, float, 0, 2) = image.width*0.5f; 417 418 To access multiple-channel matrices, you can use 419 CV_MAT_ELEM(matrix, type, i, j\*nchannels + channel_idx). 420 421 @deprecated CvMat is now obsolete; consider using Mat instead. 422 */ 423 typedef struct CvMat 424 { 425 int type; 426 int step; 427 428 /* for internal use only */ 429 int* refcount; 430 int hdr_refcount; 431 432 union 433 { 434 uchar* ptr; 435 short* s; 436 int* i; 437 float* fl; 438 double* db; 439 } data; 440 441 #ifdef __cplusplus 442 union 443 { 444 int rows; 445 int height; 446 }; 447 448 union 449 { 450 int cols; 451 int width; 452 }; 453 #else 454 int rows; 455 int cols; 456 #endif 457 458 459 #ifdef __cplusplus 460 CvMat() {} 461 CvMat(const CvMat& m) { memcpy(this, &m, sizeof(CvMat));} 462 CvMat(const cv::Mat& m); 463 #endif 464 465 } 466 CvMat; 467 468 469 #define CV_IS_MAT_HDR(mat) \ 470 ((mat) != NULL && \ 471 (((const CvMat*)(mat))->type & CV_MAGIC_MASK) == CV_MAT_MAGIC_VAL && \ 472 ((const CvMat*)(mat))->cols > 0 && ((const CvMat*)(mat))->rows > 0) 473 474 #define CV_IS_MAT_HDR_Z(mat) \ 475 ((mat) != NULL && \ 476 (((const CvMat*)(mat))->type & CV_MAGIC_MASK) == CV_MAT_MAGIC_VAL && \ 477 ((const CvMat*)(mat))->cols >= 0 && ((const CvMat*)(mat))->rows >= 0) 478 479 #define CV_IS_MAT(mat) \ 480 (CV_IS_MAT_HDR(mat) && ((const CvMat*)(mat))->data.ptr != NULL) 481 482 #define CV_IS_MASK_ARR(mat) \ 483 (((mat)->type & (CV_MAT_TYPE_MASK & ~CV_8SC1)) == 0) 484 485 #define CV_ARE_TYPES_EQ(mat1, mat2) \ 486 ((((mat1)->type ^ (mat2)->type) & CV_MAT_TYPE_MASK) == 0) 487 488 #define CV_ARE_CNS_EQ(mat1, mat2) \ 489 ((((mat1)->type ^ (mat2)->type) & CV_MAT_CN_MASK) == 0) 490 491 #define CV_ARE_DEPTHS_EQ(mat1, mat2) \ 492 ((((mat1)->type ^ (mat2)->type) & CV_MAT_DEPTH_MASK) == 0) 493 494 #define CV_ARE_SIZES_EQ(mat1, mat2) \ 495 ((mat1)->rows == (mat2)->rows && (mat1)->cols == (mat2)->cols) 496 497 #define CV_IS_MAT_CONST(mat) \ 498 (((mat)->rows|(mat)->cols) == 1) 499 500 #define IPL2CV_DEPTH(depth) \ 501 ((((CV_8U)+(CV_16U<<4)+(CV_32F<<8)+(CV_64F<<16)+(CV_8S<<20)+ \ 502 (CV_16S<<24)+(CV_32S<<28)) >> ((((depth) & 0xF0) >> 2) + \ 503 (((depth) & IPL_DEPTH_SIGN) ? 20 : 0))) & 15) 504 505 /** Inline constructor. No data is allocated internally!!! 506 * (Use together with cvCreateData, or use cvCreateMat instead to 507 * get a matrix with allocated data): 508 */ 509 CV_INLINE CvMat cvMat( int rows, int cols, int type, void* data CV_DEFAULT(NULL)) 510 { 511 CvMat m; 512 513 assert( (unsigned)CV_MAT_DEPTH(type) <= CV_64F ); 514 type = CV_MAT_TYPE(type); 515 m.type = CV_MAT_MAGIC_VAL | CV_MAT_CONT_FLAG | type; 516 m.cols = cols; 517 m.rows = rows; 518 m.step = m.cols*CV_ELEM_SIZE(type); 519 m.data.ptr = (uchar*)data; 520 m.refcount = NULL; 521 m.hdr_refcount = 0; 522 523 return m; 524 } 525 526 #ifdef __cplusplus 527 inline CvMat::CvMat(const cv::Mat& m) 528 { 529 CV_DbgAssert(m.dims <= 2); 530 *this = cvMat(m.rows, m.dims == 1 ? 1 : m.cols, m.type(), m.data); 531 step = (int)m.step[0]; 532 type = (type & ~cv::Mat::CONTINUOUS_FLAG) | (m.flags & cv::Mat::CONTINUOUS_FLAG); 533 } 534 #endif 535 536 537 #define CV_MAT_ELEM_PTR_FAST( mat, row, col, pix_size ) \ 538 (assert( (unsigned)(row) < (unsigned)(mat).rows && \ 539 (unsigned)(col) < (unsigned)(mat).cols ), \ 540 (mat).data.ptr + (size_t)(mat).step*(row) + (pix_size)*(col)) 541 542 #define CV_MAT_ELEM_PTR( mat, row, col ) \ 543 CV_MAT_ELEM_PTR_FAST( mat, row, col, CV_ELEM_SIZE((mat).type) ) 544 545 #define CV_MAT_ELEM( mat, elemtype, row, col ) \ 546 (*(elemtype*)CV_MAT_ELEM_PTR_FAST( mat, row, col, sizeof(elemtype))) 547 548 /** @brief Returns the particular element of single-channel floating-point matrix. 549 550 The function is a fast replacement for cvGetReal2D in the case of single-channel floating-point 551 matrices. It is faster because it is inline, it does fewer checks for array type and array element 552 type, and it checks for the row and column ranges only in debug mode. 553 @param mat Input matrix 554 @param row The zero-based index of row 555 @param col The zero-based index of column 556 */ 557 CV_INLINE double cvmGet( const CvMat* mat, int row, int col ) 558 { 559 int type; 560 561 type = CV_MAT_TYPE(mat->type); 562 assert( (unsigned)row < (unsigned)mat->rows && 563 (unsigned)col < (unsigned)mat->cols ); 564 565 if( type == CV_32FC1 ) 566 return ((float*)(void*)(mat->data.ptr + (size_t)mat->step*row))[col]; 567 else 568 { 569 assert( type == CV_64FC1 ); 570 return ((double*)(void*)(mat->data.ptr + (size_t)mat->step*row))[col]; 571 } 572 } 573 574 /** @brief Sets a specific element of a single-channel floating-point matrix. 575 576 The function is a fast replacement for cvSetReal2D in the case of single-channel floating-point 577 matrices. It is faster because it is inline, it does fewer checks for array type and array element 578 type, and it checks for the row and column ranges only in debug mode. 579 @param mat The matrix 580 @param row The zero-based index of row 581 @param col The zero-based index of column 582 @param value The new value of the matrix element 583 */ 584 CV_INLINE void cvmSet( CvMat* mat, int row, int col, double value ) 585 { 586 int type; 587 type = CV_MAT_TYPE(mat->type); 588 assert( (unsigned)row < (unsigned)mat->rows && 589 (unsigned)col < (unsigned)mat->cols ); 590 591 if( type == CV_32FC1 ) 592 ((float*)(void*)(mat->data.ptr + (size_t)mat->step*row))[col] = (float)value; 593 else 594 { 595 assert( type == CV_64FC1 ); 596 ((double*)(void*)(mat->data.ptr + (size_t)mat->step*row))[col] = value; 597 } 598 } 599 600 601 CV_INLINE int cvIplDepth( int type ) 602 { 603 int depth = CV_MAT_DEPTH(type); 604 return CV_ELEM_SIZE1(depth)*8 | (depth == CV_8S || depth == CV_16S || 605 depth == CV_32S ? IPL_DEPTH_SIGN : 0); 606 } 607 608 609 /****************************************************************************************\ 610 * Multi-dimensional dense array (CvMatND) * 611 \****************************************************************************************/ 612 613 #define CV_MATND_MAGIC_VAL 0x42430000 614 #define CV_TYPE_NAME_MATND "opencv-nd-matrix" 615 616 #define CV_MAX_DIM 32 617 #define CV_MAX_DIM_HEAP 1024 618 619 /** 620 @deprecated consider using cv::Mat instead 621 */ 622 typedef struct 623 #ifdef __cplusplus 624 CV_EXPORTS 625 #endif 626 CvMatND 627 { 628 int type; 629 int dims; 630 631 int* refcount; 632 int hdr_refcount; 633 634 union 635 { 636 uchar* ptr; 637 float* fl; 638 double* db; 639 int* i; 640 short* s; 641 } data; 642 643 struct 644 { 645 int size; 646 int step; 647 } 648 dim[CV_MAX_DIM]; 649 650 #ifdef __cplusplus 651 CvMatND() {} 652 CvMatND(const cv::Mat& m); 653 #endif 654 } 655 CvMatND; 656 657 #define CV_IS_MATND_HDR(mat) \ 658 ((mat) != NULL && (((const CvMatND*)(mat))->type & CV_MAGIC_MASK) == CV_MATND_MAGIC_VAL) 659 660 #define CV_IS_MATND(mat) \ 661 (CV_IS_MATND_HDR(mat) && ((const CvMatND*)(mat))->data.ptr != NULL) 662 663 664 /****************************************************************************************\ 665 * Multi-dimensional sparse array (CvSparseMat) * 666 \****************************************************************************************/ 667 668 #define CV_SPARSE_MAT_MAGIC_VAL 0x42440000 669 #define CV_TYPE_NAME_SPARSE_MAT "opencv-sparse-matrix" 670 671 struct CvSet; 672 673 typedef struct 674 #ifdef __cplusplus 675 CV_EXPORTS 676 #endif 677 CvSparseMat 678 { 679 int type; 680 int dims; 681 int* refcount; 682 int hdr_refcount; 683 684 struct CvSet* heap; 685 void** hashtable; 686 int hashsize; 687 int valoffset; 688 int idxoffset; 689 int size[CV_MAX_DIM]; 690 691 #ifdef __cplusplus 692 void copyToSparseMat(cv::SparseMat& m) const; 693 #endif 694 } 695 CvSparseMat; 696 697 #ifdef __cplusplus 698 CV_EXPORTS CvSparseMat* cvCreateSparseMat(const cv::SparseMat& m); 699 #endif 700 701 #define CV_IS_SPARSE_MAT_HDR(mat) \ 702 ((mat) != NULL && \ 703 (((const CvSparseMat*)(mat))->type & CV_MAGIC_MASK) == CV_SPARSE_MAT_MAGIC_VAL) 704 705 #define CV_IS_SPARSE_MAT(mat) \ 706 CV_IS_SPARSE_MAT_HDR(mat) 707 708 /**************** iteration through a sparse array *****************/ 709 710 typedef struct CvSparseNode 711 { 712 unsigned hashval; 713 struct CvSparseNode* next; 714 } 715 CvSparseNode; 716 717 typedef struct CvSparseMatIterator 718 { 719 CvSparseMat* mat; 720 CvSparseNode* node; 721 int curidx; 722 } 723 CvSparseMatIterator; 724 725 #define CV_NODE_VAL(mat,node) ((void*)((uchar*)(node) + (mat)->valoffset)) 726 #define CV_NODE_IDX(mat,node) ((int*)((uchar*)(node) + (mat)->idxoffset)) 727 728 /****************************************************************************************\ 729 * Histogram * 730 \****************************************************************************************/ 731 732 typedef int CvHistType; 733 734 #define CV_HIST_MAGIC_VAL 0x42450000 735 #define CV_HIST_UNIFORM_FLAG (1 << 10) 736 737 /** indicates whether bin ranges are set already or not */ 738 #define CV_HIST_RANGES_FLAG (1 << 11) 739 740 #define CV_HIST_ARRAY 0 741 #define CV_HIST_SPARSE 1 742 #define CV_HIST_TREE CV_HIST_SPARSE 743 744 /** should be used as a parameter only, 745 it turns to CV_HIST_UNIFORM_FLAG of hist->type */ 746 #define CV_HIST_UNIFORM 1 747 748 typedef struct CvHistogram 749 { 750 int type; 751 CvArr* bins; 752 float thresh[CV_MAX_DIM][2]; /**< For uniform histograms. */ 753 float** thresh2; /**< For non-uniform histograms. */ 754 CvMatND mat; /**< Embedded matrix header for array histograms. */ 755 } 756 CvHistogram; 757 758 #define CV_IS_HIST( hist ) \ 759 ((hist) != NULL && \ 760 (((CvHistogram*)(hist))->type & CV_MAGIC_MASK) == CV_HIST_MAGIC_VAL && \ 761 (hist)->bins != NULL) 762 763 #define CV_IS_UNIFORM_HIST( hist ) \ 764 (((hist)->type & CV_HIST_UNIFORM_FLAG) != 0) 765 766 #define CV_IS_SPARSE_HIST( hist ) \ 767 CV_IS_SPARSE_MAT((hist)->bins) 768 769 #define CV_HIST_HAS_RANGES( hist ) \ 770 (((hist)->type & CV_HIST_RANGES_FLAG) != 0) 771 772 /****************************************************************************************\ 773 * Other supplementary data type definitions * 774 \****************************************************************************************/ 775 776 /*************************************** CvRect *****************************************/ 777 /** @sa Rect_ */ 778 typedef struct CvRect 779 { 780 int x; 781 int y; 782 int width; 783 int height; 784 785 #ifdef __cplusplus 786 CvRect(int _x = 0, int _y = 0, int w = 0, int h = 0): x(_x), y(_y), width(w), height(h) {} 787 template<typename _Tp> 788 CvRect(const cv::Rect_<_Tp>& r): x(cv::saturate_cast<int>(r.x)), y(cv::saturate_cast<int>(r.y)), width(cv::saturate_cast<int>(r.width)), height(cv::saturate_cast<int>(r.height)) {} 789 template<typename _Tp> 790 operator cv::Rect_<_Tp>() const { return cv::Rect_<_Tp>((_Tp)x, (_Tp)y, (_Tp)width, (_Tp)height); } 791 #endif 792 } 793 CvRect; 794 795 /** constructs CvRect structure. */ 796 CV_INLINE CvRect cvRect( int x, int y, int width, int height ) 797 { 798 CvRect r; 799 800 r.x = x; 801 r.y = y; 802 r.width = width; 803 r.height = height; 804 805 return r; 806 } 807 808 809 CV_INLINE IplROI cvRectToROI( CvRect rect, int coi ) 810 { 811 IplROI roi; 812 roi.xOffset = rect.x; 813 roi.yOffset = rect.y; 814 roi.width = rect.width; 815 roi.height = rect.height; 816 roi.coi = coi; 817 818 return roi; 819 } 820 821 822 CV_INLINE CvRect cvROIToRect( IplROI roi ) 823 { 824 return cvRect( roi.xOffset, roi.yOffset, roi.width, roi.height ); 825 } 826 827 /*********************************** CvTermCriteria *************************************/ 828 829 #define CV_TERMCRIT_ITER 1 830 #define CV_TERMCRIT_NUMBER CV_TERMCRIT_ITER 831 #define CV_TERMCRIT_EPS 2 832 833 /** @sa TermCriteria 834 */ 835 typedef struct CvTermCriteria 836 { 837 int type; /**< may be combination of 838 CV_TERMCRIT_ITER 839 CV_TERMCRIT_EPS */ 840 int max_iter; 841 double epsilon; 842 843 #ifdef __cplusplus 844 CvTermCriteria(int _type = 0, int _iter = 0, double _eps = 0) : type(_type), max_iter(_iter), epsilon(_eps) {} 845 CvTermCriteria(const cv::TermCriteria& t) : type(t.type), max_iter(t.maxCount), epsilon(t.epsilon) {} 846 operator cv::TermCriteria() const { return cv::TermCriteria(type, max_iter, epsilon); } 847 #endif 848 849 } 850 CvTermCriteria; 851 852 CV_INLINE CvTermCriteria cvTermCriteria( int type, int max_iter, double epsilon ) 853 { 854 CvTermCriteria t; 855 856 t.type = type; 857 t.max_iter = max_iter; 858 t.epsilon = (float)epsilon; 859 860 return t; 861 } 862 863 864 /******************************* CvPoint and variants ***********************************/ 865 866 typedef struct CvPoint 867 { 868 int x; 869 int y; 870 871 #ifdef __cplusplus 872 CvPoint(int _x = 0, int _y = 0): x(_x), y(_y) {} 873 template<typename _Tp> 874 CvPoint(const cv::Point_<_Tp>& pt): x((int)pt.x), y((int)pt.y) {} 875 template<typename _Tp> 876 operator cv::Point_<_Tp>() const { return cv::Point_<_Tp>(cv::saturate_cast<_Tp>(x), cv::saturate_cast<_Tp>(y)); } 877 #endif 878 } 879 CvPoint; 880 881 /** constructs CvPoint structure. */ 882 CV_INLINE CvPoint cvPoint( int x, int y ) 883 { 884 CvPoint p; 885 886 p.x = x; 887 p.y = y; 888 889 return p; 890 } 891 892 893 typedef struct CvPoint2D32f 894 { 895 float x; 896 float y; 897 898 #ifdef __cplusplus 899 CvPoint2D32f(float _x = 0, float _y = 0): x(_x), y(_y) {} 900 template<typename _Tp> 901 CvPoint2D32f(const cv::Point_<_Tp>& pt): x((float)pt.x), y((float)pt.y) {} 902 template<typename _Tp> 903 operator cv::Point_<_Tp>() const { return cv::Point_<_Tp>(cv::saturate_cast<_Tp>(x), cv::saturate_cast<_Tp>(y)); } 904 #endif 905 } 906 CvPoint2D32f; 907 908 /** constructs CvPoint2D32f structure. */ 909 CV_INLINE CvPoint2D32f cvPoint2D32f( double x, double y ) 910 { 911 CvPoint2D32f p; 912 913 p.x = (float)x; 914 p.y = (float)y; 915 916 return p; 917 } 918 919 /** converts CvPoint to CvPoint2D32f. */ 920 CV_INLINE CvPoint2D32f cvPointTo32f( CvPoint point ) 921 { 922 return cvPoint2D32f( (float)point.x, (float)point.y ); 923 } 924 925 /** converts CvPoint2D32f to CvPoint. */ 926 CV_INLINE CvPoint cvPointFrom32f( CvPoint2D32f point ) 927 { 928 CvPoint ipt; 929 ipt.x = cvRound(point.x); 930 ipt.y = cvRound(point.y); 931 932 return ipt; 933 } 934 935 936 typedef struct CvPoint3D32f 937 { 938 float x; 939 float y; 940 float z; 941 942 #ifdef __cplusplus 943 CvPoint3D32f(float _x = 0, float _y = 0, float _z = 0): x(_x), y(_y), z(_z) {} 944 template<typename _Tp> 945 CvPoint3D32f(const cv::Point3_<_Tp>& pt): x((float)pt.x), y((float)pt.y), z((float)pt.z) {} 946 template<typename _Tp> 947 operator cv::Point3_<_Tp>() const { return cv::Point3_<_Tp>(cv::saturate_cast<_Tp>(x), cv::saturate_cast<_Tp>(y), cv::saturate_cast<_Tp>(z)); } 948 #endif 949 } 950 CvPoint3D32f; 951 952 /** constructs CvPoint3D32f structure. */ 953 CV_INLINE CvPoint3D32f cvPoint3D32f( double x, double y, double z ) 954 { 955 CvPoint3D32f p; 956 957 p.x = (float)x; 958 p.y = (float)y; 959 p.z = (float)z; 960 961 return p; 962 } 963 964 965 typedef struct CvPoint2D64f 966 { 967 double x; 968 double y; 969 } 970 CvPoint2D64f; 971 972 /** constructs CvPoint2D64f structure.*/ 973 CV_INLINE CvPoint2D64f cvPoint2D64f( double x, double y ) 974 { 975 CvPoint2D64f p; 976 977 p.x = x; 978 p.y = y; 979 980 return p; 981 } 982 983 984 typedef struct CvPoint3D64f 985 { 986 double x; 987 double y; 988 double z; 989 } 990 CvPoint3D64f; 991 992 /** constructs CvPoint3D64f structure. */ 993 CV_INLINE CvPoint3D64f cvPoint3D64f( double x, double y, double z ) 994 { 995 CvPoint3D64f p; 996 997 p.x = x; 998 p.y = y; 999 p.z = z; 1000 1001 return p; 1002 } 1003 1004 1005 /******************************** CvSize's & CvBox **************************************/ 1006 1007 typedef struct CvSize 1008 { 1009 int width; 1010 int height; 1011 1012 #ifdef __cplusplus 1013 CvSize(int w = 0, int h = 0): width(w), height(h) {} 1014 template<typename _Tp> 1015 CvSize(const cv::Size_<_Tp>& sz): width(cv::saturate_cast<int>(sz.width)), height(cv::saturate_cast<int>(sz.height)) {} 1016 template<typename _Tp> 1017 operator cv::Size_<_Tp>() const { return cv::Size_<_Tp>(cv::saturate_cast<_Tp>(width), cv::saturate_cast<_Tp>(height)); } 1018 #endif 1019 } 1020 CvSize; 1021 1022 /** constructs CvSize structure. */ 1023 CV_INLINE CvSize cvSize( int width, int height ) 1024 { 1025 CvSize s; 1026 1027 s.width = width; 1028 s.height = height; 1029 1030 return s; 1031 } 1032 1033 typedef struct CvSize2D32f 1034 { 1035 float width; 1036 float height; 1037 1038 #ifdef __cplusplus 1039 CvSize2D32f(float w = 0, float h = 0): width(w), height(h) {} 1040 template<typename _Tp> 1041 CvSize2D32f(const cv::Size_<_Tp>& sz): width(cv::saturate_cast<float>(sz.width)), height(cv::saturate_cast<float>(sz.height)) {} 1042 template<typename _Tp> 1043 operator cv::Size_<_Tp>() const { return cv::Size_<_Tp>(cv::saturate_cast<_Tp>(width), cv::saturate_cast<_Tp>(height)); } 1044 #endif 1045 } 1046 CvSize2D32f; 1047 1048 /** constructs CvSize2D32f structure. */ 1049 CV_INLINE CvSize2D32f cvSize2D32f( double width, double height ) 1050 { 1051 CvSize2D32f s; 1052 1053 s.width = (float)width; 1054 s.height = (float)height; 1055 1056 return s; 1057 } 1058 1059 /** @sa RotatedRect 1060 */ 1061 typedef struct CvBox2D 1062 { 1063 CvPoint2D32f center; /**< Center of the box. */ 1064 CvSize2D32f size; /**< Box width and length. */ 1065 float angle; /**< Angle between the horizontal axis */ 1066 /**< and the first side (i.e. length) in degrees */ 1067 1068 #ifdef __cplusplus 1069 CvBox2D(CvPoint2D32f c = CvPoint2D32f(), CvSize2D32f s = CvSize2D32f(), float a = 0) : center(c), size(s), angle(a) {} 1070 CvBox2D(const cv::RotatedRect& rr) : center(rr.center), size(rr.size), angle(rr.angle) {} 1071 operator cv::RotatedRect() const { return cv::RotatedRect(center, size, angle); } 1072 #endif 1073 } 1074 CvBox2D; 1075 1076 1077 /** Line iterator state: */ 1078 typedef struct CvLineIterator 1079 { 1080 /** Pointer to the current point: */ 1081 uchar* ptr; 1082 1083 /* Bresenham algorithm state: */ 1084 int err; 1085 int plus_delta; 1086 int minus_delta; 1087 int plus_step; 1088 int minus_step; 1089 } 1090 CvLineIterator; 1091 1092 1093 1094 /************************************* CvSlice ******************************************/ 1095 #define CV_WHOLE_SEQ_END_INDEX 0x3fffffff 1096 #define CV_WHOLE_SEQ cvSlice(0, CV_WHOLE_SEQ_END_INDEX) 1097 1098 typedef struct CvSlice 1099 { 1100 int start_index, end_index; 1101 1102 #if defined(__cplusplus) && !defined(__CUDACC__) 1103 CvSlice(int start = 0, int end = 0) : start_index(start), end_index(end) {} 1104 CvSlice(const cv::Range& r) { *this = (r.start != INT_MIN && r.end != INT_MAX) ? CvSlice(r.start, r.end) : CvSlice(0, CV_WHOLE_SEQ_END_INDEX); } 1105 operator cv::Range() const { return (start_index == 0 && end_index == CV_WHOLE_SEQ_END_INDEX ) ? cv::Range::all() : cv::Range(start_index, end_index); } 1106 #endif 1107 } 1108 CvSlice; 1109 1110 CV_INLINE CvSlice cvSlice( int start, int end ) 1111 { 1112 CvSlice slice; 1113 slice.start_index = start; 1114 slice.end_index = end; 1115 1116 return slice; 1117 } 1118 1119 1120 1121 /************************************* CvScalar *****************************************/ 1122 /** @sa Scalar_ 1123 */ 1124 typedef struct CvScalar 1125 { 1126 double val[4]; 1127 1128 #ifdef __cplusplus 1129 CvScalar() {} 1130 CvScalar(double d0, double d1 = 0, double d2 = 0, double d3 = 0) { val[0] = d0; val[1] = d1; val[2] = d2; val[3] = d3; } 1131 template<typename _Tp> 1132 CvScalar(const cv::Scalar_<_Tp>& s) { val[0] = s.val[0]; val[1] = s.val[1]; val[2] = s.val[2]; val[3] = s.val[3]; } 1133 template<typename _Tp> 1134 operator cv::Scalar_<_Tp>() const { return cv::Scalar_<_Tp>(cv::saturate_cast<_Tp>(val[0]), cv::saturate_cast<_Tp>(val[1]), cv::saturate_cast<_Tp>(val[2]), cv::saturate_cast<_Tp>(val[3])); } 1135 template<typename _Tp, int cn> 1136 CvScalar(const cv::Vec<_Tp, cn>& v) 1137 { 1138 int i; 1139 for( i = 0; i < (cn < 4 ? cn : 4); i++ ) val[i] = v.val[i]; 1140 for( ; i < 4; i++ ) val[i] = 0; 1141 } 1142 #endif 1143 } 1144 CvScalar; 1145 1146 CV_INLINE CvScalar cvScalar( double val0, double val1 CV_DEFAULT(0), 1147 double val2 CV_DEFAULT(0), double val3 CV_DEFAULT(0)) 1148 { 1149 CvScalar scalar; 1150 scalar.val[0] = val0; scalar.val[1] = val1; 1151 scalar.val[2] = val2; scalar.val[3] = val3; 1152 return scalar; 1153 } 1154 1155 1156 CV_INLINE CvScalar cvRealScalar( double val0 ) 1157 { 1158 CvScalar scalar; 1159 scalar.val[0] = val0; 1160 scalar.val[1] = scalar.val[2] = scalar.val[3] = 0; 1161 return scalar; 1162 } 1163 1164 CV_INLINE CvScalar cvScalarAll( double val0123 ) 1165 { 1166 CvScalar scalar; 1167 scalar.val[0] = val0123; 1168 scalar.val[1] = val0123; 1169 scalar.val[2] = val0123; 1170 scalar.val[3] = val0123; 1171 return scalar; 1172 } 1173 1174 /****************************************************************************************\ 1175 * Dynamic Data structures * 1176 \****************************************************************************************/ 1177 1178 /******************************** Memory storage ****************************************/ 1179 1180 typedef struct CvMemBlock 1181 { 1182 struct CvMemBlock* prev; 1183 struct CvMemBlock* next; 1184 } 1185 CvMemBlock; 1186 1187 #define CV_STORAGE_MAGIC_VAL 0x42890000 1188 1189 typedef struct CvMemStorage 1190 { 1191 int signature; 1192 CvMemBlock* bottom; /**< First allocated block. */ 1193 CvMemBlock* top; /**< Current memory block - top of the stack. */ 1194 struct CvMemStorage* parent; /**< We get new blocks from parent as needed. */ 1195 int block_size; /**< Block size. */ 1196 int free_space; /**< Remaining free space in current block. */ 1197 } 1198 CvMemStorage; 1199 1200 #define CV_IS_STORAGE(storage) \ 1201 ((storage) != NULL && \ 1202 (((CvMemStorage*)(storage))->signature & CV_MAGIC_MASK) == CV_STORAGE_MAGIC_VAL) 1203 1204 1205 typedef struct CvMemStoragePos 1206 { 1207 CvMemBlock* top; 1208 int free_space; 1209 } 1210 CvMemStoragePos; 1211 1212 1213 /*********************************** Sequence *******************************************/ 1214 1215 typedef struct CvSeqBlock 1216 { 1217 struct CvSeqBlock* prev; /**< Previous sequence block. */ 1218 struct CvSeqBlock* next; /**< Next sequence block. */ 1219 int start_index; /**< Index of the first element in the block + */ 1220 /**< sequence->first->start_index. */ 1221 int count; /**< Number of elements in the block. */ 1222 schar* data; /**< Pointer to the first element of the block. */ 1223 } 1224 CvSeqBlock; 1225 1226 1227 #define CV_TREE_NODE_FIELDS(node_type) \ 1228 int flags; /**< Miscellaneous flags. */ \ 1229 int header_size; /**< Size of sequence header. */ \ 1230 struct node_type* h_prev; /**< Previous sequence. */ \ 1231 struct node_type* h_next; /**< Next sequence. */ \ 1232 struct node_type* v_prev; /**< 2nd previous sequence. */ \ 1233 struct node_type* v_next /**< 2nd next sequence. */ 1234 1235 /** 1236 Read/Write sequence. 1237 Elements can be dynamically inserted to or deleted from the sequence. 1238 */ 1239 #define CV_SEQUENCE_FIELDS() \ 1240 CV_TREE_NODE_FIELDS(CvSeq); \ 1241 int total; /**< Total number of elements. */ \ 1242 int elem_size; /**< Size of sequence element in bytes. */ \ 1243 schar* block_max; /**< Maximal bound of the last block. */ \ 1244 schar* ptr; /**< Current write pointer. */ \ 1245 int delta_elems; /**< Grow seq this many at a time. */ \ 1246 CvMemStorage* storage; /**< Where the seq is stored. */ \ 1247 CvSeqBlock* free_blocks; /**< Free blocks list. */ \ 1248 CvSeqBlock* first; /**< Pointer to the first sequence block. */ 1249 1250 typedef struct CvSeq 1251 { 1252 CV_SEQUENCE_FIELDS() 1253 } 1254 CvSeq; 1255 1256 #define CV_TYPE_NAME_SEQ "opencv-sequence" 1257 #define CV_TYPE_NAME_SEQ_TREE "opencv-sequence-tree" 1258 1259 /*************************************** Set ********************************************/ 1260 /** @brief Set 1261 Order is not preserved. There can be gaps between sequence elements. 1262 After the element has been inserted it stays in the same place all the time. 1263 The MSB(most-significant or sign bit) of the first field (flags) is 0 iff the element exists. 1264 */ 1265 #define CV_SET_ELEM_FIELDS(elem_type) \ 1266 int flags; \ 1267 struct elem_type* next_free; 1268 1269 typedef struct CvSetElem 1270 { 1271 CV_SET_ELEM_FIELDS(CvSetElem) 1272 } 1273 CvSetElem; 1274 1275 #define CV_SET_FIELDS() \ 1276 CV_SEQUENCE_FIELDS() \ 1277 CvSetElem* free_elems; \ 1278 int active_count; 1279 1280 typedef struct CvSet 1281 { 1282 CV_SET_FIELDS() 1283 } 1284 CvSet; 1285 1286 1287 #define CV_SET_ELEM_IDX_MASK ((1 << 26) - 1) 1288 #define CV_SET_ELEM_FREE_FLAG (1 << (sizeof(int)*8-1)) 1289 1290 /** Checks whether the element pointed by ptr belongs to a set or not */ 1291 #define CV_IS_SET_ELEM( ptr ) (((CvSetElem*)(ptr))->flags >= 0) 1292 1293 /************************************* Graph ********************************************/ 1294 1295 /** @name Graph 1296 1297 We represent a graph as a set of vertices. Vertices contain their adjacency lists (more exactly, 1298 pointers to first incoming or outcoming edge (or 0 if isolated vertex)). Edges are stored in 1299 another set. There is a singly-linked list of incoming/outcoming edges for each vertex. 1300 1301 Each edge consists of: 1302 1303 - Two pointers to the starting and ending vertices (vtx[0] and vtx[1] respectively). 1304 1305 A graph may be oriented or not. In the latter case, edges between vertex i to vertex j are not 1306 distinguished during search operations. 1307 1308 - Two pointers to next edges for the starting and ending vertices, where next[0] points to the 1309 next edge in the vtx[0] adjacency list and next[1] points to the next edge in the vtx[1] 1310 adjacency list. 1311 1312 @see CvGraphEdge, CvGraphVtx, CvGraphVtx2D, CvGraph 1313 @{ 1314 */ 1315 #define CV_GRAPH_EDGE_FIELDS() \ 1316 int flags; \ 1317 float weight; \ 1318 struct CvGraphEdge* next[2]; \ 1319 struct CvGraphVtx* vtx[2]; 1320 1321 1322 #define CV_GRAPH_VERTEX_FIELDS() \ 1323 int flags; \ 1324 struct CvGraphEdge* first; 1325 1326 1327 typedef struct CvGraphEdge 1328 { 1329 CV_GRAPH_EDGE_FIELDS() 1330 } 1331 CvGraphEdge; 1332 1333 typedef struct CvGraphVtx 1334 { 1335 CV_GRAPH_VERTEX_FIELDS() 1336 } 1337 CvGraphVtx; 1338 1339 typedef struct CvGraphVtx2D 1340 { 1341 CV_GRAPH_VERTEX_FIELDS() 1342 CvPoint2D32f* ptr; 1343 } 1344 CvGraphVtx2D; 1345 1346 /** 1347 Graph is "derived" from the set (this is set a of vertices) 1348 and includes another set (edges) 1349 */ 1350 #define CV_GRAPH_FIELDS() \ 1351 CV_SET_FIELDS() \ 1352 CvSet* edges; 1353 1354 typedef struct CvGraph 1355 { 1356 CV_GRAPH_FIELDS() 1357 } 1358 CvGraph; 1359 1360 #define CV_TYPE_NAME_GRAPH "opencv-graph" 1361 1362 /** @} */ 1363 1364 /*********************************** Chain/Countour *************************************/ 1365 1366 typedef struct CvChain 1367 { 1368 CV_SEQUENCE_FIELDS() 1369 CvPoint origin; 1370 } 1371 CvChain; 1372 1373 #define CV_CONTOUR_FIELDS() \ 1374 CV_SEQUENCE_FIELDS() \ 1375 CvRect rect; \ 1376 int color; \ 1377 int reserved[3]; 1378 1379 typedef struct CvContour 1380 { 1381 CV_CONTOUR_FIELDS() 1382 } 1383 CvContour; 1384 1385 typedef CvContour CvPoint2DSeq; 1386 1387 /****************************************************************************************\ 1388 * Sequence types * 1389 \****************************************************************************************/ 1390 1391 #define CV_SEQ_MAGIC_VAL 0x42990000 1392 1393 #define CV_IS_SEQ(seq) \ 1394 ((seq) != NULL && (((CvSeq*)(seq))->flags & CV_MAGIC_MASK) == CV_SEQ_MAGIC_VAL) 1395 1396 #define CV_SET_MAGIC_VAL 0x42980000 1397 #define CV_IS_SET(set) \ 1398 ((set) != NULL && (((CvSeq*)(set))->flags & CV_MAGIC_MASK) == CV_SET_MAGIC_VAL) 1399 1400 #define CV_SEQ_ELTYPE_BITS 12 1401 #define CV_SEQ_ELTYPE_MASK ((1 << CV_SEQ_ELTYPE_BITS) - 1) 1402 1403 #define CV_SEQ_ELTYPE_POINT CV_32SC2 /**< (x,y) */ 1404 #define CV_SEQ_ELTYPE_CODE CV_8UC1 /**< freeman code: 0..7 */ 1405 #define CV_SEQ_ELTYPE_GENERIC 0 1406 #define CV_SEQ_ELTYPE_PTR CV_USRTYPE1 1407 #define CV_SEQ_ELTYPE_PPOINT CV_SEQ_ELTYPE_PTR /**< &(x,y) */ 1408 #define CV_SEQ_ELTYPE_INDEX CV_32SC1 /**< #(x,y) */ 1409 #define CV_SEQ_ELTYPE_GRAPH_EDGE 0 /**< &next_o, &next_d, &vtx_o, &vtx_d */ 1410 #define CV_SEQ_ELTYPE_GRAPH_VERTEX 0 /**< first_edge, &(x,y) */ 1411 #define CV_SEQ_ELTYPE_TRIAN_ATR 0 /**< vertex of the binary tree */ 1412 #define CV_SEQ_ELTYPE_CONNECTED_COMP 0 /**< connected component */ 1413 #define CV_SEQ_ELTYPE_POINT3D CV_32FC3 /**< (x,y,z) */ 1414 1415 #define CV_SEQ_KIND_BITS 2 1416 #define CV_SEQ_KIND_MASK (((1 << CV_SEQ_KIND_BITS) - 1)<<CV_SEQ_ELTYPE_BITS) 1417 1418 /** types of sequences */ 1419 #define CV_SEQ_KIND_GENERIC (0 << CV_SEQ_ELTYPE_BITS) 1420 #define CV_SEQ_KIND_CURVE (1 << CV_SEQ_ELTYPE_BITS) 1421 #define CV_SEQ_KIND_BIN_TREE (2 << CV_SEQ_ELTYPE_BITS) 1422 1423 /** types of sparse sequences (sets) */ 1424 #define CV_SEQ_KIND_GRAPH (1 << CV_SEQ_ELTYPE_BITS) 1425 #define CV_SEQ_KIND_SUBDIV2D (2 << CV_SEQ_ELTYPE_BITS) 1426 1427 #define CV_SEQ_FLAG_SHIFT (CV_SEQ_KIND_BITS + CV_SEQ_ELTYPE_BITS) 1428 1429 /** flags for curves */ 1430 #define CV_SEQ_FLAG_CLOSED (1 << CV_SEQ_FLAG_SHIFT) 1431 #define CV_SEQ_FLAG_SIMPLE (0 << CV_SEQ_FLAG_SHIFT) 1432 #define CV_SEQ_FLAG_CONVEX (0 << CV_SEQ_FLAG_SHIFT) 1433 #define CV_SEQ_FLAG_HOLE (2 << CV_SEQ_FLAG_SHIFT) 1434 1435 /** flags for graphs */ 1436 #define CV_GRAPH_FLAG_ORIENTED (1 << CV_SEQ_FLAG_SHIFT) 1437 1438 #define CV_GRAPH CV_SEQ_KIND_GRAPH 1439 #define CV_ORIENTED_GRAPH (CV_SEQ_KIND_GRAPH|CV_GRAPH_FLAG_ORIENTED) 1440 1441 /** point sets */ 1442 #define CV_SEQ_POINT_SET (CV_SEQ_KIND_GENERIC| CV_SEQ_ELTYPE_POINT) 1443 #define CV_SEQ_POINT3D_SET (CV_SEQ_KIND_GENERIC| CV_SEQ_ELTYPE_POINT3D) 1444 #define CV_SEQ_POLYLINE (CV_SEQ_KIND_CURVE | CV_SEQ_ELTYPE_POINT) 1445 #define CV_SEQ_POLYGON (CV_SEQ_FLAG_CLOSED | CV_SEQ_POLYLINE ) 1446 #define CV_SEQ_CONTOUR CV_SEQ_POLYGON 1447 #define CV_SEQ_SIMPLE_POLYGON (CV_SEQ_FLAG_SIMPLE | CV_SEQ_POLYGON ) 1448 1449 /** chain-coded curves */ 1450 #define CV_SEQ_CHAIN (CV_SEQ_KIND_CURVE | CV_SEQ_ELTYPE_CODE) 1451 #define CV_SEQ_CHAIN_CONTOUR (CV_SEQ_FLAG_CLOSED | CV_SEQ_CHAIN) 1452 1453 /** binary tree for the contour */ 1454 #define CV_SEQ_POLYGON_TREE (CV_SEQ_KIND_BIN_TREE | CV_SEQ_ELTYPE_TRIAN_ATR) 1455 1456 /** sequence of the connected components */ 1457 #define CV_SEQ_CONNECTED_COMP (CV_SEQ_KIND_GENERIC | CV_SEQ_ELTYPE_CONNECTED_COMP) 1458 1459 /** sequence of the integer numbers */ 1460 #define CV_SEQ_INDEX (CV_SEQ_KIND_GENERIC | CV_SEQ_ELTYPE_INDEX) 1461 1462 #define CV_SEQ_ELTYPE( seq ) ((seq)->flags & CV_SEQ_ELTYPE_MASK) 1463 #define CV_SEQ_KIND( seq ) ((seq)->flags & CV_SEQ_KIND_MASK ) 1464 1465 /** flag checking */ 1466 #define CV_IS_SEQ_INDEX( seq ) ((CV_SEQ_ELTYPE(seq) == CV_SEQ_ELTYPE_INDEX) && \ 1467 (CV_SEQ_KIND(seq) == CV_SEQ_KIND_GENERIC)) 1468 1469 #define CV_IS_SEQ_CURVE( seq ) (CV_SEQ_KIND(seq) == CV_SEQ_KIND_CURVE) 1470 #define CV_IS_SEQ_CLOSED( seq ) (((seq)->flags & CV_SEQ_FLAG_CLOSED) != 0) 1471 #define CV_IS_SEQ_CONVEX( seq ) 0 1472 #define CV_IS_SEQ_HOLE( seq ) (((seq)->flags & CV_SEQ_FLAG_HOLE) != 0) 1473 #define CV_IS_SEQ_SIMPLE( seq ) 1 1474 1475 /** type checking macros */ 1476 #define CV_IS_SEQ_POINT_SET( seq ) \ 1477 ((CV_SEQ_ELTYPE(seq) == CV_32SC2 || CV_SEQ_ELTYPE(seq) == CV_32FC2)) 1478 1479 #define CV_IS_SEQ_POINT_SUBSET( seq ) \ 1480 (CV_IS_SEQ_INDEX( seq ) || CV_SEQ_ELTYPE(seq) == CV_SEQ_ELTYPE_PPOINT) 1481 1482 #define CV_IS_SEQ_POLYLINE( seq ) \ 1483 (CV_SEQ_KIND(seq) == CV_SEQ_KIND_CURVE && CV_IS_SEQ_POINT_SET(seq)) 1484 1485 #define CV_IS_SEQ_POLYGON( seq ) \ 1486 (CV_IS_SEQ_POLYLINE(seq) && CV_IS_SEQ_CLOSED(seq)) 1487 1488 #define CV_IS_SEQ_CHAIN( seq ) \ 1489 (CV_SEQ_KIND(seq) == CV_SEQ_KIND_CURVE && (seq)->elem_size == 1) 1490 1491 #define CV_IS_SEQ_CONTOUR( seq ) \ 1492 (CV_IS_SEQ_CLOSED(seq) && (CV_IS_SEQ_POLYLINE(seq) || CV_IS_SEQ_CHAIN(seq))) 1493 1494 #define CV_IS_SEQ_CHAIN_CONTOUR( seq ) \ 1495 (CV_IS_SEQ_CHAIN( seq ) && CV_IS_SEQ_CLOSED( seq )) 1496 1497 #define CV_IS_SEQ_POLYGON_TREE( seq ) \ 1498 (CV_SEQ_ELTYPE (seq) == CV_SEQ_ELTYPE_TRIAN_ATR && \ 1499 CV_SEQ_KIND( seq ) == CV_SEQ_KIND_BIN_TREE ) 1500 1501 #define CV_IS_GRAPH( seq ) \ 1502 (CV_IS_SET(seq) && CV_SEQ_KIND((CvSet*)(seq)) == CV_SEQ_KIND_GRAPH) 1503 1504 #define CV_IS_GRAPH_ORIENTED( seq ) \ 1505 (((seq)->flags & CV_GRAPH_FLAG_ORIENTED) != 0) 1506 1507 #define CV_IS_SUBDIV2D( seq ) \ 1508 (CV_IS_SET(seq) && CV_SEQ_KIND((CvSet*)(seq)) == CV_SEQ_KIND_SUBDIV2D) 1509 1510 /****************************************************************************************/ 1511 /* Sequence writer & reader */ 1512 /****************************************************************************************/ 1513 1514 #define CV_SEQ_WRITER_FIELDS() \ 1515 int header_size; \ 1516 CvSeq* seq; /**< the sequence written */ \ 1517 CvSeqBlock* block; /**< current block */ \ 1518 schar* ptr; /**< pointer to free space */ \ 1519 schar* block_min; /**< pointer to the beginning of block*/\ 1520 schar* block_max; /**< pointer to the end of block */ 1521 1522 typedef struct CvSeqWriter 1523 { 1524 CV_SEQ_WRITER_FIELDS() 1525 } 1526 CvSeqWriter; 1527 1528 1529 #define CV_SEQ_READER_FIELDS() \ 1530 int header_size; \ 1531 CvSeq* seq; /**< sequence, beign read */ \ 1532 CvSeqBlock* block; /**< current block */ \ 1533 schar* ptr; /**< pointer to element be read next */ \ 1534 schar* block_min; /**< pointer to the beginning of block */\ 1535 schar* block_max; /**< pointer to the end of block */ \ 1536 int delta_index;/**< = seq->first->start_index */ \ 1537 schar* prev_elem; /**< pointer to previous element */ 1538 1539 typedef struct CvSeqReader 1540 { 1541 CV_SEQ_READER_FIELDS() 1542 } 1543 CvSeqReader; 1544 1545 /****************************************************************************************/ 1546 /* Operations on sequences */ 1547 /****************************************************************************************/ 1548 1549 #define CV_SEQ_ELEM( seq, elem_type, index ) \ 1550 /** assert gives some guarantee that <seq> parameter is valid */ \ 1551 ( assert(sizeof((seq)->first[0]) == sizeof(CvSeqBlock) && \ 1552 (seq)->elem_size == sizeof(elem_type)), \ 1553 (elem_type*)((seq)->first && (unsigned)index < \ 1554 (unsigned)((seq)->first->count) ? \ 1555 (seq)->first->data + (index) * sizeof(elem_type) : \ 1556 cvGetSeqElem( (CvSeq*)(seq), (index) ))) 1557 #define CV_GET_SEQ_ELEM( elem_type, seq, index ) CV_SEQ_ELEM( (seq), elem_type, (index) ) 1558 1559 /** Add element to sequence: */ 1560 #define CV_WRITE_SEQ_ELEM_VAR( elem_ptr, writer ) \ 1561 { \ 1562 if( (writer).ptr >= (writer).block_max ) \ 1563 { \ 1564 cvCreateSeqBlock( &writer); \ 1565 } \ 1566 memcpy((writer).ptr, elem_ptr, (writer).seq->elem_size);\ 1567 (writer).ptr += (writer).seq->elem_size; \ 1568 } 1569 1570 #define CV_WRITE_SEQ_ELEM( elem, writer ) \ 1571 { \ 1572 assert( (writer).seq->elem_size == sizeof(elem)); \ 1573 if( (writer).ptr >= (writer).block_max ) \ 1574 { \ 1575 cvCreateSeqBlock( &writer); \ 1576 } \ 1577 assert( (writer).ptr <= (writer).block_max - sizeof(elem));\ 1578 memcpy((writer).ptr, &(elem), sizeof(elem)); \ 1579 (writer).ptr += sizeof(elem); \ 1580 } 1581 1582 1583 /** Move reader position forward: */ 1584 #define CV_NEXT_SEQ_ELEM( elem_size, reader ) \ 1585 { \ 1586 if( ((reader).ptr += (elem_size)) >= (reader).block_max ) \ 1587 { \ 1588 cvChangeSeqBlock( &(reader), 1 ); \ 1589 } \ 1590 } 1591 1592 1593 /** Move reader position backward: */ 1594 #define CV_PREV_SEQ_ELEM( elem_size, reader ) \ 1595 { \ 1596 if( ((reader).ptr -= (elem_size)) < (reader).block_min ) \ 1597 { \ 1598 cvChangeSeqBlock( &(reader), -1 ); \ 1599 } \ 1600 } 1601 1602 /** Read element and move read position forward: */ 1603 #define CV_READ_SEQ_ELEM( elem, reader ) \ 1604 { \ 1605 assert( (reader).seq->elem_size == sizeof(elem)); \ 1606 memcpy( &(elem), (reader).ptr, sizeof((elem))); \ 1607 CV_NEXT_SEQ_ELEM( sizeof(elem), reader ) \ 1608 } 1609 1610 /** Read element and move read position backward: */ 1611 #define CV_REV_READ_SEQ_ELEM( elem, reader ) \ 1612 { \ 1613 assert( (reader).seq->elem_size == sizeof(elem)); \ 1614 memcpy(&(elem), (reader).ptr, sizeof((elem))); \ 1615 CV_PREV_SEQ_ELEM( sizeof(elem), reader ) \ 1616 } 1617 1618 1619 #define CV_READ_CHAIN_POINT( _pt, reader ) \ 1620 { \ 1621 (_pt) = (reader).pt; \ 1622 if( (reader).ptr ) \ 1623 { \ 1624 CV_READ_SEQ_ELEM( (reader).code, (reader)); \ 1625 assert( ((reader).code & ~7) == 0 ); \ 1626 (reader).pt.x += (reader).deltas[(int)(reader).code][0]; \ 1627 (reader).pt.y += (reader).deltas[(int)(reader).code][1]; \ 1628 } \ 1629 } 1630 1631 #define CV_CURRENT_POINT( reader ) (*((CvPoint*)((reader).ptr))) 1632 #define CV_PREV_POINT( reader ) (*((CvPoint*)((reader).prev_elem))) 1633 1634 #define CV_READ_EDGE( pt1, pt2, reader ) \ 1635 { \ 1636 assert( sizeof(pt1) == sizeof(CvPoint) && \ 1637 sizeof(pt2) == sizeof(CvPoint) && \ 1638 reader.seq->elem_size == sizeof(CvPoint)); \ 1639 (pt1) = CV_PREV_POINT( reader ); \ 1640 (pt2) = CV_CURRENT_POINT( reader ); \ 1641 (reader).prev_elem = (reader).ptr; \ 1642 CV_NEXT_SEQ_ELEM( sizeof(CvPoint), (reader)); \ 1643 } 1644 1645 /************ Graph macros ************/ 1646 1647 /** Return next graph edge for given vertex: */ 1648 #define CV_NEXT_GRAPH_EDGE( edge, vertex ) \ 1649 (assert((edge)->vtx[0] == (vertex) || (edge)->vtx[1] == (vertex)), \ 1650 (edge)->next[(edge)->vtx[1] == (vertex)]) 1651 1652 1653 1654 /****************************************************************************************\ 1655 * Data structures for persistence (a.k.a serialization) functionality * 1656 \****************************************************************************************/ 1657 1658 /** "black box" file storage */ 1659 typedef struct CvFileStorage CvFileStorage; 1660 1661 /** Storage flags: */ 1662 #define CV_STORAGE_READ 0 1663 #define CV_STORAGE_WRITE 1 1664 #define CV_STORAGE_WRITE_TEXT CV_STORAGE_WRITE 1665 #define CV_STORAGE_WRITE_BINARY CV_STORAGE_WRITE 1666 #define CV_STORAGE_APPEND 2 1667 #define CV_STORAGE_MEMORY 4 1668 #define CV_STORAGE_FORMAT_MASK (7<<3) 1669 #define CV_STORAGE_FORMAT_AUTO 0 1670 #define CV_STORAGE_FORMAT_XML 8 1671 #define CV_STORAGE_FORMAT_YAML 16 1672 1673 /** @brief List of attributes. : 1674 1675 In the current implementation, attributes are used to pass extra parameters when writing user 1676 objects (see cvWrite). XML attributes inside tags are not supported, aside from the object type 1677 specification (type_id attribute). 1678 @see cvAttrList, cvAttrValue 1679 */ 1680 typedef struct CvAttrList 1681 { 1682 const char** attr; /**< NULL-terminated array of (attribute_name,attribute_value) pairs. */ 1683 struct CvAttrList* next; /**< Pointer to next chunk of the attributes list. */ 1684 } 1685 CvAttrList; 1686 1687 /** initializes CvAttrList structure */ 1688 CV_INLINE CvAttrList cvAttrList( const char** attr CV_DEFAULT(NULL), 1689 CvAttrList* next CV_DEFAULT(NULL) ) 1690 { 1691 CvAttrList l; 1692 l.attr = attr; 1693 l.next = next; 1694 1695 return l; 1696 } 1697 1698 struct CvTypeInfo; 1699 1700 #define CV_NODE_NONE 0 1701 #define CV_NODE_INT 1 1702 #define CV_NODE_INTEGER CV_NODE_INT 1703 #define CV_NODE_REAL 2 1704 #define CV_NODE_FLOAT CV_NODE_REAL 1705 #define CV_NODE_STR 3 1706 #define CV_NODE_STRING CV_NODE_STR 1707 #define CV_NODE_REF 4 /**< not used */ 1708 #define CV_NODE_SEQ 5 1709 #define CV_NODE_MAP 6 1710 #define CV_NODE_TYPE_MASK 7 1711 1712 #define CV_NODE_TYPE(flags) ((flags) & CV_NODE_TYPE_MASK) 1713 1714 /** file node flags */ 1715 #define CV_NODE_FLOW 8 /**<Used only for writing structures in YAML format. */ 1716 #define CV_NODE_USER 16 1717 #define CV_NODE_EMPTY 32 1718 #define CV_NODE_NAMED 64 1719 1720 #define CV_NODE_IS_INT(flags) (CV_NODE_TYPE(flags) == CV_NODE_INT) 1721 #define CV_NODE_IS_REAL(flags) (CV_NODE_TYPE(flags) == CV_NODE_REAL) 1722 #define CV_NODE_IS_STRING(flags) (CV_NODE_TYPE(flags) == CV_NODE_STRING) 1723 #define CV_NODE_IS_SEQ(flags) (CV_NODE_TYPE(flags) == CV_NODE_SEQ) 1724 #define CV_NODE_IS_MAP(flags) (CV_NODE_TYPE(flags) == CV_NODE_MAP) 1725 #define CV_NODE_IS_COLLECTION(flags) (CV_NODE_TYPE(flags) >= CV_NODE_SEQ) 1726 #define CV_NODE_IS_FLOW(flags) (((flags) & CV_NODE_FLOW) != 0) 1727 #define CV_NODE_IS_EMPTY(flags) (((flags) & CV_NODE_EMPTY) != 0) 1728 #define CV_NODE_IS_USER(flags) (((flags) & CV_NODE_USER) != 0) 1729 #define CV_NODE_HAS_NAME(flags) (((flags) & CV_NODE_NAMED) != 0) 1730 1731 #define CV_NODE_SEQ_SIMPLE 256 1732 #define CV_NODE_SEQ_IS_SIMPLE(seq) (((seq)->flags & CV_NODE_SEQ_SIMPLE) != 0) 1733 1734 typedef struct CvString 1735 { 1736 int len; 1737 char* ptr; 1738 } 1739 CvString; 1740 1741 /** All the keys (names) of elements in the readed file storage 1742 are stored in the hash to speed up the lookup operations: */ 1743 typedef struct CvStringHashNode 1744 { 1745 unsigned hashval; 1746 CvString str; 1747 struct CvStringHashNode* next; 1748 } 1749 CvStringHashNode; 1750 1751 typedef struct CvGenericHash CvFileNodeHash; 1752 1753 /** Basic element of the file storage - scalar or collection: */ 1754 typedef struct CvFileNode 1755 { 1756 int tag; 1757 struct CvTypeInfo* info; /**< type information 1758 (only for user-defined object, for others it is 0) */ 1759 union 1760 { 1761 double f; /**< scalar floating-point number */ 1762 int i; /**< scalar integer number */ 1763 CvString str; /**< text string */ 1764 CvSeq* seq; /**< sequence (ordered collection of file nodes) */ 1765 CvFileNodeHash* map; /**< map (collection of named file nodes) */ 1766 } data; 1767 } 1768 CvFileNode; 1769 1770 #ifdef __cplusplus 1771 extern "C" { 1772 #endif 1773 typedef int (CV_CDECL *CvIsInstanceFunc)( const void* struct_ptr ); 1774 typedef void (CV_CDECL *CvReleaseFunc)( void** struct_dblptr ); 1775 typedef void* (CV_CDECL *CvReadFunc)( CvFileStorage* storage, CvFileNode* node ); 1776 typedef void (CV_CDECL *CvWriteFunc)( CvFileStorage* storage, const char* name, 1777 const void* struct_ptr, CvAttrList attributes ); 1778 typedef void* (CV_CDECL *CvCloneFunc)( const void* struct_ptr ); 1779 #ifdef __cplusplus 1780 } 1781 #endif 1782 1783 /** @brief Type information 1784 1785 The structure contains information about one of the standard or user-defined types. Instances of the 1786 type may or may not contain a pointer to the corresponding CvTypeInfo structure. In any case, there 1787 is a way to find the type info structure for a given object using the cvTypeOf function. 1788 Alternatively, type info can be found by type name using cvFindType, which is used when an object 1789 is read from file storage. The user can register a new type with cvRegisterType that adds the type 1790 information structure into the beginning of the type list. Thus, it is possible to create 1791 specialized types from generic standard types and override the basic methods. 1792 */ 1793 typedef struct CvTypeInfo 1794 { 1795 int flags; /**< not used */ 1796 int header_size; /**< sizeof(CvTypeInfo) */ 1797 struct CvTypeInfo* prev; /**< previous registered type in the list */ 1798 struct CvTypeInfo* next; /**< next registered type in the list */ 1799 const char* type_name; /**< type name, written to file storage */ 1800 CvIsInstanceFunc is_instance; /**< checks if the passed object belongs to the type */ 1801 CvReleaseFunc release; /**< releases object (memory etc.) */ 1802 CvReadFunc read; /**< reads object from file storage */ 1803 CvWriteFunc write; /**< writes object to file storage */ 1804 CvCloneFunc clone; /**< creates a copy of the object */ 1805 } 1806 CvTypeInfo; 1807 1808 1809 /**** System data types ******/ 1810 1811 typedef struct CvPluginFuncInfo 1812 { 1813 void** func_addr; 1814 void* default_func_addr; 1815 const char* func_names; 1816 int search_modules; 1817 int loaded_from; 1818 } 1819 CvPluginFuncInfo; 1820 1821 typedef struct CvModuleInfo 1822 { 1823 struct CvModuleInfo* next; 1824 const char* name; 1825 const char* version; 1826 CvPluginFuncInfo* func_tab; 1827 } 1828 CvModuleInfo; 1829 1830 /** @} */ 1831 1832 #endif /*__OPENCV_CORE_TYPES_H__*/ 1833 1834 /* End of file. */ 1835