1,、CvMat之間的復(fù)制 //注意:深拷貝 - 單獨分配空間,兩者相互獨立 CvMat* a; CvMat* b = cvCloneMat(a); //copy a to b 2,、Mat之間的復(fù)制 //注意:淺拷貝 - 不復(fù)制數(shù)據(jù)只創(chuàng)建矩陣頭,,數(shù)據(jù)共享(更改a,b,c的任意一個都會對另外2個產(chǎn)生同樣的作用) Mat a; Mat b = a; //a "copy" to b Mat c(a); //a "copy" to c //注意:深拷貝 Mat a; Mat b = a.clone(); //a copy to b Mat c; a.copyTo(c); //a copy to c 3、CvMat轉(zhuǎn)Mat //使用Mat的構(gòu)造函數(shù):Mat::Mat(const CvMat* m, bool copyData=false); 默認(rèn)情況下copyData為false CvMat* a; //注意:以下三種效果一致,,均為淺拷貝 Mat b(a); //a "copy" to b Mat b(a, false); //a "copy" to b Mat b = a; //a "copy" to b //注意:當(dāng)將參數(shù)copyData設(shè)為true后,,則為深拷貝(復(fù)制整個圖像數(shù)據(jù)) Mat b = Mat(a, true); //a copy to b 4、Mat轉(zhuǎn)CvMat //注意:淺拷貝 Mat a; CvMat b = a; //a "copy" to b //注意:深拷貝 Mat a; CvMat *b; CvMat temp = a; //轉(zhuǎn)化為CvMat類型,,而不是復(fù)制數(shù)據(jù) cvCopy(&temp, b); //真正復(fù)制數(shù)據(jù) cvCopy使用前要先開辟內(nèi)存空間 ==========IplImage與上述二者間的轉(zhuǎn)化和拷貝=========== 1,、IplImage之間的復(fù)制 2,、IplImage轉(zhuǎn)Mat //使用Mat的構(gòu)造函數(shù):Mat::Mat(const IplImage* img, bool copyData=false); 默認(rèn)情況下copyData為false IplImage* srcImg = cvLoadImage("Lena.jpg"); //注意:以下三種效果一致,,均為淺拷貝 Mat M(srcImg); Mat M(srcImg, false); Mat M = srcImg; //注意:當(dāng)將參數(shù)copyData設(shè)為true后,則為深拷貝(復(fù)制整個圖像數(shù)據(jù)) Mat M(srcImg, true); 3,、Mat轉(zhuǎn)IplImage //注意:淺拷貝 - 同樣只是創(chuàng)建圖像頭,,而沒有復(fù)制數(shù)據(jù) Mat M; IplImage img = M; IplImage img = IplImage(M); //深拷貝 cv::Mat img2; IplImage imgTmp = img2; IplImage *input = cvCloneImage(&imgTmp); 4、IplImage轉(zhuǎn)CvMat //法一:cvGetMat函數(shù) IplImage* img; CvMat temp; CvMat* mat = cvGetMat(img, &temp); //深拷貝 //法二:cvConvert函數(shù) CvMat *mat = cvCreateMat(img->height, img->width, CV_64FC3); //注意height和width的順序 cvConvert(img, mat); //深拷貝 5,、CvMat轉(zhuǎn)IplImage //法一:cvGetImage函數(shù) CvMat M; IplImage* img = cvCreateImageHeader(M.size(), M.depth(), M.channels()); cvGetImage(&M, img); //深拷貝:函數(shù)返回img //也可寫成 CvMat M; IplImage* img = cvGetImage(&M, cvCreateImageHeader(M.size(), M.depth(), M.channels())); //法二:cvConvert函數(shù) CvMat M; IplImage* img = cvCreateImage(M.size(), M.depth(), M.channels()); cvConvert(&M, img); //深拷貝
|
|
來自: 昵稱17328427 > 《cv》