2  modules\core\include\opencv2\core\core_c.h
这个需要头文件 #include  “opencv2/core/types_c.h”

core_c.h 包括:数组的分配、释放、初始化和对数组元素的访问(包括矩阵迭代器:在稠密矩阵用n-ary操作子),算术、逻辑和比较操作,匹配操作,矩阵操作,数组统计,离散线性变换和相关函数,动态数据结构(包括内部序列函数),画图(包括通过序列树进行迭代), 系统函数,保留数据(包括高层函数, 添加自己类型,计算运行时间函数, CPU性能, 多线程, 错误句柄)

数组的分配、释放、初始化和对数组元素的访问

CVAPI(void*)  cvAlloc( size_tsize );//<malloc>触发器,如果没有足够内存空间报错(像其他的openCV函数回调cvAlloc)
 
CVAPI(void)   cvFree_( void*ptr );
#define cvFree(ptr) (cvFree_(*(ptr)),*(ptr)=0)//<free>触发器,释放内存空间后,采用double指针来清除数据指针
CVAPI(IplImage*)  cvCreateImageHeader(CvSize size, int depth, intchannels );//分配和初始化IplImage头指针
CVAPI(IplImage*) cvInitImageHeader(IplImage* image, CvSize size, intdepth,int channels, int originCV_DEFAULT(0),                                 int alignCV_DEFAULT(4));//初始化IplImage头指针
 
CVAPI(IplImage*)  cvCreateImage(CvSize size, int depth, int channels );//创建IPL图像(图像和数据)
 
CVAPI(void)  cvReleaseImageHeader(IplImage** image );//释放IPL图像头
CVAPI(void)  cvReleaseImage(IplImage** image );//释放IPL头指针和数据
CVAPI(IplImage*) cvCloneImage( const IplImage*image );//创建IPL头拷贝(步长根据不同情况不同)
CVAPI(void)  cvSetImageCOI(IplImage* image, int coi );//设置感兴趣的通道(但是只有很少的函数支持COI),采用cvCopy来取出(或者放回)已选定的通道
CVAPI(int)  cvGetImageCOI( const IplImage*image );//恢复图像感兴趣的通道
CVAPI(void)  cvSetImageROI(IplImage* image, CvRect rect );//设置图像感兴趣区域(感兴趣通道不变)
CVAPI(void)  cvResetImageROI(IplImage* image );//重设置图像的感兴趣区域(ROI)和感兴趣通道(COI)
CVAPI(CvRect) cvGetImageROI( const IplImage*image );//恢复图像ROI
CVAPI(CvMat*)  cvCreateMatHeader( int rows, int cols, int type);//分配和初始化CvMat头
#define CV_AUTOSTEP  0x7fffffff
CVAPI(CvMat*) cvInitMatHeader( CvMat* mat, int rows, int cols,inttype, void*dataCV_DEFAULT(NULL),                            intstepCV_DEFAULT(CV_AUTOSTEP) );//初始化CvMat头
CVAPI(CvMat*)  cvCreateMat( int rows, int cols, int type);//分配和初始化CvMat头和分配数据
CVAPI(void)  cvReleaseMat(CvMat** mat );//释放CvMat头和重新分配矩阵头(reference计算数据数量)
 
CV_INLINE  void  cvDecRefData(CvArr* arr )//缩减CvMat数据reference计算器和如果达到0则重分配数据
{
    if( CV_IS_MAT( arr))
    {
        CvMat*mat = (CvMat*)arr;
        mat->data.ptr= NULL;
        if(mat->refcount != NULL && --*mat->refcount == 0 )
            cvFree(&mat->refcount );
        mat->refcount= NULL;
    }
    else if(CV_IS_MATND( arr ))
    {
        CvMatND*mat = (CvMatND*)arr;
        mat->data.ptr= NULL;
        if(mat->refcount != NULL && --*mat->refcount == 0 )
            cvFree(&mat->refcount );
        mat->refcount= NULL;
    }
}
 
CV_INLINE  int  cvIncRefData(CvArr* arr )//增加CvMat数据reference计算器
{
    int refcount =0;
    if( CV_IS_MAT( arr))
    {
        CvMat*mat = (CvMat*)arr;
        if(mat->refcount != NULL )
            refcount= ++*mat->refcount;
    }
    else if(CV_IS_MATND( arr ))
    {
        CvMatND*mat = (CvMatND*)arr;
        if(mat->refcount != NULL )
            refcount= ++*mat->refcount;
    }
    return refcount;
}
 
 
CVAPI(CvMat*) cvCloneMat( const CvMat*mat );//创建输入矩阵(或者步长)的精确拷贝
 
