首页 > 其他分享 >mat 和IPIImage之间的转换

mat 和IPIImage之间的转换

时间:2023-02-02 15:01:08浏览次数:41  
标签:转换 Mat img IPIImage flags operator filename IplImage mat

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);

标签:转换,Mat,img,IPIImage,flags,operator,filename,IplImage,mat
From: https://www.cnblogs.com/kn-zheng/p/17086032.html

相关文章