Image Processing in opencv is the most basic operation. Generally, the image type is iplimage. However, when we process images, most of them process the pixel matrix, therefore, the conversion between the three types will facilitate our work.
Compared with cvmat and iplimage, the mat type has stronger matrix operation capabilities 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 );
Matctx (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