CVAPI(CvMat*) cvGetSubRect( const CvArr*arr, CvMat* submat, CvRect rect );//通过输入的数组的的矩形(或者子矩形)大小来创建一个新的矩阵(数据不会被拷贝)
#define cvGetSubArr cvGetSubRect
 
CVAPI(CvMat*) cvGetRows( const CvArr*arr, CvMat*submat,                        int start_row, int end_row,int delta_rowCV_DEFAULT(1));//选择输入数组的行跨度(开始行:步长:结束行),结束行不包括跨度
 
CV_INLINE  CvMat*  cvGetRow( const CvArr*arr, CvMat* submat, int row )
{
    return cvGetRows(arr, submat, row, row + 1, 1 );
}
 
 
CVAPI(CvMat*) cvGetCols( const CvArr*arr, CvMat* submat,
int start_col, int end_col);//选择输入数组的列跨度:(:,开始列:结束列)(结束列不包括进跨度)
 
CV_INLINE  CvMat*  cvGetCol( const CvArr*arr, CvMat* submat, int col )
{
    return cvGetCols(arr, submat, col, col + 1 );
}
 
 
CVAPI(CvMat*) cvGetDiag( const CvArr* arr,CvMat*submat,                            intdiag CV_DEFAULT(0));//选择输入数组的diagonal,如果diag=0,表示主对角线;如果diag>0,表示上对角;如果diag<0,表示下对角
 
CVAPI(void) cvScalarToRawData( const CvScalar*scalar, void* data,int type,int extend_to_12 CV_DEFAULT(0) );//低层尺度<->原始数据转换函数
 
CVAPI(void) cvRawDataToScalar( const void*data, int type, CvScalar* scalar );
 
CVAPI(CvMatND*)  cvCreateMatNDHeader( int dims, const int*sizes, inttype );//分配和初始化CvMatND头
 
CVAPI(CvMatND*)  cvCreateMatND( int dims, const int*sizes, int type );//分配和初始化CvMatND头和分配数据
 
CVAPI(CvMatND*)  cvInitMatNDHeader(CvMatND* mat, int dims, constint* sizes,int type, void*data CV_DEFAULT(NULL) );//初始化重分配的CvMatND头
 
CV_INLINE  void  cvReleaseMatND(CvMatND** mat )//释放CvMatND
{
    cvReleaseMat((CvMat**)mat );
}
 
CVAPI(CvMatND*) cvCloneMatND( const CvMatND*mat );//新建CvMatND(或者步长)的拷贝
 
CVAPI(CvSparseMat*)  cvCreateSparseMat( int dims, const int*sizes,int type );//分配和初始化CvSparseMat头和分配数据
 
CVAPI(void)  cvReleaseSparseMat(CvSparseMat** mat );//释放CvSparseMat
 
CVAPI(CvSparseMat*) cvCloneSparseMat( const CvSparseMat*mat );//新建一个CvSparseMat(或者0 items)的拷贝
 
CVAPI(CvSparseNode*)cvInitSparseMatIterator( const CvSparseMat* mat,CvSparseMatIterator*mat_iterator );//初始化稀疏矩阵迭代器,返回第一个节点(如果为空,则返回NULL)
 
CV_INLINE CvSparseNode*cvGetNextSparseNode( CvSparseMatIterator* mat_iterator )//返回下一稀疏矩阵节点(如果没有更多的节点,则返回NULL)
{
    if(mat_iterator->node->next )
        return mat_iterator->node= mat_iterator->node->next;
    else
    {
        int idx;
        for(idx = ++mat_iterator->curidx; idx < mat_iterator->mat->hashsize;idx++ )
        {
            CvSparseNode*node = (CvSparseNode*)mat_iterator->mat->hashtable[idx];
            if(node )
            {
                mat_iterator->curidx= idx;
                return mat_iterator->node= node;
            }
        }
        return NULL;
    }
}
 
数组的分配、释放、初始化和对数组元素的访问---矩阵迭代器:在稠密矩阵用n-ary操作子
 
#define CV_MAX_ARR 10
 
//定义稀疏矩阵迭代结构体
typedef struct CvNArrayIterator
{
    int count;
    int dims;
    CvSize size;
    uchar*ptr[CV_MAX_ARR];
    int stack[CV_MAX_DIM];
    CvMatND*hdr[CV_MAX_ARR];
}
CvNArrayIterator;
 
