第三章初探opencv
Opencv的基本数据类型
typedefstructCvPoint
{
intx;
inty;
#ifdef__cplusplus
CvPoint(int_x= 0, int_y= 0): x(_x), y(_y) {}
template<typename_Tp>
CvPoint(constcv::Point_<_Tp>& pt): x((int)pt.x), y((int)pt.y) {}
template<typename_Tp>
operatorcv::Point_<_Tp>() const{  returncv::Point_<_Tp>(cv::saturate_cast<_Tp>(x), cv::saturate_cast<_Tp>(y)); }
#endif
}
CvPoint;
包含两个变体类型
typedefstructCvPoint2D32f
{
floatx;
floaty;
#ifdef__cplusplus
CvPoint2D32f(float_x= 0, float_y= 0): x(_x), y(_y) {}
template<typename_Tp>
CvPoint2D32f(constcv::Point_<_Tp>& pt): x((float)pt.x), y((float)pt.y) {}
template<typename_Tp>
operatorcv::Point_<_Tp>() const{  returncv::Point_<_Tp>(cv::saturate_cast<_Tp>(x), cv::saturate_cast<_Tp>(y)); }
#endif
}
CvPoint2D32f;
typedefstructCvPoint3D32f
{
floatx;
floaty;
floatz;
#ifdef__cplusplus
CvPoint3D32f(float_x= 0, float_y= 0, float_z= 0): x(_x), y(_y), z(_z) {}
template<typename_Tp>
CvPoint3D32f(constcv::Point3_<_Tp>& pt): x((float)pt.x), y((float)pt.y), z((float)pt.z) {}
template<typename_Tp>
operatorcv::Point3_<_Tp>() const{  returncv::Point3_<_Tp>(cv::saturate_cast<_Tp>(x), cv::saturate_cast<_Tp>(y), cv::saturate_cast<_Tp>(z)); }
#endif
}
CvPoint3D32f;
------------------------------cvsize
typedefstructCvSize
{
intwidth;
intheight;
#ifdef__cplusplus
CvSize(intw= 0, inth= 0): width(w), height(h) {}
template<typename_Tp>
CvSize(constcv::Size_<_Tp>& sz): width(cv::saturate_cast<int>(sz.width)), height(cv::saturate_cast<int>(sz.height)) {}
template<typename_Tp>
operatorcv::Size_<_Tp>() const{  returncv::Size_<_Tp>(cv::saturate_cast<_Tp>(width), cv::saturate_cast<_Tp>(height)); }
#endif
}
CvSize;
变体
typedefstructCvSize2D32f
{
floatwidth;
floatheight;
#ifdef__cplusplus
CvSize2D32f(floatw= 0, floath= 0): width(w), height(h) {}
template<typename_Tp>
CvSize2D32f(constcv::Size_<_Tp>& sz): width(cv::saturate_cast<float>(sz.width)), height(cv::saturate_cast<float>(sz.height)) {}
template<typename_Tp>
operatorcv::Size_<_Tp>() const{  returncv::Size_<_Tp>(cv::saturate_cast<_Tp>(width), cv::saturate_cast<_Tp>(height)); }
#endif
}
CvSize2D32f;
---------------------------cvscalar val指向四个双精度浮点型数组 存放RGBA值
typedefstructCvScalar
{
doubleval[4];
#ifdef__cplusplus
CvScalar() {}
CvScalar(doubled0, doubled1= 0, doubled2= 0, doubled3= 0) { val[0] = d0; val[1] =  d1; val[2] = d2; val[3] =  d3; }
template<typename_Tp>
CvScalar(constcv::Scalar_<_Tp>& s) { val[0] =  s.val[0]; val[1] = s.val[1]; val[2] = s.val[2]; val[3] =  s.val[3]; }
template<typename_Tp>
operatorcv::Scalar_<_Tp>() const{  returncv::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])); }
template<typename_Tp, intcn>
CvScalar(constcv::Vec<_Tp, cn>& v)
{
inti;
for( i = 0; i < (cn < 4 ? cn : 4); i++ ) val[i] = v.val[i];
for( ; i < 4; i++ ) val[i] = 0;
}
#endif
}
CvScalar;
-------------------------cvrect
typedefstructCvRect
{
intx;
inty;
intwidth;
intheight;
#ifdef__cplusplus
CvRect(int_x= 0, int_y= 0, intw= 0, inth= 0): x(_x), y(_y), width(w), height(h) {}
template<typename_Tp>
CvRect(constcv::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)) {}
template<typename_Tp>
operatorcv::Rect_<_Tp>() const{  returncv::Rect_<_Tp>((_Tp)x, (_Tp)y, (_Tp)width, (_Tp)height); }
#endif
}
CvRect;
矩阵和图像类型
图像操作:
缩放
单通道提取
找出特定通道的最大最小
两图像求和
对图像进行阀值操作
cvMat矩阵结构
新建一个二维矩阵的原型
/** @brief Creates a matrix header and allocates the matrix data.
The function call is equivalent to the following code:
@code
CvMat* mat = cvCreateMatHeader(rows, cols, type);
cvCreateData(mat);
@endcode
@param rows Number of rows in the matrix
@param cols Number of columns in the matrix
@param type The type of the matrix elements in the form
CV_\<bit depth\>\<S|U|F\>C\<number of channels\> , where S=signed, U=unsigned, F=float. For
example, CV _ 8UC1 means the elements are 8-bit unsigned and the there is 1 channel, and CV _
32SC2 means the elements are 32-bit signed and there are 2 channels.
*/

CVAPI(CvMat*) cvCreateMat( introws,//行
intcols,//列
inttype);//预定义类型
cvCreateMat由多个原函数组成:
//创建cvmat结构,不分配内存
CVAPI(CvMat*) cvCreateMatHeader( introws, intcols, inttype);
//数据的内存分配
CVAPI(void) cvCreateData( CvArr*  arr);
//根据现有矩阵,创建一个新的矩阵
/** Creates an exact copy of the input matrix (except, may be, step value) */
CVAPI(CvMat*) cvCloneMat( constCvMat* mat);
//释放矩阵
CVAPI(void) cvReleaseMat( CvMat**  mat);
cvMat结构体
typedefstructCvMat
{
inttype;
intstep;
/* for internal use only */
int* refcount;
inthdr_refcount;
union
{
uchar* ptr;
short* s;
int* i;
float* fl;
double* db;
} data;
#ifdef__cplusplus
union
{
introws;
intheight;
};
union
{
intcols;
intwidth;
};
#else
introws;
intcols;
#endif
#ifdef__cplusplus
CvMat() {}
CvMat(constCvMat& m) { memcpy(this, &m, sizeof(CvMat));}
CvMat(constcv::Mat& m);
#endif
}
CvMat;
矩阵数据的存取
访问矩阵的三种方法:
简单的方法
函数原型
#defineCV_MAT_ELEM( mat, elemtype, row, col ) 
CvMat* mat = cvCreateMat(5,5,CV_32FC1);
//从矩阵中提取一个元素
floatelement_3_2 =  CV_MAT_ELEM(*mat,//矩阵
float,//元素类型
3,//行
2);//列

