CvMat, Mat IplImage转换

CvMat之间的复制

// Note: deep copy – separately allocated space, two independent
CvMat* a;
CvMat* b = cvCloneMat(a);   //copy a to b

Mat 之间的复制:浅拷贝,深拷贝

// Note: shallow copy – not just copy the data to create a matrix head, data sharing (change a, b, c of the same effect will be on any one of the other two production)
Mat a;
Mat b = a; //a “copy” to b
Mat c(a); //a “copy” to c
// Note: deep copy
Mat a;
Mat b = a.clone(); //a copy to b
Mat c;
a.copyTo(c); //a copy to c

CvMat --> Mat

// Use the constructor Mat: Mat :: Mat (const CvMat * m, bool copyData = false); copyData default is false
CvMat* a;
// Note: the following three consistent results, are shallow copy
Mat b(a);   //a “copy” to b
Mat b(a, false);    //a “copy” to b
Mat b = a;  //a “copy” to b
// Note: When the parameter copyData set to true, it was a deep copy (copying the entire image data)
Mat b = Mat(a, true); //a copy to b

Mat ----> CvMat

// Note: shallow copy
Mat a;
CvMat b = a; //a “copy” to b
// Note: deep copy
Mat a;
CvMat *b;
CvMat temp = a;  // into CvMat type, instead of copying data
CVCopy  (& temp, b);  // true copy data

IplImage --> Mat

// Use the constructor Mat: Mat :: Mat (const IplImage * img, bool copyData = false); default is false copyData
IplImage* srcImg = cvLoadImage(“Lena.jpg”);
// Note: the following three consistent results, are shallow copy
Mat M(srcImg);
Mat M(srcImg, false);
Mat M = srcImg;
// Note: When the parameter copyData set to true, it was a deep copy (copying the entire image data)
Mat M(srcImg, true);

Mat --> IplImage

// Note: shallow copy – again, just to create an image first, but not to copy data
Mat M;
IplImage img = M;
IplImage img = IplImage(M);

IplImage --> CvMat

// Method a: cvGetMat function
IplImage* img;
CvMat temp;
CvMat* mat = cvGetMat(img, &temp);  //深拷贝
// Act II: cvConvert function
CvMat *mat = cvCreateMat(img->height, img->width, CV_64FC3);  //注意height和width的顺序
cvConvert (img, mat);     // a deep copy

CvMat --> IplImage

// Method a: cvGetImage function
CvMat M;
IplImage* img = cvCreateImageHeader(M.size(), M.depth(), M.channels());
cvGetImage (& M, img);     // a deep copy: The function returns img
// Also be written as
CvMat M;
IplImage* img = cvGetImage(&M, cvCreateImageHeader(M.size(), M.depth(), M.channels()));
// Act II: cvConvert function
CvMat M;
IplImage* img = cvCreateImage(M.size(), M.depth(), M.channels());
cvConvert (& M, img);  // a deep copy
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值