Converting mat, iplimage, and cvmat types in opencv

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.