#define CV_NO_DEPTH_CHECK     1
#define CV_NO_CN_CHECK        2
#define CV_NO_SIZE_CHECK      4
 
CVAPI(int) cvInitNArrayIterator( int count,CvArr**arrs,                               const CvArr*mask, CvMatND* stubs,                              CvNArrayIterator*array_iterator,                                int flagsCV_DEFAULT(0) );//通过一些数组初始化迭代器(和cvNextArraySlice函数一起用于N-ari元素操作)
 
CVAPI(int) cvNextNArraySlice(CvNArrayIterator* array_iterator );//如果迭代结束返回0,否则返回非0数
 
CVAPI(int) cvGetElemType( const CvArr*arr );//返回数组元素的类型,比如CV_8UC1, CV_64FC4等
 
CVAPI(int) cvGetDims( const CvArr*arr, int* sizes CV_DEFAULT(NULL) );//获取数组维数值和维数大小
 
CVAPI(int) cvGetDimSize( const CvArr*arr, int index );//获取给定数组维数值的大小,比如2D数组 cvGetDimSize(arr,0)返回行值(图像的高度),cvGetDimSize(arr,1)返回列值(图像的宽度)
 
CVAPI(uchar*) cvPtr1D( const CvArr*arr, int idx0, int* typeCV_DEFAULT(NULL));//ptr=&arr(idx0,idx1,…),所有索引值为0,维数从高到低,比如2D表示为(y,x),3D表示为(z,y,x)
 
CVAPI(uchar*) cvPtr2D( const CvArr*arr, int idx0, int idx1, int* type CV_DEFAULT(NULL) );
CVAPI(uchar*) cvPtr3D( const CvArr*arr, int idx0, int idx1, intidx2,int* typeCV_DEFAULT(NULL));
 
CVAPI(uchar*) cvPtrND( const CvArr*arr, const int* idx, int* type CV_DEFAULT(NULL),int create_nodeCV_DEFAULT(1),                      unsigned*precalc_hashval CV_DEFAULT(NULL));//对于CvMat或者IplImage索引值首先为行索引(y),其次为列索引(x);对于CvMatND或者CvSparseMat索引值应当与维数值相匹配,并且索引值的顺序应当和维数顺序相匹配
 
 
CVAPI(CvScalar) cvGet1D( const CvArr*arr, int idx0 );
CVAPI(CvScalar) cvGet2D( const CvArr*arr, int idx0, int idx1 );
CVAPI(CvScalar) cvGet3D( const CvArr*arr, int idx0, int idx1, intidx2 );
CVAPI(CvScalar) cvGetND( const CvArr*arr, const int* idx );
 
 
CVAPI(double) cvGetReal1D( const CvArr*arr, int idx0 );
CVAPI(double) cvGetReal2D( const CvArr*arr, int idx0, int idx1 );
CVAPI(double) cvGetReal3D( const CvArr*arr, int idx0, int idx1, intidx2 );
CVAPI(double) cvGetRealND( const CvArr*arr, const int* idx );
 
 
CVAPI(void) cvSet1D( CvArr* arr, int idx0,CvScalar value );
CVAPI(void) cvSet2D( CvArr* arr, int idx0, int idx1,CvScalar value );
CVAPI(void) cvSet3D( CvArr* arr, int idx0, int idx1, int idx2,CvScalar value );
CVAPI(void) cvSetND( CvArr* arr, const int*idx, CvScalar value );
 
 
CVAPI(void) cvSetReal1D( CvArr* arr, int idx0, double value);
CVAPI(void) cvSetReal2D( CvArr* arr, int idx0, int idx1, double value);
CVAPI(void) cvSetReal3D( CvArr* arr, int idx0,
                        int idx1, int idx2, double value);
CVAPI(void) cvSetRealND( CvArr* arr, const int*idx, double value );
 
CVAPI(void) cvClearND( CvArr* arr, const int*idx );//清除N维稠密矩阵元素;如果是稀疏矩阵,则删除给定节点
 
CVAPI(CvMat*) cvGetMat( const CvArr*arr, CvMat*header,                       int*coi CV_DEFAULT(NULL),int allowND CV_DEFAULT(0));//将CvMat(IplImage,CvMat,…)转换成CvMat。如果最后的参数为0,在数组最后维连续的情况下,可以将多维矩阵转换成CvMat,最后转换的矩阵的行数将很大。
 
