cv::Mat与IplImage 的相互转换

From IplImage or CvMat to cv::Mat:
from definition of cv::Mat
// converts old-style CvMat to the new matrix; the data is not copied by
default
Mat(const CvMat* m, bool copyData=false);
// converts old-style IplImage to the new matrix; the data is not copied by
default
Mat(const IplImage* img, bool copyData=false);

So:
IplImage *myIplImage = cvCreateImage(...);
Mat myIplImageMat=Mat(myIplImage,true); //true if you wish an independent copy
else it will change myIplImage data

Vice-Versa:
again, from the definition of cv::Mat
// converts header to CvMat; no data is copied
operator CvMat() const;
// converts header to IplImage; no data is copied
operator IplImage() const;

That is:

Mat myMat=Mat(...);
IplImage myIplImageMat=myMat; //without * !!!
cvWhatEverOldCFunction(&myMat,...other arguments);

With CvMat is the same.

你可能感兴趣的:(image)