//同时读取数据并设置数据
CvMat* mat = cvCreateMat(5, 5,  CV_32FC1);
//从矩阵中提取一个元素
floatelement_3_2 = 7.7;
*((float*)CV_MAT_ELEM_PTR(*mat,//矩阵
3,//行
2))//列
= element_3_2;
麻烦的方法
//访问普通矩阵中的方法
CVAPI(uchar*) cvPtr1D( constCvArr* arr, //矩阵指针参数
intidx0, //索引的整数值
int*  typeCV_DEFAULT(NULL));//输出值的类型
CVAPI(uchar*) cvPtr2D( constCvArr* arr, 
intidx0, 
intidx1, 
int*  typeCV_DEFAULT(NULL) );
CVAPI(uchar*) cvPtr3D( constCvArr* arr, 
intidx0, 
intidx1, 
intidx2,
int* typeCV_DEFAULT(NULL));
CVAPI(uchar*) cvPtrND( constCvArr* arr, 
constint* idx, //指向整型数组的指针(索引)
int*  typeCV_DEFAULT(NULL),
intcreate_nodeCV_DEFAULT(1),
unsigned* precalc_hashvalCV_DEFAULT(NULL));
只是读取数据
CVAPI(double) cvGetReal1D( constCvArr* arr,  intidx0);
CVAPI(double) cvGetReal2D( constCvArr* arr,  intidx0,  intidx1);
CVAPI(double) cvGetReal3D( constCvArr* arr,  intidx0,  intidx1,  intidx2);
CVAPI(double) cvGetRealND( constCvArr* arr,  constint*  idx);
//会很浪费空间
CVAPI(CvScalar) cvGet1D( constCvArr* arr,  intidx0);
CVAPI(CvScalar) cvGet2D( constCvArr* arr,  intidx0,  intidx1);
CVAPI(CvScalar) cvGet3D( constCvArr* arr,  intidx0,  intidx1,  intidx2);
CVAPI(CvScalar) cvGetND( constCvArr* arr,  constint*  idx);
为矩阵元素设定值
CVAPI(void) cvSetReal1D( CvArr*  arr, intidx0, doublevalue);
CVAPI(void) cvSetReal2D( CvArr*  arr, intidx0, intidx1, doublevalue);
CVAPI(void) cvSetReal3D( CvArr*  arr, intidx0,
intidx1, intidx2, doublevalue);
CVAPI(void) cvSetRealND( CvArr*  arr, constint* idx,  doublevalue);
CVAPI(void) cvSet1D( CvArr*  arr, intidx0, CvScalarvalue);
CVAPI(void) cvSet2D( CvArr*  arr, intidx0, intidx1, CvScalarvalue);
CVAPI(void) cvSet3D( CvArr*  arr, intidx0, intidx1, intidx2, CvScalarvalue);
CVAPI(void) cvSetND( CvArr*  arr, constint* idx,  CvScalarvalue);
处理浮点型单通道矩阵
doublecvmGet(  constCvMat*  mat, introw, intcol)
voidcvmSet(  CvMat* mat,  introw,  intcol,  doublevalue)
恰当的方法
矩阵的存储是按光栅扫描顺序存储
/**
累加一个三通道矩阵中的所有元素
*/
floatsum(constCvMat* mat) {
floats = 0.0f;
for(introw = 0; row < mat->rows; row++)
{
constfloat* ptr = (constfloat*)(mat->data.ptr + row*mat->step);
for(intcol = 0; col < mat->cols; col++)
{
s += *ptr++;
}
}
return(s);
}
点的数组
计算给定点的位置的计算公式
δ=(row)*Ncols*Nchannels+(col)*Nchannels+(channel)
Ncols 列数
Nchannels通道数
IplImage数据结构
_IplImage
{
intnSize; /**< sizeof(IplImage) */
intID; /**< version (=0)*/
intnChannels; /**< Most of OpenCV functions support 1,2,3 or 4 channels 
通道数
*/
intalphaChannel; /**< Ignored by OpenCV */
intdepth; /**< Pixel depth in bits: 
IPL_DEPTH_8U, 无符号8位整数
IPL_DEPTH_8S, 有符号8位整数
IPL_DEPTH_16S,有符号16位整数
IPL_DEPTH_32S,  有符号32位整数
IPL_DEPTH_32F 32位符点数单精度 
IPL_DEPTH_64F 64位符点数单双精度
are supported. */
charcolorModel[4]; /**< Ignored by OpenCV */
charchannelSeq[4]; /**< ditto */
intdataOrder; /**< 0 - interleaved color channels, 1 - separate color channels.
cvCreateImage can only create interleaved images
取值可以是
IPL_DATA_ORDER_PIXEL将像素点不同通道的值交错排在一起
IPL_DATA_ORDER_PLANE将像素同通道值排在一起

*/
intorigin; /**< 0 - top-left origin,
1 - bottom-left origin (Windows bitmaps style).
IPL_ORIGIN_TL
IPL_ORIGIN_BL
设置坐示原点位置
*/
intalign; /**< Alignment of image rows (4 or 8).
OpenCV ignores it and uses widthStep instead. */
intwidth; /**< Image width in pixels. */
intheight; /**< 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; /**< " " */
intimageSize; /**< Image data size in bytes
(==image->height*image->widthStep
in case of interleaved data)*/
char*imageData; /**< Pointer to aligned image data.指向第一行数据的指针*/
intwidthStep; /**< Size of aligned image row in bytes. 
相邻行的同列点之间的字节数
*/
intBorderMode[4]; /**< Ignored by OpenCV. */
intBorderConst[4]; /**< Ditto. */
char*imageDataOrigin; /**< Pointer to very origin of image data
(not necessarily aligned) -
needed for correct deallocation */
#ifdef__cplusplus
_IplImage() {}
_IplImage(constcv::Mat& m);
#endif
}
IplImage;
访问图像数据
#include<opencv2\opencv.hpp>
usingnamespacecv;
voidstaturate_sv(IplImage* img);
intmain(intargc,char** argv) {
//读入图像
IplImage* img= cvLoadImage("test.jpg");
//
staturate_sv(img);
return0;
}
/*
在色度不变的情况下,设置每个点的饱合度为255
*/
voidstaturate_sv(IplImage* img) {
for(inty = 0; y < img->height; y++)
{
//指向第y行的起始位置
uchar* ptr = (uchar*)(
img->imageData + y*img->widthStep
);
for(intx = 0; x < img->width; x++)
{
//c通道在x行的位置
ptr[3 * x + 1] = 255;
ptr[3 * x + 2] = 255;
}
}
}
对ROI和widthStep的补充
可以提高计算机视觉代码的执行速度
设置和取消ORI
CVAPI(void) cvSetImageROI( IplImage*  image, CvRectrect);
CVAPI(void) cvResetImageROI( IplImage*  image);
使用imageROI来增加某范围的像素
/*
用imageROI来增加某范围的像素
在图像roi的蓝色通道增加150级灰度的效果
*/
voidroi_add() {
//可以从控制台传入参数
IplImage* src;
//加载图像
if((src=cvLoadImage("test.jpg"))!=0) {
//初始化坐标
intx = atoi("10");
inty = atoi("10");
intwidth = atoi("50");
intheight = atoi("50");
intadd = atoi("150");
cvSetImageROI(src,cvRect(x,y,width,height));
cvAddS(src,cvScalar(add),src);
//释放roi
cvResetImageROI(src);
cvNamedWindow("Roi_Add",1);
cvShowImage("Roi_Add",src);
cvWaitKey();
}
}
如下图所示
/*
使用widthStep方法把图像的所有像素值加1
*/
CvRectinterest_rect;
voidaddByWdthStep(IplImage* interest_rect_img) {
interest_rect =CvRect(10,10,50,50);
IplImage* sub_img = cvCreateImageHeader(
cvSize(
interest_rect.width,
interest_rect.height
),
interest_rect_img->depth,
interest_rect_img->nChannels
);
sub_img->origin = interest_rect_img->origin;
sub_img->widthStep = interest_rect_img->widthStep;
sub_img->imageData = interest_rect_img->imageData +
interest_rect.y*interest_rect_img->widthStep +
interest_rect.x*interest_rect_img->nChannels;
cvAddS(sub_img,cvScalar(1),sub_img);
cvNamedWindow("WidthStep", 1);
cvShowImage("WidthStep", sub_img);
cvWaitKey();
cvReleaseImageHeader(&sub_img);
}
矩阵和图像操作
//计算两个数组差值的绝对值
/** dst(x,y,c) = abs(src1(x,y,c) - src2(x,y,c)) */
CVAPI(void) cvAbsDiff( constCvArr* src1, 
constCvArr* src2, 
CvArr*  dst);
//计算数组和标量差值的绝对值
/** dst(x,y,c) = abs(src(x,y,c) - value(c)) */
CVAPI(void) cvAbsDiffS( constCvArr* src, 
CvArr*  dst, 
CvScalarvalue);
//计算数组中所有元素的绝对值
#definecvAbs( src,
dst ) //计算结果写到dst
cvAbsDiffS( (src), (dst), cvScalarAll(0))
//两个数组的元素级的加运算,如果mask没有被设空,那么mask非零元素指定的dest值在函数执行后不变
/** dst(mask) = src1(mask) + src2(mask) */
CVAPI(void) cvAdd( constCvArr* src1,  constCvArr*  src2, CvArr*  dst,
constCvArr* maskCV_DEFAULT(NULL));
//一个数据和一个标量的元素级的相加运算
/** dst(mask) = src(mask) + value */
CVAPI(void) cvAddS( constCvArr* src,  CvScalarvalue,  CvArr* dst,
constCvArr* maskCV_DEFAULT(NULL));
//两个数据的元素级的加权相加运算,可以用于实现alpha融合,即两幅图像融合
/** dst = src1 * alpha + src2 * beta + gamma */
CVAPI(void) cvAddWeighted( constCvArr* src1,  doublealpha,
constCvArr* src2,  doublebeta,
doublegamma, CvArr*  dst);
/*
alpha融合
*/
voidalpha_blends() {
IplImage*src1, *src2;
if((src1=cvLoadImage("test2.jpg"))!=0&&(src2=cvLoadImage("test.jpg"))!=0)
{
intx = atoi("10");
inty = atoi("10");
intwidth = atoi("200");
intheight = atoi("200");
doublealpha = (double)atof("0.5");
doublebeta = (double)atof("0.4");
cvSetImageROI(src1, CvRect(x, y, width, height));
cvSetImageROI(src2, CvRect(0, 0, width, height));
cvAddWeighted(src1, alpha, src2, beta, 0.0, src1);
cvResetImageROI(src1);
cvNamedWindow("Alpha_blend", 1);
cvShowImage("Alpha_blend", src1);
cvWaitKey();
}
}
//两个数组进行按位与
/** dst(idx) = src1(idx) & src2(idx) */
CVAPI(void) cvAnd( constCvArr* src1,  constCvArr*  src2,
CvArr*  dst, constCvArr* maskCV_DEFAULT(NULL));
/** dst(idx) = src(idx) & value */
CVAPI(void) cvAndS( constCvArr* src,  CvScalarvalue,
CvArr* dst,  constCvArr*  maskCV_DEFAULT(NULL));
//计算数组中所有元素的平均值
/** Calculates mean value of array elements */
CVAPI(CvScalar) cvAvg( constCvArr* arr,  constCvArr*  maskCV_DEFAULT(NULL) );
//计算数组中所有元素的绝对值和标准差
/** Calculates mean and standard deviation of pixel values */
CVAPI(void) cvAvgSdv( constCvArr* arr,  CvScalar* mean,  CvScalar* std_dev,
constCvArr* maskCV_DEFAULT(NULL) );
//计算一组n维空间向量的协方差
/** Calculates covariation matrix for a set of vectors
@see @ref core_c_CovarFlags "flags"
*/
CVAPI(void) cvCalcCovarMatrix( constCvArr** vects,  intcount,
CvArr* cov_mat,  CvArr* avg,  intflags);
Flags的取值:
CV_COVAR_NORMAL计算均值和协方差
CV_COVAR_SCRAMBLED快速pca scrambled协方差
CV_COVAR_USE_AVG输入均值
CV_COVAR_SCALE重新输出缩放的协方差矩阵
//进行比较操作
/** dst(idx) = src1(idx) _cmp_op_ src2(idx)  两个数组中所有元素运用设置的比较操作*/
CVAPI(void) cvCmp( constCvArr* src1,
constCvArr* src2, 
CvArr*  dst, 
intcmp_op);
/** dst(idx) = src1(idx) _cmp_op_ value  对数组和标量运用设置的比较操作*/
CVAPI(void) cvCmpS( constCvArr* src, 
doublevalue, 
CvArr*  dst, 
intcmp_op);
Cmp_op 的取值如下:
CV_CMP_EQ(src1i==src2i)
CV_CMP_GT(src1i>src2i)
CV_CMP_GE(src1i>=src2i)
CV_CMP_LT(src1i<rc2i)
CV_CMP_LE(src1i<=src2i)
CV_CMP_NE(src1i!=src2i)

