OPENCV 2. 数据结构
来源:互联网 发布:数据库的定义及特点 编辑:程序博客网 时间:2024/06/14 12:12
Opencv的数据结构定义于types_c.h中,下面对其一一介绍:
a. CvRect 矩形类
typedef struct CvRect{ int x; int y; int width; int height;}CvRect;
x和y表示矩形的起始坐标,而width和height则表示矩形的宽和高;其构造函数为:
CV_INLINE CvRect cvRect( int x, int y, int width, int height ){ CvRect r; r.x = x; r.y = y; r.width = width; r.height = height; return r;}
此外还有IplROI也类似于矩形类;
b. CvPoint 点类
typedef struct CvPoint{ int x; int y;}CvPoint;
CV_INLINE CvPoint cvPoint( int x, int y ){ CvPoint p; p.x = x; p.y = y; return p;}
此外还有表示浮点型的点:CvPoint2D32f、CvPoint2D64f;三维点CvPoint3D32f、cvPoint2D64f;
c. 尺寸类
typedef struct CvSize{ int width; int height;}CvSize;
同样有构造函数 CV_INLINE CvSize cvSize( int width, int height ),和更高精度的尺寸类CvSize2D32f;
d. 颜色类
typedef struct CvScalar{ double val[4];}CvScalar;
表示图像的B(blue)、G(green)、R(red)、alpha - 图像的透明度;构造函数有:
CV_INLINE CvScalar cvScalar( double val0, double val1 CV_DEFAULT(0), double val2 CV_DEFAULT(0), double val3 CV_DEFAULT(0))CV_INLINE CvScalar cvRealScalar( double val0 )CV_INLINE CvScalar cvScalarAll( double val0123 )
e. 矩阵类
typedef struct CvMat{ int type; // 数据类型,经过计算后的一串数字 int step; // 一行数据的长度,单位为字节 /* for internal use only */ int* refcount; // 数据引用计数,内部使用,不用管 int hdr_refcount; union { uchar* ptr; short* s; int* i; float* fl; double* db; } data; // 数据地址#ifdef __cplusplus union { int rows; int height; }; union { int cols; int width; };#else int rows; int cols;#endif}CvMat;
1.大多数情况下,step等于 width * 单个数据的长度,但是也存在例外情况
2.ptr、s、i、fl和db表示的是同一个地址。CvMat这样进行定义的目的是为了更好的操作数据;
3.Mat A = B;这时只进行浅拷贝,如果需要用到深拷贝,则需要使用cvCloneMat
int main() { double AA[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; CvMat Ma=cvMat(3, 4, CV_64FC1, AA); CvMat Mb = Ma; CvMat * Mc = cvCloneMat(&Ma); printf("Address of AA = %d\nAddress of Ma = %d\nAddress of Mb = %d\nAddress of Mc = %d\n", (int)AA, (int)Ma.data.ptr, (int)Mb.data.ptr, (int)Mc->data.ptr); cvReleaseMat(&Mc);}
得到的结果是:
Address of AA = 1964272
Address of Ma = 1964272
Address of Mb = 1964272
Address of Mc = 3658064
f. IplImage图像类
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;
1.roi是图像的感兴趣的区域,当进行显示时,只会显示感兴越区域;
2.cvCopy会拷贝图像的感兴趣区域,而cvCloneImage则会拷贝所有的值;
阅读全文
0 0
- OPENCV 2. 数据结构
- opencv 数据结构
- OpenCV----OpenCV基础数据结构
- opencv 数据结构之一opencv cvScalar
- openCV 常用数据结构
- [转]OpenCV: 数据结构
- OpenCV基础数据结构
- OpenCV 基础数据结构 家谱!
- openCV-cvMat数据结构
- openCV-cvMat数据结构
- opencv常用数据结构
- opencv数据结构CvScalar
- OpenCV基础数据结构
- openCV-cvMat数据结构
- OpenCV的序列数据结构
- OpenCV数据结构CvMemStorage
- OpenCV IplImage数据结构
- opencv 基本数据结构
- MySQL 5.7.20免安装版安装教程
- OnTouch关于performClick的Warning
- 最新vue-cli 2.9.1的webpack存在问题
- 自动化测试
- HDU4825 01trie+二进制
- OPENCV 2. 数据结构
- 远程连接MYSQL提示Host is not allowed to connect to this MySQL server
- 【机房管理】上下机
- HDU 2141-Can you find it?
- mysql函数扩展之UDF开发
- 阿里云服务器外部访问8080端口方法-阿里云安全规则
- 浅谈M、V、VM
- How to configure MailEnable to send emails on Google Cloud Platform instance?
- linux环境tcpdump使用时提示无法只好打该用户命令。