Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV - IplImage

What is IplImage in OpenCV? Can you just explain what is meant by it as a type? When should we use it?

Thanks.

like image 882
Simplicity Avatar asked Mar 04 '11 10:03

Simplicity


2 Answers

Based on the 'c++' tag you have in your question: You should not use it, you should use cv::Mat. Every IplImage is a cv::Mat internally.

IplImage is only used in the C API. It is a kind of CvMat and holds image data. Its name originates from OpenCV's roots (Intel IPL).

It is not relevant anymore if you use the C++ API of OpenCV.

like image 181
ypnos Avatar answered Oct 22 '22 08:10

ypnos


IplImage and cv::Mat are different header types for matrix/image data. They're basically compatible with each other, but IplImage is used in OpenCV's C API, while cv::Mat is used in the new C++ API.

When you decide to use OpenCV's C API, you will mostly use IplImages. Otherwise you will mostly use cv::Mats.

Of course, you can convert IplImages and cv::Mats to each other, e.g.

cv::Mat mat(myIplImage);

In this case, they share the same underlying data, i.e. modifications made through either header will be visible regardless of what header you're using to access the data.

Deep-copy (not only header is "transformed"/copied, but also the underlying data) is possible with

cv::Mat mat(myIplImage, true)

Note that multiple IplImages can also point to the same underlying data, as can multiple cv::Mats.


When working with OpenCV and similar libraries it is important to notice that cv::Mats and IplImages are only "headers" for the actual data. You could say that cv::Mats and IplImages are basically pointers plus important meta information like number of rows, columns, channels and the datatype used for individual cells/pixels of the matrix/image. And, like real pointers, they can reference/point to the same real data.

For example, look at the definition of IplImage: http://opencv.willowgarage.com/documentation/basic_structures.html#iplimage

The most important member is char *imageData;. This pointer references the actual image data. However, the IplImage as a whole contains meta information about the image as well, like number of rows and columns.

like image 21
robert Avatar answered Oct 22 '22 09:10

robert