base.h处于core模块中,是OpenCV的核心类。其作用是定义了OpenCV的基本错误类型,在程序运行出现错误是抛出错误,防止数据溢出。总而言之,其功能主要是考虑程序的健壮性。
头文件
#ifndef __OPENCV_CORE_BASE_HPP__
#define __OPENCV_CORE_BASE_HPP__
#ifndef __cplusplus
# error base.hpp header must be compiled as C++
#endif
#include <climits>
#include "opencv2/core/cvdef.h"
#include "opencv2/core/cvstd.hpp"
namespace cv
{
和其他程序一样,base.h中包含头文件cvdef.h,和cvstd.hpp。从名字中就可以读出,base.hpp,是一个.hpp类型的文件,它既包含了声明,又包含了定义(h+cpp)。
namespace Error {
enum {
StsOk= 0, /* everithing is ok */
StsBackTrace= -1, /* pseudo error for back trace */
StsError= -2, /* unknown /unspecified error */
StsInternal= -3, /* internal error (bad state) */
StsNoMem= -4, /* insufficient memory */
StsBadArg= -5, /* function arg/param is bad */
StsBadFunc= -6, /* unsupported function */
StsNoConv= -7, /* iter. didn't converge */
StsAutoTrace= -8, /* tracing */
HeaderIsNull= -9, /* image header is NULL */
BadImageSize= -10, /* image size is invalid */
BadOffset= -11, /* offset is invalid */
BadDataPtr= -12, /**/
BadStep= -13, /**/
BadModelOrChSeq= -14, /**/
BadNumChannels= -15, /**/
BadNumChannel1U= -16, /**/
BadDepth= -17, /**/
BadAlphaChannel= -18, /**/
BadOrder= -19, /**/
BadOrigin= -20, /**/
BadAlign= -21, /**/
BadCallBack= -22, /**/
BadTileSize= -23, /**/
BadCOI= -24, /**/
BadROISize= -25, /**/
MaskIsTiled= -26, /**/
StsNullPtr= -27, /* null pointer */
StsVecLengthErr= -28, /* incorrect vector length */
StsFilterStructContentErr= -29, /* incorr. filter structure content */
StsKernelStructContentErr= -30, /* incorr. transform kernel content */
StsFilterOffsetErr= -31, /* incorrect filter ofset value */
StsBadSize= -201, /* the input/output structure size is incorrect */
StsDivByZero= -202, /* division by zero */
StsInplaceNotSupported= -203, /* in-place operation is not supported */
StsObjectNotFound= -204, /* request can't be completed */
StsUnmatchedFormats= -205, /* formats of input/output arrays differ */
StsBadFlag= -206, /* flag is wrong or not supported */
StsBadPoint= -207, /* bad CvPoint */
StsBadMask= -208, /* bad format of mask (neither 8uC1 nor 8sC1)*/
StsUnmatchedSizes= -209, /* sizes of input/output structures do not match */
StsUnsupportedFormat= -210, /* the data format/type is not supported by the function*/
StsOutOfRange= -211, /* some of parameters are out of range */
StsParseError= -212, /* invalid syntax/structure of the parsed file */
StsNotImplemented= -213, /* the requested function/feature is not implemented */
StsBadMemBlock= -214, /* an allocated block has been corrupted */
StsAssert= -215, /* assertion failed */
GpuNotSupported= -216,
GpuApiCallError= -217,
OpenGlNotSupported= -218,
OpenGlApiCallError= -219,
OpenCLApiCallError= -220,
OpenCLDoubleNotSupported= -221,
OpenCLInitError= -222,
OpenCLNoAMDBlasFft= -223
};
} //Error
首先为error专门开了一个namespace,这里用枚举类型的方式定义了错误的类型,这样就把ID和名称联系在了一起,之后只要使用错误的名称就可以调用错误的ID了,增强程序的可读性。
enum { DECOMP_LU = 0,
DECOMP_SVD = 1,
DECOMP_EIG = 2,
DECOMP_CHOLESKY = 3,
DECOMP_QR = 4,
DECOMP_NORMAL = 16
};
矩阵的分解方式
enum { NORM_INF = 1,
NORM_L1 = 2,
NORM_L2 = 4,
NORM_L2SQR = 5,
NORM_HAMMING = 6,
NORM_HAMMING2 = 7,
NORM_TYPE_MASK = 7,
NORM_RELATIVE = 8,
NORM_MINMAX = 32
};
正规化的类型
enum { CMP_EQ = 0,
CMP_GT = 1,
CMP_GE = 2,
CMP_LT = 3,
CMP_LE = 4,
CMP_NE = 5
};
比较的类型
enum { GEMM_1_T = 1,
GEMM_2_T = 2,
GEMM_3_T = 4
};
enum { DFT_INVERSE = 1,
DFT_SCALE = 2,
DFT_ROWS = 4,
DFT_COMPLEX_OUTPUT = 16,
DFT_REAL_OUTPUT = 32,
DCT_INVERSE = DFT_INVERSE,
DCT_ROWS = DFT_ROWS
};
//! Various border types, image boundaries are denoted with '|'
enum {
BORDER_CONSTANT = 0, // iiiiii|abcdefgh|iiiiiii with some specified 'i'
BORDER_REPLICATE = 1, // aaaaaa|abcdefgh|hhhhhhh
BORDER_REFLECT = 2, // fedcba|abcdefgh|hgfedcb
BORDER_WRAP = 3, // cdefgh|abcdefgh|abcdefg
BORDER_REFLECT_101 = 4, // gfedcb|abcdefgh|gfedcba
BORDER_TRANSPARENT = 5, // uvwxyz|absdefgh|ijklmno
BORDER_REFLECT101 = BORDER_REFLECT_101,
BORDER_DEFAULT = BORDER_REFLECT_101,
BORDER_ISOLATED = 16 // do not look outside of ROI
};
这些都大同小异,通过枚举类的方式实现变量名和ID的替换。
//////////////// static assert /////////////////
#define CVAUX_CONCAT_EXP(a, b) a##b