//用可选的缩放值转换数组元素类型
//1 将原图像的数据类型转换为目标图像的数据类型
//2 对图像数据执行线性变换
CVAPI(void) cvConvertScale( constCvArr* src,
CvArr*  dst,
doublescaleCV_DEFAULT(1),
doubleshiftCV_DEFAULT(0) );
//先缩放和平移,算出绝对值,然后进行数据类型的转换
/** Performs linear transformation on every source array element,
stores absolute value of the result:
dst(x,y,c) = abs(scale*src(x,y,c)+shift).
destination array must have 8u type.
In other cases one may use cvConvertScale + cvAbsDiffS */
CVAPI(void) cvConvertScaleAbs( constCvArr* src,
CvArr*  dst,// 结果数据的绝对值
doublescaleCV_DEFAULT(1),
doubleshiftCV_DEFAULT(0) );
//一个图像复制到别一个图像 
CVAPI(void) cvCopy( constCvArr* src, //源图像
CvArr*  dst,//目标图像
constCvArr* maskCV_DEFAULT(NULL) );
//array中非0元素的个数
/** Calculates number of non-zero pixels */
CVAPI(int) cvCountNonZero( constCvArr* arr);
//计算两个三维向量的向量积,必须为单通道数组
CVAPI(void) cvCrossProduct( constCvArr* src1, 
constCvArr* src2,
CvArr*  dst);//单通道,长度应精确为3
//将数组的通道从一个颜色空间转换到另一个颜色空间
/** @brief Converts input array pixels from one color space to another
@see cv::cvtColor
*/
CVAPI(void) cvCvtColor( constCvArr* src,  CvArr* dst,  intcode);
CV_BGR2BGRA=0,
CV_RGB2RGBA=CV_BGR2BGRA,
CV_BGRA2BGR=1,
CV_RGBA2RGB=CV_BGRA2BGR,
CV_BGR2RGBA=2,
CV_RGB2BGRA=CV_BGR2RGBA,
CV_RGBA2BGR=3,
CV_BGRA2RGB=CV_RGBA2BGR,
CV_BGR2RGB=4,
CV_RGB2BGR=CV_BGR2RGB,
CV_BGRA2RGBA=5,
CV_RGBA2BGRA=CV_BGRA2RGBA,
CV_BGR2GRAY=6,
CV_RGB2GRAY=7,
CV_GRAY2BGR=8,
CV_GRAY2RGB=CV_GRAY2BGR,
CV_GRAY2BGRA=9,
CV_GRAY2RGBA=CV_GRAY2BGRA,
CV_BGRA2GRAY=10,
CV_RGBA2GRAY=11,
CV_BGR2BGR565=12,
CV_RGB2BGR565=13,
CV_BGR5652BGR=14,
CV_BGR5652RGB=15,
CV_BGRA2BGR565=16,
CV_RGBA2BGR565=17,
CV_BGR5652BGRA=18,
CV_BGR5652RGBA=19,
CV_GRAY2BGR565=20,
CV_BGR5652GRAY=21,
CV_BGR2BGR555=22,
CV_RGB2BGR555=23,
CV_BGR5552BGR=24,
CV_BGR5552RGB=25,
CV_BGRA2BGR555=26,
CV_RGBA2BGR555=27,
CV_BGR5552BGRA=28,
CV_BGR5552RGBA=29,
CV_GRAY2BGR555=30,
CV_BGR5552GRAY=31,
CV_BGR2XYZ=32,
CV_RGB2XYZ=33,
CV_XYZ2BGR=34,
CV_XYZ2RGB=35,
CV_BGR2YCrCb=36,
CV_RGB2YCrCb=37,
CV_YCrCb2BGR=38,
CV_YCrCb2RGB=39,
CV_BGR2HSV=40,
CV_RGB2HSV=41,
CV_BGR2Lab=44,
CV_RGB2Lab=45,
CV_BayerBG2BGR=46,
CV_BayerGB2BGR=47,
CV_BayerRG2BGR=48,
CV_BayerGR2BGR=49,
CV_BayerBG2RGB=CV_BayerRG2BGR,
CV_BayerGB2RGB=CV_BayerGR2BGR,
CV_BayerRG2RGB=CV_BayerBG2BGR,
CV_BayerGR2RGB=CV_BayerGB2BGR,
CV_BGR2Luv=50,
CV_RGB2Luv=51,
CV_BGR2HLS=52,
CV_RGB2HLS=53,
CV_HSV2BGR=54,
CV_HSV2RGB=55,
CV_Lab2BGR=56,
CV_Lab2RGB=57,
CV_Luv2BGR=58,
CV_Luv2RGB=59,
CV_HLS2BGR=60,
CV_HLS2RGB=61,
CV_BayerBG2BGR_VNG=62,
CV_BayerGB2BGR_VNG=63,
CV_BayerRG2BGR_VNG=64,
CV_BayerGR2BGR_VNG=65,
CV_BayerBG2RGB_VNG=CV_BayerRG2BGR_VNG,
CV_BayerGB2RGB_VNG=CV_BayerGR2BGR_VNG,
CV_BayerRG2RGB_VNG=CV_BayerBG2BGR_VNG,
CV_BayerGR2RGB_VNG=CV_BayerGB2BGR_VNG,
CV_BGR2HSV_FULL= 66,
CV_RGB2HSV_FULL= 67,
CV_BGR2HLS_FULL= 68,
CV_RGB2HLS_FULL= 69,
CV_HSV2BGR_FULL= 70,
CV_HSV2RGB_FULL= 71,
CV_HLS2BGR_FULL= 72,
CV_HLS2RGB_FULL= 73,
CV_LBGR2Lab= 74,
CV_LRGB2Lab= 75,
CV_LBGR2Luv= 76,
CV_LRGB2Luv= 77,
CV_Lab2LBGR= 78,
CV_Lab2LRGB= 79,
CV_Luv2LBGR= 80,
CV_Luv2LRGB= 81,
CV_BGR2YUV= 82,
CV_RGB2YUV= 83,
CV_YUV2BGR= 84,
CV_YUV2RGB= 85,
CV_BayerBG2GRAY= 86,
CV_BayerGB2GRAY= 87,
CV_BayerRG2GRAY= 88,
CV_BayerGR2GRAY= 89,
//YUV 4:2:0 formats family
CV_YUV2RGB_NV12= 90,
CV_YUV2BGR_NV12= 91,
CV_YUV2RGB_NV21= 92,
CV_YUV2BGR_NV21= 93,
CV_YUV420sp2RGB=  CV_YUV2RGB_NV21,
CV_YUV420sp2BGR=  CV_YUV2BGR_NV21,
CV_YUV2RGBA_NV12= 94,
CV_YUV2BGRA_NV12= 95,
CV_YUV2RGBA_NV21= 96,
CV_YUV2BGRA_NV21= 97,
CV_YUV420sp2RGBA=  CV_YUV2RGBA_NV21,
CV_YUV420sp2BGRA=  CV_YUV2BGRA_NV21,
CV_YUV2RGB_YV12= 98,
CV_YUV2BGR_YV12= 99,
CV_YUV2RGB_IYUV= 100,
CV_YUV2BGR_IYUV= 101,
CV_YUV2RGB_I420=  CV_YUV2RGB_IYUV,
CV_YUV2BGR_I420=  CV_YUV2BGR_IYUV,
CV_YUV420p2RGB=  CV_YUV2RGB_YV12,
CV_YUV420p2BGR=  CV_YUV2BGR_YV12,
CV_YUV2RGBA_YV12= 102,
CV_YUV2BGRA_YV12= 103,
CV_YUV2RGBA_IYUV= 104,
CV_YUV2BGRA_IYUV= 105,
CV_YUV2RGBA_I420=  CV_YUV2RGBA_IYUV,
CV_YUV2BGRA_I420=  CV_YUV2BGRA_IYUV,
CV_YUV420p2RGBA=  CV_YUV2RGBA_YV12,
CV_YUV420p2BGRA=  CV_YUV2BGRA_YV12,
CV_YUV2GRAY_420= 106,
CV_YUV2GRAY_NV21=  CV_YUV2GRAY_420,
CV_YUV2GRAY_NV12=  CV_YUV2GRAY_420,
CV_YUV2GRAY_YV12=  CV_YUV2GRAY_420,
CV_YUV2GRAY_IYUV=  CV_YUV2GRAY_420,
CV_YUV2GRAY_I420=  CV_YUV2GRAY_420,
CV_YUV420sp2GRAY=  CV_YUV2GRAY_420,
CV_YUV420p2GRAY=  CV_YUV2GRAY_420,
//YUV 4:2:2 formats family
CV_YUV2RGB_UYVY= 107,
CV_YUV2BGR_UYVY= 108,
//CV_YUV2RGB_VYUY = 109,
//CV_YUV2BGR_VYUY = 110,
CV_YUV2RGB_Y422=  CV_YUV2RGB_UYVY,
CV_YUV2BGR_Y422=  CV_YUV2BGR_UYVY,
CV_YUV2RGB_UYNV=  CV_YUV2RGB_UYVY,
CV_YUV2BGR_UYNV=  CV_YUV2BGR_UYVY,
CV_YUV2RGBA_UYVY= 111,
CV_YUV2BGRA_UYVY= 112,
//CV_YUV2RGBA_VYUY = 113,
//CV_YUV2BGRA_VYUY = 114,
CV_YUV2RGBA_Y422=  CV_YUV2RGBA_UYVY,
CV_YUV2BGRA_Y422=  CV_YUV2BGRA_UYVY,
CV_YUV2RGBA_UYNV=  CV_YUV2RGBA_UYVY,
CV_YUV2BGRA_UYNV=  CV_YUV2BGRA_UYVY,
CV_YUV2RGB_YUY2= 115,
CV_YUV2BGR_YUY2= 116,
CV_YUV2RGB_YVYU= 117,
CV_YUV2BGR_YVYU= 118,
CV_YUV2RGB_YUYV=  CV_YUV2RGB_YUY2,
CV_YUV2BGR_YUYV=  CV_YUV2BGR_YUY2,
CV_YUV2RGB_YUNV=  CV_YUV2RGB_YUY2,
CV_YUV2BGR_YUNV=  CV_YUV2BGR_YUY2,
CV_YUV2RGBA_YUY2= 119,
CV_YUV2BGRA_YUY2= 120,
CV_YUV2RGBA_YVYU= 121,
CV_YUV2BGRA_YVYU= 122,
CV_YUV2RGBA_YUYV=  CV_YUV2RGBA_YUY2,
CV_YUV2BGRA_YUYV=  CV_YUV2BGRA_YUY2,
CV_YUV2RGBA_YUNV=  CV_YUV2RGBA_YUY2,
CV_YUV2BGRA_YUNV=  CV_YUV2BGRA_YUY2,
CV_YUV2GRAY_UYVY= 123,
CV_YUV2GRAY_YUY2= 124,
//CV_YUV2GRAY_VYUY = CV_YUV2GRAY_UYVY,
CV_YUV2GRAY_Y422=  CV_YUV2GRAY_UYVY,
CV_YUV2GRAY_UYNV=  CV_YUV2GRAY_UYVY,
CV_YUV2GRAY_YVYU=  CV_YUV2GRAY_YUY2,
CV_YUV2GRAY_YUYV=  CV_YUV2GRAY_YUY2,
CV_YUV2GRAY_YUNV=  CV_YUV2GRAY_YUY2,
// alpha premultiplication
CV_RGBA2mRGBA= 125,
CV_mRGBA2RGBA= 126,
CV_RGB2YUV_I420= 127,
CV_BGR2YUV_I420= 128,
CV_RGB2YUV_IYUV=  CV_RGB2YUV_I420,
CV_BGR2YUV_IYUV=  CV_BGR2YUV_I420,
CV_RGBA2YUV_I420= 129,
CV_BGRA2YUV_I420= 130,
CV_RGBA2YUV_IYUV=  CV_RGBA2YUV_I420,
CV_BGRA2YUV_IYUV=  CV_BGRA2YUV_I420,
CV_RGB2YUV_YV12= 131,
CV_BGR2YUV_YV12= 132,
CV_RGBA2YUV_YV12= 133,
CV_BGRA2YUV_YV12= 134,
// Edge-Aware Demosaicing
CV_BayerBG2BGR_EA= 135,
CV_BayerGB2BGR_EA= 136,
CV_BayerRG2BGR_EA= 137,
CV_BayerGR2BGR_EA= 138,
CV_BayerBG2RGB_EA=  CV_BayerRG2BGR_EA,
CV_BayerGB2RGB_EA=  CV_BayerGR2BGR_EA,
CV_BayerRG2RGB_EA=  CV_BayerBG2BGR_EA,
CV_BayerGR2RGB_EA=  CV_BayerGB2BGR_EA,
CV_COLORCVT_MAX= 139

