openCV library for Renesas RZ/A

Dependents:   RZ_A2M_Mbed_samples

Committer:
RyoheiHagimoto
Date:
Fri Jan 29 04:53:38 2021 +0000
Revision:
0:0e0631af0305
copied from https://github.com/d-kato/opencv-lib.

Who changed what in which revision?

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