CVAPI(IplImage*) cvGetImage( const CvArr*arr, IplImage* image_header );//CvArr(IplImage,CvMat)转换成IplImage
 
 
CVAPI(CvArr*) cvReshapeMatND( const CvArr*arr,                           int sizeof_header,CvArr* header,int new_cn, int new_dims, int* new_sizes );//改变多维数组的形状:new_cn== 0表示通道数不变;new_dims == 0表示维数大小不变(除非需要设置新的通道数);如果new_dims == 1,不需要特定指定维数的大小。最后结果配置为w/o数据拷贝完成。如果最后结果数组为稀疏,数组头应满足CvSparseMat;如果结果为1火星和2维,数组头应满足CvMat;如果是稠密数组,数组头应满足CvMatND
 
#define cvReshapeND( arr, header,new_cn, new_dims, new_sizes )  cvReshapeMatND( (arr), sizeof(*(header)),(header),(new_cn), (new_dims), (new_sizes))
 
CVAPI(CvMat*) cvReshape( const CvArr*arr, CvMat* header,                       int new_cn, int new_rowsCV_DEFAULT(0) );
 
CVAPI(void) cvRepeat( const CvArr*src, CvArr* dst );//将原始2维数组经过几次水平和垂直方向填满目标数组
 
CVAPI(void)  cvCreateData( CvArr*arr );//创建和配置数组数据
 
CVAPI(void)  cvReleaseData(CvArr* arr );//释放数组数据
 
CVAPI(void)  cvSetData( CvArr*arr, void* data, int step );//将用户数据添加到数组头部,指针指向上一最后维。即所有数组维和w/o接口连接
 
CVAPI(void) cvGetRawData( const CvArr*arr, uchar** data,
int* step CV_DEFAULT(NULL),CvSize* roi_sizeCV_DEFAULT(NULL));//获取CvMat,IplImage,CvMatND的原始数据,如果数组不能表示为矩阵,则该函数报错
 
CVAPI(CvSize) cvGetSize( const CvArr*arr );//返回数组元素的宽度和高度
 
CVAPI(void)  cvCopy( const CvArr*src, CvArr* dst,                 const CvArr*mask CV_DEFAULT(NULL) );//将源数组拷贝到目标数组
 
CVAPI(void)  cvSet( CvArr* arr,CvScalarvalue,                   const CvArr*mask CV_DEFAULT(NULL) );//设置所有或者被标记的输入数组的元素为相同值
 
CVAPI(void)  cvSetZero( CvArr*arr );//清除所有数组元素(设置为0)
#define cvZero  cvSetZero
 
CVAPI(void)  cvSplit( const CvArr*src, CvArr* dst0, CvArr* dst1,CvArr* dst2, CvArr* dst3 );//将多通道数组分成单通道数组或者获取单一颜色通道
 
CVAPI(void)  cvMerge( const CvArr*src0, const CvArr* src1,
const CvArr* src2, const CvArr*src3,CvArr* dst );//将单通道数组合并成一个多通道数组,或者插入单一颜色通道
 
CVAPI(void)  cvMixChannels( const CvArr**src, int src_count,CvArr** dst, int dst_count,const int*from_to, int pair_count );//从输入数组拷贝通道到输入数组的特定通道
 
CVAPI(void)  cvConvertScale( const CvArr*src, CvArr*dst,                            double scaleCV_DEFAULT(1),double shift CV_DEFAULT(0) );//完成在源数组上的线性变换:dst=scale*src(x,y,z)+shift.允许连接输入和输出数组的深度(通道数必须相同),故可实现类型转换
#define cvCvtScale cvConvertScale
#define cvScale  cvConvertScale
#define cvConvert( src, dst )  cvConvertScale((src), (dst), 1, 0 )
 
 
CVAPI(void)  cvConvertScaleAbs( const CvArr*src, CvArr* dst,doublescale CV_DEFAULT(1),double shift CV_DEFAULT(0) );//完成在每个源数组上的绝对线性变换:dst(x,y,z)=abs(scale*src(x,y,z)+shift),目标数组必须为8u 类型,其他类型可以使用cvConvertScale+cvAbsDiffS
#define cvCvtScaleAbs  cvConvertScaleAbs
 
CVAPI(CvTermCriteria) cvCheckTermCriteria(CvTermCriteria criteria,double default_eps,int default_max_iters );//确保终止规则有效性和设置eps为default_eps(如果没有设置),设置max_iter为default_max_iters(如果没有设置)
 
 
算术、逻辑和比较操作
CVAPI(void)  cvAdd( const CvArr*src1, const CvArr* src2, CvArr* dst,const CvArr* maskCV_DEFAULT(NULL));
 