/** Calculates determinant of input matrix  计算方阵的行列式*/
CVAPI(double) cvDet( constCvArr* mat);
//用另外一个数组对一个数组进行元素级的除法运算
/** element-wise division/inversion with scaling:
dst(idx) = src1(idx) * scale / src2(idx)
or dst(idx) = scale / src2(idx) if src1 == 0 */
CVAPI(void) cvDiv( constCvArr* src1, 
constCvArr* src2,
CvArr* dst, 
doublescaleCV_DEFAULT(1));
//计算两个向量的点积,单通道
CVAPI(double) cvDotProduct( constCvArr* src1,  constCvArr*  src2);
//计算方阵的特征值和特征向量
/** Finds eigen values and vectors of a symmetric matrix */
CVAPI(void) cvEigenVV( CvArr*  mat, //矩阵
CvArr*  evects, //顺序保存的特征向量
CvArr*  evals,//特征值
doubleepsCV_DEFAULT(0),//停止参数
intlowindexCV_DEFAULT(-1),
inthighindexCV_DEFAULT(-1));
//围绕选定轴旋转
/** Mirror array data around horizontal (flip=0),
vertical (flip=1) or both(flip=-1) axises:
cvFlip(src) flips images vertically and sequences horizontally (inplace) */
CVAPI(void) cvFlip( constCvArr* src,//图像
CvArr*  dstCV_DEFAULT(NULL),//
intflip_modeCV_DEFAULT(0));//为0时,只会绕x轴转
//矩阵乘法 d=a*op(A)*op(B)+b*op(C)
/** Extended matrix transform:
dst = alpha*op(A)*op(B) + beta*op(C), where op(X) is X or X^T */
CVAPI(void) cvGEMM( constCvArr* src1, 
constCvArr* src2, 
doublealpha,
constCvArr* src3,
doublebeta, 
CvArr*  dst,
inttABCCV_DEFAULT(0));//转置,可以是0 或是以下几种
#defineCV_GEMM_A_T1
#defineCV_GEMM_B_T2
#defineCV_GEMM_C_T4
//从一个数组的列中复制元素
/** @overload
@param arr Input array
@param submat Pointer to the resulting sub-array header
@param col Zero-based index of the selected column
*/
CV_INLINECvMat* cvGetCol( constCvArr* arr, //矩阵
CvMat*  submat, //指向矩阵中的特定列
intcol)//指定列
{
returncvGetCols(  arr, submat,  col, col+ 1 );
}
//从数组相邻的多列中复制元素
CVAPI(CvMat*) cvGetCols( constCvArr* arr, 
CvMat*  submat,
intstart_col,//开始列
intend_col);//结束列
//复制数组中对角线上的所有元素
CVAPI(CvMat*) cvGetDiag( constCvArr* arr, 
CvMat*  submat,
intdiagCV_DEFAULT(0));
//返回数组的维数
CVAPI(int) cvGetDims( constCvArr* arr,  int* sizesCV_DEFAULT(NULL) );
//返回一个数组的所有维的大小
CVAPI(int) cvGetDimSize( constCvArr* arr,  intindex);
//从一个数组的行中复制元素
CV_INLINECvMat* cvGetRow( constCvArr* arr,  CvMat* submat,  introw)
{
returncvGetRows(  arr, submat,  row, row+ 1, 1 );
}
//从一个数组的相邻行中复制数组
CVAPI(CvMat*) cvGetRows( constCvArr* arr,  CvMat* submat,
intstart_row, intend_row,
intdelta_rowCV_DEFAULT(1));
//得到二维数组的尺寸
CVAPI(CvSize) cvGetSize( constCvArr* arr);
//从一个数组的子区域复制元素
CVAPI(CvMat*) cvGetSubRect( constCvArr* arr,  CvMat* submat,  CvRectrect);
//检查一个数组中的元素是否在另外两个数组中的值的范转围
//检查图像中像素的灰度是否属于某一指定范围
/** dst(idx) = lower(idx) <= src(idx) < upper(idx) */
CVAPI(void) cvInRange( constCvArr* src,//图像
constCvArr* lower,//起始值
constCvArr* upper,
CvArr*  dst);//如果>=lower,且<upper,dst中对应的值为0xff,否则为0
//检查一个数组的元素的值是否在另外两个标量的范围
//如果是多通道,则会分通道进行处理
/** dst(idx) = lower <= src(idx) < upper */
CVAPI(void) cvInRangeS( constCvArr* src,
CvScalarlower,
CvScalarupper, 
CvArr*  dst);


