modules/core/include/opencv2/core/types_c.h
前面的是一些宏定义,是为了兼容C,C++。对于一些函数的调用方式,建议补充一点补充知识:http://blog.csdn.net/yongdun_007/archive/2010/12/21/6090281.aspx,
这个头文件是很重要的一个文件,建议大家都看看,这里定义了opencv用到的所有的数据类型和结构。详细如下: types_c.h包括:常用的宏指令和内联函数,随机数的生成,图像数据类型,矩阵数据类型,多维稠密矩阵,多维稀疏矩阵,稀疏矩阵迭代,直方图,其他数据类型定义(包括矩形,终止准则,点和变量,size变量和Box变量,片和部分,尺度或者角度),动态数据结构(包括内存存储,序列,节点或者集,图结构,链和轮廓),序列类型,序列的读/写操作,对序列的操作(包括图的微操作),保持数据结构的稳定性,系统数据类型。
常用的宏指令和内联函数
#define CV_PI 3.1415926535897932384626433832795//定义PI大小
#define CV_LOG2 0.69314718055994530941723212145818//定义log2
#define CV_SWAP(a,b,t) ((t) = (a), (a) = (b), (b) = (t))//交换a,b
#ifndef MIN #define MIN(a,b) ((a) > (b) ? (b) : (a))//求a,b最小值
#endif #ifndef MAX #define MAX(a,b) ((a) < (b) ? (b) : (a))//求a,b最大值
#endif /* min & max without jumps */
#define CV_IMIN(a, b) ((a) ^ (((a)^(b)) & (((a) < (b)) - 1)))
//
#define CV_IMAX(a, b) ((a) ^ (((a)^(b)) & (((a) > (b)) - 1)))
//
/* absolute value without jumps */
#ifndef __cplusplus #define CV_IABS(a) (((a) ^ ((a) < 0 ? -1 : 0)) - ((a) < 0 ? -1 : 0))
#else
#define CV_IABS(a) abs(a)
#endif
#define CV_CMP(a,b) (((a) > (b)) - ((a) < (b)))
#define CV_SIGN(a) CV_CMP((a),0)
// 返回和参数最接近的整数值 CV_INLINE int cvRound( double value )
//返回不大于参数的最大整数值 CV_INLINE int cvFloor( double value )
//返回不小于参数的最小整数值 CV_INLINE int cvCeil( double value )
//对参数开平方并进行求倒
#define cvInvSqrt(value) ((float)(1./sqrt(value)))
//对参数开平方
#define cvSqrt(value) ((float)sqrt(value))
//判定是否为合法数 CV_INLINE int cvIsNaN( double value )
//判定是否为无穷 CV_INLINE int cvIsInf( double value )
随机数的生成
typedef uint64 CvRNG;
//初始化随机数生成器状态 CV_INLINE CvRNG cvRNG( int64 seed CV_DEFAULT(-1))
//返回32位无符号整型并更新RNG CV_INLINE unsigned cvRandInt( CvRNG* rng )
//返回浮点型随机数并更新RNG CV_INLINE double cvRandReal( CvRNG* rng )
图像数据类型
#ifndef HAVE_IPL
/* * The following definitions (until #endif)
* is an extract from IPL headers.
* Copyright (c) 1995 Intel Corporation.
*/
//定义深度位数
#define IPL_DEPTH_SIGN 0x80000000
#define IPL_DEPTH_1U 1
#define IPL_DEPTH_8U 8
#define IPL_DEPTH_16U 16
#define IPL_DEPTH_32F 32
//定义有符号深度位数
#define IPL_DEPTH_8S (IPL_DEPTH_SIGN| 8)
#define IPL_DEPTH_16S (IPL_DEPTH_SIGN|16)
#define IPL_DEPTH_32S (IPL_DEPTH_SIGN|32)
//定义数据顺序
#define IPL_DATA_ORDER_PIXEL 0
#define IPL_DATA_ORDER_PLANE 1
//定义图像原点位置
#define IPL_ORIGIN_TL 0 //左上
#define IPL_ORIGIN_BL 1 //左下
//定义扫描线位数
#define IPL_ALIGN_4BYTES 4
#define IPL_ALIGN_8BYTES 8
#define IPL_ALIGN_16BYTES 16
#define IPL_ALIGN_32BYTES 32
//定义扫描线对齐
#define IPL_ALIGN_DWORD IPL_ALIGN_4BYTES
#define IPL_ALIGN_QWORD IPL_ALIGN_8BYTES
//定义扫描线宽度状态
#define IPL_BORDER_CONSTANT 0 //扫描线连续
#define IPL_BORDER_REPLICATE 1 //双扫描线
#define IPL_BORDER_REFLECT 2 //带阴影扫描线
#define IPL_BORDER_WRAP 3 //波浪扫描线
//定义图像结构体
typedef struct _IplImage
{
int nSize; /* sizeof(IplImage) */
int ID; /* version (=0)*/
int nChannels; /* Most of OpenCV functions support 1,2,3 or 4 channels */
int alphaChannel; /* Ignored by OpenCV */
int depth; /* Pixel depth in bits: IPL_DEPTH_8U, IPL_DEPTH_8S, IPL_DEPTH_16S, IPL_DEPTH_32S,IPL_DEPTH_32F and IPL_DEPTH_64F are supported. */
char colorModel[4]; /* Ignored by OpenCV */
char channelSeq[4]; /* ditto */
int dataOrder; /* 0 - interleaved color channels, 1 - separate color channels. cvCreateImage can only create interleaved images */
int origin; /* 0 - top-left origin, 1 - bottom-left origin (Windows bitmaps style). */
int align; /* Alignment of image rows (4 or 8). OpenCV ignores it and uses widthStep instead. */
int width; /* Image width in pixels. */
int height; /* Image height in pixels. */
struct _IplROI *roi; /* Image ROI. If NULL, the whole image is selected. */
struct _IplImage *maskROI; /* Must be NULL. */
void *imageId; /* " " */
struct _IplTileInfo *tileInfo; /* " " */
int imageSize; /* Image data size in bytes (==image->height*image->widthStep in case of interleaved data)*/
char *imageData; /* Pointer to aligned image data. */
int widthStep; /* Size of aligned image row in bytes. */
int BorderMode[4]; /* Ignored by OpenCV. */
int BorderConst[4]; /* Ditto. */
char *imageDataOrigin; /* Pointer to very origin of image data (not necessarily aligned) - needed for correct deallocation */
} IplImage;
//定义图像分块信息结构体 typedef struct _IplTileInfo IplTileInfo;
//定义图像感兴趣区域
typedef struct _IplROI
{
int coi; /* 0 - no COI (all channels are selected), 1 - 0th channel is selected ...*/ //感兴趣通道
int xOffset; //X坐标值
int yOffset; //y坐标值
int width; //感兴趣区域宽度
int height; //感兴趣区域高度
} IplROI;
//定义卷积核结构体
typedef struct _IplConvKernel
{
int nCols;
int nRows;
int anchorX;
int anchorY;
int *values;
int nShiftR;
} IplConvKernel;
//定义快速卷积核结构体
typedef struct _IplConvKernelFP
{
int nCols;
int nRows;
int anchorX;
int anchorY;
float *values;
} IplConvKernelFP;
#define IPL_IMAGE_HEADER 1
#define IPL_IMAGE_DATA 2
#define IPL_IMAGE_ROI 4
#endif/*HAVE_IPL*/
//定义边界模式
#define IPL_BORDER_REFLECT_101 4 //带有阴影
#define IPL_BORDER_TRANSPARENT 5 //透明
#define IPL_IMAGE_MAGIC_VAL ((int)sizeof(IplImage))
#define CV_TYPE_NAME_IMAGE "opencv-image"
#define CV_IS_IMAGE_HDR(img) / ((img) != NULL && ((const IplImage*)(img))->nSize == sizeof(IplImage))
#define CV_IS_IMAGE(img) / (CV_IS_IMAGE_HDR(img) && ((IplImage*)img)->imageData != NULL)
//定义存储在图像的双精度数据 #define IPL_DEPTH_64F 64
//定义从给定图像,给定数据类型,给定坐标(col,row)获取图像像素值
#define CV_IMAGE_ELEM( image, elemtype, row, col ) / (((elemtype*)((image)->imageData + (image)->widthStep*(row)))[(col)])
矩阵数据类型
//
#define CV_CN_MAX 512
//定义矩阵数据最大值 #define CV_CN_SHIFT 3
//
#define CV_DEPTH_MAX (1 << CV_CN_SHIFT)
//定义矩阵数据类型
#define CV_8U 0
#define CV_8S 1
#define CV_16U 2
#define CV_16S 3
#define CV_32S 4
#define CV_32F 5
#define CV_64F 6
#define CV_USRTYPE1 7
//
#define CV_MAT_DEPTH_MASK (CV_DEPTH_MAX - 1)
#define CV_MAT_DEPTH(flags) ((flags) & CV_MAT_DEPTH_MASK)
//
#define CV_MAKETYPE(depth,cn) (CV_MAT_DEPTH(depth) + (((cn)-1) << CV_CN_SHIFT))
#define CV_MAKE_TYPE CV_MAKETYPE
//
#define CV_8UC1 CV_MAKETYPE(CV_8U,1