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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值