Article from: http://blog.sina.com.cn/s/blog_67eb1f2f0100z35o.html
At type has stronger matrix operation capability than cvmat and iplimage, and supports common matrix operations (refer to various matrix operations in MATLAB ), therefore, converting iplimage and cvmat to mat makes data processing easier.
The mat type can be used to directly store image information. It can be implemented through functions such as imread, imwrite, and imshow (similar to the functions in MATLAB). It seems that the iplimage type can be replaced to some extent.
(1) convert the iplimage type to the mat type
MAT: MAT (const iplimage * IMG, bool copydata = false );
By default, the new mat type shares image data with the original iplimage type. The conversion only creates a mat matrix header. When the parameter copydata is set to true, the entire image data is copied.
Example:
Iplimage * iplimg = cvloadimage ("greatwave.jpg", 1 );
Mat CTX (iplimg); // iplimage *-> mat share data
// Or: mat CTX = iplimg;
(2) convert the mat type to the iplimage type
Create an image header without copying data.
Example:
Iplimage ipl_img = IMG; // mat-> iplimage
(3) convert the cvmat type to the mat type
Similar to iplimage conversion, you can choose whether to copy data.
MAT: MAT (const cvmat * m, bool copydata = false );
(4) convert the mat type to the cvmat type
Similar to iplimage conversion, only matrix headers are created without copying data.
Example:
// Assume that mat-type imgmat image data exists
Cvmat = imgmat; // mat-> cvmat