// Note: deep copy – separately allocated space, two independent
CvMat* a;
CvMat* b = cvCloneMat(a); //copy a to b
// 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
// 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
// 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);
// Note: shallow copy – again, just to create an image first, but not to copy data
Mat M;
IplImage img = M;
IplImage img = IplImage(M);
// 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
// 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