OPENCV image processing is the most basic operation, the general image type is the iplimage type, but when we process the image, most of the pixel matrix is processed, so the conversion between these three types will be convenient for our work
The mat type has stronger matrix operations than Cvmat and iplimage and supports common matrix operations (referencing various matrix operations in MATLAB), so converting iplimage and Cvmat types to mat types is easier to process.
The mat type can be used to store image information directly, through functions such as Imread, Imwrite, Imshow, and so on (similar to functions in MATLAB), which seems to replace the iplimage type in some way.
(1) Convert iplimage type to mat type
Mat::mat (const iplimage* IMG, bool copydata=false);
By default, the new mat type shares the image data with the original Iplimage type, and the conversion simply creates a mat matrix header. When the parameter copydata is set to true, the entire image data is copied.
Cases:
iplimage*iplimg = Cvloadimage ("greatwave.jpg", 1);
MATMTX (IPLIMG); iplimage*->mat sharing data
Or:mat MTX = iplimg;
(2) Convert mat type to Iplimage type
The same is just creating the image header without copying the data.
Cases:
Iplimage ipl_img = img; Mat-Iplimage
(3) Convert the Cvmat type to mat type
Similar to the conversion of iplimage, you can choose whether to copy data.
Mat::mat (const cvmat* m, bool copydata=false);
(4) Convert mat type to Cvmat type
Similar to the conversion of iplimage, the data is not copied and only the matrix header is created.
Cases:
Assume that the Imgmat image data for the mat type exists
Cvmat Cvmat = Imgmat; Mat-Cvmat
Conversion between mat and Iplimage,cvmat type in OPENCV