mat 和IPIImage之间的转换

opencv2.3.1

Mat::operator IplImage
Creates the IplImage header for the matrix.
C++: Mat::operator IplImage() const
The operator creates the IplImage header for the matrix without copying the underlying data. You should make sure
than the original matrix is not deallocated while the IplImage header is used. Similarly to Mat::operator CvMat ,
the operator is useful for intermixing the new and the old OpenCV API’s.

imread
Loads an image from a file.
C++: Mat imread(const string& filename, int flags=1 )
Python: cv2.imread(filename[, flags ]) !retval
C: IplImage* cvLoadImage(const char* filename, int flags=CV_LOAD_IMAGE_COLOR )
C: CvMat* cvLoadImageM(const char* filename, int flags=CV_LOAD_IMAGE_COLOR )
Python: cv.LoadImage(filename, flags=CV_LOAD_IMAGE_COLOR)! None
Python: cv.LoadImageM(filename, flags=CV_LOAD_IMAGE_COLOR)! None
Parameters
filename – Name of file to be loaded.
flags – Flags specifying the color type of a loaded image

– >0 Return a 3-channel color image
– =0 Return a grayscale image
– <0 Return the loaded image as is. Note that in the current implementation the alpha
channel, if any, is stripped from the output image. For example, a 4-channel RGBA
image is loaded as RGB if flags  0 .

Backward conversion from Mat to CvMat or IplImage is provided via cast operators Mat::operator
CvMat() const and Mat::operator IplImage(). The operators do NOT copy the data.
IplImage* img = cvLoadImage("greatwave.jpg", 1);
Mat mtx(img); // convert IplImage* -> Mat
CvMat oldmat = mtx; // convert Mat -> CvMat
CV_Assert(oldmat.cols == img->width && oldmat.rows == img->height &&
oldmat.data.ptr == (uchar*)img->imageData && oldmat.step == img->widthStep);

是时候好好总结下自己走过的路。
原文地址:https://www.cnblogs.com/haoxing990/p/4574681.html