首页 > 其他 > 详细

opencv::Mat属性

时间:2019-09-03 14:40:38      阅读:201      评论:0      收藏:0      [点我收藏+]

 

Mat对象OpenCV2.0之后引进的图像数据结构、自动分配内存、不存在内存泄漏的问题,是面向对象的数据结构。
分了两个部分,头部与数据部分。

IplImage是从2001年OpenCV发布之后就一直存在,是C语言风格的数据结构,需要开发者自己分配与管理内存,对大的程序使用它容易导致内存泄漏问题。

 

//默认构造函数 Mat A;
Mat ()

//常用构造函数 Mat A(10,10,8UC3);
Mat (int rows, int cols, int type)

//Mat A(300, 400, CV_8UC3,Scalar(255,255,255));
Mat (int ndims, const int *sizes, int type, const Scalar &s)

//Mat D (A, Rect(10, 10, 100, 100) );
Mat (const Mat &m, const Rect &roi)

Mat (Size size, int type)
Mat (int rows, int cols, int type, const Scalar &s)
Mat (Size size, int type, const Scalar &s)
Mat (int ndims, const int *sizes, int type)
Mat (const Mat &m)
Mat (int rows, int cols, int type, void *data, size_t step=AUTO_STEP)
Mat (Size size, int type, void *data, size_t step=AUTO_STEP)
Mat (int ndims, const int *sizes, int type, void *data, const size_t *steps=0)
Mat (const Mat &m, const Range &rowRange, const Range &colRange=Range::all())
Mat (const Mat &m, const Range *ranges)

 

常用方法:
void copyTo(Mat mat)
void convertTo(Mat dst, int type)
Mat clone()
int channels()
int depth()
bool empty();
uchar* ptr(i=0)


输出图像的内存是自动分配的
使用OpenCV的C++接口,不需要考虑内存分配问题
赋值操作和拷贝构造函数只会复制头部分
使用clone与copyTo两个函数实现数据完全复制

部分复制:一般情况下只会复制Mat对象的头和指针部分,不会复制数据部分
Mat A= imread(imgFilePath)  
Mat B(A)  // 只复制 头和指针部分

完全复制:如果想把Mat对象的头部和数据部分一起复制,可以通过如下两个API实现
Mat F = A.clone();
Mat G; A.copyTo(G);

 

opencv::Mat属性

原文:https://www.cnblogs.com/osbreak/p/11452433.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!