CVAPI(void)  cvAddS( const CvArr*src, CvScalar value, CvArr* dst,const CvArr* mask CV_DEFAULT(NULL));
 
CVAPI(void)  cvSub( const CvArr*src1, const CvArr* src2, CvArr* dst,const CvArr* maskCV_DEFAULT(NULL));
 
 CV_INLINE  void  cvSubS( const CvArr*src, CvScalar value, CvArr* dst,const CvArr* mask CV_DEFAULT(NULL))
{
    cvAddS( src,cvScalar( -value.val[0], -value.val[1], -value.val[2], -value.val[3]),dst, mask);
}
 
 CVAPI(void)  cvSubRS( const CvArr*src, CvScalar value, CvArr* dst,const CvArr* mask CV_DEFAULT(NULL));
 
CVAPI(void)  cvMul( const CvArr*src1, const CvArr*src2,                  CvArr*dst, double scale CV_DEFAULT(1) );
 
 CVAPI(void)  cvDiv( const CvArr*src1, const CvArr*src2,                   CvArr*dst, double scale CV_DEFAULT(1));
 
 CVAPI(void)  cvScaleAdd( const CvArr*src1, CvScalarscale,                        const CvArr*src2, CvArr* dst );
#define cvAXPY( A, real_scalar, B, C )cvScaleAdd(A, cvRealScalar(real_scalar), B, C)
 
 
CVAPI(void)  cvAddWeighted( const CvArr*src1, double alpha,                            const CvArr*src2, double beta,double gamma, CvArr* dst );
 
 
CVAPI(double)  cvDotProduct( const CvArr*src1, const CvArr* src2 );
 
 
CVAPI(void) cvAnd( const CvArr*src1, const CvArr*src2,                  CvArr*dst, const CvArr* mask CV_DEFAULT(NULL));
 
 
CVAPI(void) cvAndS( const CvArr*src, CvScalarvalue,                   CvArr*dst, const CvArr* mask CV_DEFAULT(NULL));
 
 
CVAPI(void) cvOr( const CvArr*src1, const CvArr*src2,                 CvArr*dst, const CvArr* mask CV_DEFAULT(NULL));
 
 
CVAPI(void) cvOrS( const CvArr*src, CvScalarvalue,                 CvArr*dst, const CvArr* mask CV_DEFAULT(NULL));
 
 
CVAPI(void) cvXor( const CvArr*src1, const CvArr*src2,                  CvArr*dst, const CvArr* mask CV_DEFAULT(NULL));
 
 
CVAPI(void) cvXorS( const CvArr*src, CvScalarvalue,                   CvArr*dst, const CvArr* mask CV_DEFAULT(NULL));
 
 
CVAPI(void) cvNot( const CvArr*src, CvArr* dst );
 
 
CVAPI(void) cvInRange( const CvArr*src, const CvArr*lower,                      const CvArr*upper, CvArr* dst );
 
 
CVAPI(void) cvInRangeS( const CvArr*src, CvScalarlower,                       CvScalarupper, CvArr* dst );
 
#define CV_CMP_EQ   0
#define CV_CMP_GT   1
#define CV_CMP_GE   2
#define CV_CMP_LT   3
#define CV_CMP_LE   4
#define CV_CMP_NE   5
 
//比较操作仅支持单通道数组,目标图像应该0为8uC1或者8sC1
 
CVAPI(void) cvCmp( const CvArr*src1, const CvArr* src2, CvArr* dst,int cmp_op );
 
CVAPI(void) cvCmpS( const CvArr*src, double value, CvArr* dst, intcmp_op );
 
 
CVAPI(void) cvMin( const CvArr*src1, const CvArr* src2, CvArr* dst );
 
 
CVAPI(void) cvMax( const CvArr*src1, const CvArr* src2, CvArr* dst );
 
 
CVAPI(void) cvMinS( const CvArr*src, double value, CvArr* dst );
 
 
CVAPI(void) cvMaxS( const CvArr*src, double value, CvArr* dst );
 
 
CVAPI(void) cvAbsDiff( const CvArr*src1, const CvArr* src2, CvArr* dst );
 
 
CVAPI(void) cvAbsDiffS( const CvArr*src, CvArr* dst, CvScalar value );
#define cvAbs( src, dst ) cvAbsDiffS((src), (dst), cvScalarAll(0))