Conversion between mat and Iplimage,cvmat type in OPENCV

Source: Internet
Author: User

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

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.