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, via functions Imread, Imwrite, Imshow, and so on (similar to functions in MATLAB). Mat is opencv2.0 's new data structure for image processing, and there are more and more trends replacing the previous Cvmat and lplimage, compared to the greatest benefit of mat is the ability to manage memory more easily, eliminating the need for programmers to manually manage the release of memory.
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.
Iplimage -Matmat::mat (constbool copydata=false); /* The default Copydata=false, which shares data with the original Iplimage, just creates a matrix header */ Example: Iplimage* iplimg = Cvloadimage ("greatwave.jpg"1 /* Iplimage *-Mat, shared data; Or:mat MTX = iplimg; */
2. Convert mat type to Iplimage type
Mat-*/* Create only image headers, do not copy data */
3. Convert the Cvmat type to mat type
Cvmat- Matmat::mat (constbool copydata=false/* similar to Iplimage- > Mat to choose whether to copy data * /
4. Convert mat type to Cvmat type
Mat,= Imgmat; /* Mat--Cvmat, similar to convert to Iplimage, do not copy data only create Matrix header
Conversion between mat and Iplimage,cvmat type in OPENCV