//求矩阵的转置
/** Inverts matrix */
CVAPI(double) cvInvert( constCvArr* src,//
CvArr*  dst,//保存结果
intmethodCV_DEFAULT(CV_LU));//参数值有以下几种:
#defineCV_LU0高斯消去
#defineCV_SVD1奇异值分解
#defineCV_SVD_SYM2对称矩阵的SVD
//计算两个向量间的马式距离
/** Calculates Mahalanobis(weighted) distance */
CVAPI(double) cvMahalanobis( constCvArr* vec1, 
constCvArr* vec2, 
constCvArr* mat);
//两个数组中进行元素级的取最小值
/** dst(idx) = min(src1(idx),src2(idx)) */
CVAPI(void) cvMin( constCvArr* src1,  constCvArr*  src2, CvArr*  dst);
//一个数组和一个标量中进行元素级的取最小值
/** dst(idx) = min(src(idx),value) */
CVAPI(void) cvMinS( constCvArr* src,  doublevalue,  CvArr* dst);
//两个数组中取最大值
/** dst(idx) = max(src1(idx),src2(idx)) */
CVAPI(void) cvMax( constCvArr* src1,  constCvArr*  src2, CvArr*  dst);
//一个数组和一个标量中进行元素组的取最大值
/** dst(idx) = max(src(idx),value) */
CVAPI(void) cvMaxS( constCvArr* src,  doublevalue,  CvArr* dst);
//把几个单通道图像合并为一个多通道图像
/** Merges a set of single-channel arrays into the single multi-channel array
or inserts one particular [color] plane to the array */
CVAPI(void) cvMerge( constCvArr* src0,  constCvArr*  src1,
constCvArr* src2,  constCvArr*  src3,
CvArr* dst);
//寻找数组中的最大最小值
/** Finds global minimum, maximum and their positions */
CVAPI(void) cvMinMaxLoc( constCvArr* arr,  double* min_val,  double* max_val,
CvPoint*  min_locCV_DEFAULT(NULL),
CvPoint*  max_locCV_DEFAULT(NULL),
constCvArr* maskCV_DEFAULT(NULL) );
//计算两个数组,元素级的乘积
/** dst(idx) = src1(idx) * src2(idx) * scale
(scaled element-wise multiplication of 2 arrays) */
CVAPI(void) cvMul( constCvArr* src1,  constCvArr*  src2,
CvArr* dst,  doublescaleCV_DEFAULT(1) );
//对数组中的元素按位取反
/** dst(idx) = ~src(idx) */
CVAPI(void) cvNot( constCvArr* src,  CvArr* dst);
//计算两个数组的正态相关性
/** Finds norm, difference norm or relative difference norm for an array (or two arrays)
@see ref core_c_NormFlags "flags"
*/
CVAPI(double) cvNorm( constCvArr* arr1,  constCvArr*  arr2CV_DEFAULT(NULL),
intnorm_typeCV_DEFAULT(CV_L2),
constCvArr* maskCV_DEFAULT(NULL) );
//将数组中元素进行规一化
/** @see ref core_c_NormFlags "flags" */
CVAPI(void) cvNormalize( constCvArr* src,  CvArr* dst,
doubleaCV_DEFAULT(1.), doublebCV_DEFAULT(0.),
intnorm_typeCV_DEFAULT(CV_L2),
constCvArr* maskCV_DEFAULT(NULL) );
Norm_type的类型
#defineCV_C1
#defineCV_L12
#defineCV_L24
#defineCV_MINMAX32
//两个数组按位或
/** dst(idx) = src1(idx) | src2(idx) */
CVAPI(void) cvOr( constCvArr* src1,  constCvArr*  src2,
CvArr*  dst, constCvArr* maskCV_DEFAULT(NULL));
//数组与标量之间按位或
/** dst(idx) = src(idx) | value */
CVAPI(void) cvOrS( constCvArr* src,  CvScalarvalue,
CvArr* dst,  constCvArr*  maskCV_DEFAULT(NULL));
//通过给定操作符将二维数组约简为向量
/** @see @ref core_c_ReduceFlags "flags" */
CVAPI(void) cvReduce( constCvArr* src,  CvArr* dst,  intdimCV_DEFAULT(-1),
intopCV_DEFAULT(CV_REDUCE_SUM) );
//以平铺的方式进行数组复制
/** Repeats source 2d array several times in both horizontal and
vertical direction to fill destination array */
CVAPI(void) cvRepeat( constCvArr* src,  CvArr* dst);
CVAPI(void) cvConvertScale( constCvArr* src,  CvArr* dst,
doublescaleCV_DEFAULT(1),
doubleshiftCV_DEFAULT(0) );
//用给定值初始化数组
CVAPI(void) cvSet( CvArr*  arr, CvScalarvalue,
constCvArr* maskCV_DEFAULT(NULL) );
//所有元素初始化为0
CVAPI(void) cvSetZero( CvArr*  arr);
#definecvZerocvSetZero
//将数组对角线上的设置为1,其他为0
/** Makes an identity matrix (mat_ij = i == j) */
CVAPI(void) cvSetIdentity( CvArr*  mat, CvScalarvalueCV_DEFAULT(cvRealScalar(1)) );
//求出线性方程的解
/** Solves linear system (src1)*(dst) = (src2)
(returns 0 if src1 is a singular and CV_LU method is used) */
CVAPI(int) cvSolve( constCvArr* src1,  constCvArr*  src2, CvArr*  dst,
intmethodCV_DEFAULT(CV_LU));
//将多通道数组分解成为多个单通道数组
/** Splits a multi-channel array into the set of single-channel arrays or
extracts particular [color] plane */
CVAPI(void) cvSplit( constCvArr* src,  CvArr* dst0,  CvArr* dst1,
CvArr* dst2,  CvArr* dst3);
//两个数组元素级相减
/** dst(mask) = src1(mask) - src2(mask) */
CVAPI(void) cvSub( constCvArr* src1,  constCvArr*  src2, CvArr*  dst,
constCvArr* maskCV_DEFAULT(NULL));
//元素级的从数组减去标量
/** dst(mask) = src(mask) - value = src(mask) + (-value) */
CV_INLINEvoidcvSubS( constCvArr* src,  CvScalarvalue,  CvArr* dst,
constCvArr* maskCV_DEFAULT(NULL))
{
cvAddS( src, cvScalar( -value.val[0], -value.val[1], -value.val[2], -value.val[3]),
dst,  mask);
}
//从标量中减去数组
/** dst(mask) = value - src(mask) */
CVAPI(void) cvSubRS( constCvArr* src,  CvScalarvalue,  CvArr* dst,
constCvArr* maskCV_DEFAULT(NULL));
//元素级求和
/** Finds sum of array elements */
CVAPI(CvScalar) cvSum( constCvArr* arr);
//二维矩阵的奇异值分解
/** Performs Singular Value Decomposition of a matrix */
CVAPI(void) cvSVD( CvArr*  A, CvArr*  W, CvArr*  UCV_DEFAULT(NULL),
CvArr* VCV_DEFAULT(NULL), intflagsCV_DEFAULT(0));
//奇异值回代计算
/** Performs Singular Value Back Substitution (solves A*X = B):
flags must be the same as in cvSVD */
CVAPI(void) cvSVBkSb( constCvArr* W, constCvArr* U,
constCvArr* V, constCvArr* B,
CvArr* X, intflags);
//计算矩阵迹,对角线元素的总和
/** Calculates trace of the matrix (sum of elements on the main diagonal) */
CVAPI(CvScalar) cvTrace( constCvArr* mat);
//矩阵的转置运算
/** Tranposes matrix. Square matrices can be transposed in-place */
CVAPI(void) cvTranspose( constCvArr* src,  CvArr* dst);
#definecvTcvTranspose
//按位异或操作
/** dst(idx) = src1(idx) ^ src2(idx) */
CVAPI(void) cvXor( constCvArr* src1,  constCvArr*  src2,
CvArr*  dst, constCvArr* maskCV_DEFAULT(NULL));
//数组与标量之间按位异或
/** dst(idx) = src(idx) ^ value */
CVAPI(void) cvXorS( constCvArr* src,  CvScalarvalue,
CvArr* dst,  constCvArr*  maskCV_DEFAULT(NULL));
//所有通道,所有元素置0
CVAPI(void) cvSetZero( CvArr*  arr);
#definecvZerocvSetZero
绘图
1直线
//函数原型
/** @brief Draws 4-connected, 8-connected or antialiased line segment connecting two points
@see cv::line
*/
CVAPI(void) cvLine( CvArr*  img, //图像
CvPointpt1, //直线的起始点
CvPointpt2,
CvScalarcolor, //颜色
intthicknessCV_DEFAULT(1),//线宽
intline_typeCV_DEFAULT(8), //8连通,反走样模式
intshiftCV_DEFAULT(0) );
//画矩形
/** @brief Draws a rectangle given two opposite corners of the rectangle (pt1 & pt2)
if thickness<0 (e.g. thickness == CV_FILLED), the filled box is drawn
@see cv::rectangle
*/
CVAPI(void) cvRectangle( CvArr*  img, 
CvPointpt1,
CvPointpt2,
CvScalarcolor, 
intthicknessCV_DEFAULT(1),
intline_typeCV_DEFAULT(8),
intshiftCV_DEFAULT(0));
2圆形和椭圆
//画圆
/** @brief Draws a circle with specified center and radius.
Thickness works in the same way as with cvRectangle
@see cv::circle
*/
CVAPI(void) cvCircle( CvArr*  img, //图像
CvPointcenter, //圆心
intradius,//半径
CvScalarcolor, //颜色
intthicknessCV_DEFAULT(1),//线宽
intline_typeCV_DEFAULT(8), //
intshiftCV_DEFAULT(0));//
//椭圆
CVAPI(void) cvEllipse( CvArr*  img, //图像
CvPointcenter, //圆心
CvSizeaxes,//高度和宽度
doubleangle, //偏离主轴 的角度 ,x轴逆时针方向为正
doublestart_angle, //开始角度
doubleend_angle,//结束角度
CvScalarcolor, //颜色
intthicknessCV_DEFAULT(1),//线宽
intline_typeCV_DEFAULT(8), 
intshiftCV_DEFAULT(0));
3多边形
//一次可以绘制多个多边形
/** @brief Fills an area bounded by one or more arbitrary polygons
@see cv::fillPoly
*/
CVAPI(void) cvFillPoly( CvArr*  img, 
CvPoint**  pts, 
constint* npts,//记数点构成的数组
intcontours, 
CvScalarcolor,//颜色
intline_typeCV_DEFAULT(8),
intshiftCV_DEFAULT(0) );
//一次只能会制一个多边形,只能画凸多边形
/** @brief Fills convex or monotonous polygon.
@see cv::fillConvexPoly
*/
CVAPI(void) cvFillConvexPoly( CvArr*  img,//图像
constCvPoint* pts,//
intnpts, //
CvScalarcolor,//颜色
intline_typeCV_DEFAULT(8), 
intshiftCV_DEFAULT(0));
//只画边
/** @brief Draws one or more polygonal curves
@see cv::polylines
*/
CVAPI(void) cvPolyLine( CvArr*  img,
CvPoint**  pts, 
constint* npts, 
intcontours,
intis_closed, 
CvScalarcolor, 
intthicknessCV_DEFAULT(1),
intline_typeCV_DEFAULT(8), 
intshiftCV_DEFAULT(0) );
4字体和文字
/** @brief Renders text stroke with specified font and color at specified location.
CvFont should be initialized with cvInitFont
@see cvInitFont, cvGetTextSize, cvFont, cv::putText
*/
CVAPI(void) cvPutText( CvArr*  img, //图像
constchar* text, //文字内容
CvPointorg,//文本框左下角的位置
constCvFont* font, //字体格式
CvScalarcolor);//颜色
//初始化字体格式
CVAPI(void) cvInitFont( CvFont*  font, //自定义的字体变量
intfont_face,//可用字体变量
doublehscale, //渲染时选择全高(1.0)半高(0.5)
doublevscale,//创建斜体字
doubleshearCV_DEFAULT(0),
intthicknessCV_DEFAULT(1),
intline_typeCV_DEFAULT(8));
可用字体
#defineCV_FONT_HERSHEY_SIMPLEX0
#defineCV_FONT_HERSHEY_PLAIN1
#defineCV_FONT_HERSHEY_DUPLEX2
#defineCV_FONT_HERSHEY_COMPLEX3
#defineCV_FONT_HERSHEY_TRIPLEX4
#defineCV_FONT_HERSHEY_COMPLEX_SMALL5
#defineCV_FONT_HERSHEY_SCRIPT_SIMPLEX6
#defineCV_FONT_HERSHEY_SCRIPT_COMPLEX7
示例代码如下:
/*
绘图
*/
intacmeArr1[2];
CvPointpointArr2[3];
voiddrawing() {
//读入图像
IplImage*img = cvLoadImage("test2.jpg");
//直线的起始点
CvPointpit1= cvPoint(10, 10);
CvPointpit2 = cvPoint(100,200);
//线的颜色
CvScalarcolor= cvScalar(255, 0, 0);
//画线
//cvLine(img, pit1, pit2, color,2,8,0);
//画矩形
//cvRectangle(img,pit1,pit2,color,CV_FILLED);
//画圆形
//cvCircle(img,pit2,100,color,CV_FILLED);
//画椭圆
//CvSize eSize = cvSize(100, 50);
//cvEllipse(img,pit2,eSize,0,0,360,color);
//画多边形
//一次可以同时画多个多边形,全填充
//初始化多边开数组
CvPoint** pointArrs =  newCvPoint*[2];
pointArrs[0] = newCvPoint[3];
pointArrs[1] = newCvPoint[4];
intacmeArr1[2] = { 3,4 };
//三角形
pointArrs[0][0] =cvPoint(200,40);
pointArrs[0][1] =cvPoint(150, 80);
pointArrs[0][2]=cvPoint(250, 80); 
//四边形
pointArrs[1][0] =cvPoint(150, 100);
pointArrs[1][1] =cvPoint(250, 100);
pointArrs[1][2]=cvPoint(250, 200);
pointArrs[1][3]=cvPoint(150, 200); 
//初始化顶点数组
cvFillPoly(img, pointArrs, acmeArr1,2,color);
//一次只能画一个多边形
//初始化多边开数组
//pointArr2[1]= cvPoint(100, 100);
//pointArr2[2] = cvPoint(100, 300);
//pointArr2[3] = cvPoint(200, 400);
//顶点数
//int num = 3;
//cvFillConvexPoly(img, pointArr2, num,color);
//只连线画边
//cvPolyLine(img, pointArrs, acmeArr1, 2,true, color);
//字体与文字
//初始化字体格式
//CvFont myFont;
//cvInitFont(&myFont,CV_FONT_HERSHEY_COMPLEX,1.0,1.0,0.0);
//cvPutText(img,"hello retacn!",pit2,&myFont,color);
//创建窗体
cvNamedWindow("Drawing"); 
//显示图像
cvShowImage("Drawing", img);
cvWaitKey(); 
}
数据存储
存储的格式有
图片:
//保存图像
/* save image to file */
CVAPI(int) cvSaveImage( constchar* filename,//文件名称s
constCvArr* image,//图像
constint* paramsCV_DEFAULT(0) );
//加载图像
/* load image from file
iscolor can be a combination of above flags where CV_LOAD_IMAGE_UNCHANGED
overrides the other flags
using CV_LOAD_IMAGE_ANYCOLOR alone is equivalent to CV_LOAD_IMAGE_UNCHANGED
unless CV_LOAD_IMAGE_ANYDEPTH is specified images are converted to 8bit
*/
CVAPI(IplImage*) cvLoadImage( constchar* filename,  intiscolorCV_DEFAULT(CV_LOAD_IMAGE_COLOR));
CVAPI(CvMat*) cvLoadImageM( constchar* filename,  intiscolorCV_DEFAULT(CV_LOAD_IMAGE_COLOR));
cvMat的读取
CVAPI(void) cvSave( constchar* filename, //文件名
constvoid* struct_ptr,//
constchar* nameCV_DEFAULT(NULL),
constchar* commentCV_DEFAULT(NULL),
CvAttrListattributesCV_DEFAULT(cvAttrList()));
CVAPI(void*) cvLoad( constchar* filename,
CvMemStorage*  memstorageCV_DEFAULT(NULL),
constchar* nameCV_DEFAULT(NULL),
constchar** real_nameCV_DEFAULT(NULL) );
视频的读取
/* grab a frame, return 1 on success, 0 on fail.
this function is thought to be fast */
CVAPI(int) cvGrabFrame( CvCapture*  capture);
/* initialize video file writer */
CVAPI(CvVideoWriter*) cvCreateVideoWriter( constchar* filename,  intfourcc,
doublefps, CvSizeframe_size,
intis_colorCV_DEFAULT(1));
/* write frame to video file */
CVAPI(int) cvWriteFrame( CvVideoWriter*  writer, constIplImage* image);
/*
往磁盘上写一个配置文件
*/
voidwriteCfg() {
CvMat* cmatrix=cvCreateMat(2,3,CV_8UC3);
CvFileStorage* fs = cvOpenFileStorage(
"cfg.xml",
0,
CV_STORAGE_WRITE//写数据,读数扰为CV_STORAGE_READ
);
cvWriteInt(fs, "frame_count", 10); 
cvStartWriteStruct(fs, "frame_size", CV_NODE_SEQ);//开始结构编写
cvWriteInt(fs, 0, 320);
cvWriteInt(fs, 0, 200);
cvEndWriteStruct(fs);//结构结束
cvWrite(fs, "color_cvt_matrix", cmatrix);//色彩转换矩阵
cvReleaseFileStorage(&fs);//释放cvFileStorage
}
生成文件的内容如下:
<?xml version="1.0"?>
<opencv_storage>
<frame_count>10</frame_count>
<frame_size>
320 200</frame_size>
<color_cvt_matrix type_id="opencv-matrix">
<rows>2</rows>
<cols>3</cols>
<dt>"3u"</dt>
<data>
205 205 205 205 205 205 205 205 205 205 205 205 205 205 205 205 205
205</data></color_cvt_matrix>
</opencv_storage>
/*
读取配置文件
*/
voidreadCfg() {
CvFileStorage* fs = cvOpenFileStorage(
"cfg.xml",
0,
CV_STORAGE_READ//写数据,读数扰为CV_STORAGE_READ
);
intframe_count = cvReadIntByName(
fs,
0,
"frame_count",
5
);
//得到结构体
CvSeq* s = cvGetFileNodeByName(fs, 0, "frame_size")->data.seq;
intframe_width = cvReadInt((CvFileNode*)cvGetSeqElem(s,0));
intframe_height = cvReadInt((CvFileNode*)cvGetSeqElem(s, 1));
CvMat* color_cvt_matrix = (CvMat*)cvReadByName(
fs,
0,
"color_cvt_matrix"
);
cvReleaseFileStorage(&fs);
}
数据存储常用函数
cvOpenFileStorage//为读写打开文件
cvReleaseFileStorage//释放存储的数据
写操作
cvStartWriteStruct//开始写入新的数据结构
cvEndWriteStruct//结束写入数据结构
cvWriteInt//写入整型
cvWriteReal//写入浮点型
cvWriteString//写入字符串
cvWriteComment//写入一个注释定串
cvWrite//写入一个对象
cvWriteRawData//写入多个数值
cvWriteFileNode//将文件结点写入另一个文件存储器
读操作
cvGetRootFileNode//取得存储器的根节点
cvGetFileNodeName//返回文件节点名
cvGetHashedKey//为名称返回一个唯一的指什
cvGetFileNode//在映图或文件存储器中找到节点
cvGetFileNodeByName//在映图或存储器中找到相应节点
cvReadInt//读取整型
cvReadIntByName//读取一个有名称的整型
cvReadReal//读取浮点型
cvReadRealByName//读取一个有名称的浮点型
cvReadString//从文件节点取字符串
cvReadStringByName//根据名称查取得文件节点
cvRead//找到对象解码并返回指针
cvReadByName//打到对象并解码
cvReadRawData//读取多个数值
cvStartReadRawData//初始化文件结点序列的读取
cvReadRawDataSlice//读取文件节点的内容