I'm pretty new to OpenCV (about 2 months now). I have the book Learning OpenCV by Bradski and Kaehler. My question is, if I want to do everything in a 2.0+ manner, when should I use Matrices (Mat) and when should I use IplImage?
Bradky's book states upfront (Preface) that it's written based on OpenCV 2.0, and it mostly uses IplImage in its sample code, but the more recent online documentation makes it sound like Mat is now a catch-all data type for images, masks, etc, kind of like a basic matrix in Matlab. This leaves me wondering if IplImage should be considered obsolete.
So, should I be totally avoiding IplImages when writing new code? Or is there important stuff IplImages allow me to do that Mats do not?
Thanks.
The IplImage is taken from the Intel Image Processing Library, in which the format is native. OpenCV only supports a subset of possible IplImage formats, as outlined in the parameter list above. In addition to the above restrictions, OpenCV handles ROIs differently.
The Mat class of OpenCV library is used to store the values of an image. It represents an n-dimensional array and is used to store image data of grayscale or color images, voxel volumes, vector fields, point clouds, tensors, histograms, etc.
IplImage
has been in OpenCV since the very beginning. It is a part of the C interface for OpenCV. You need to allocate and deallocate memory for IplImage
structures yourself. (remember the cvReleaseImage
commands?)
The new Mat
structure is a part of the C++ structure. So obviously it is object oriented. Also, it manages all memory for you! It keeps a track of references to it. Then the number of references goes to zero, it deallocates automatically. This is one superb feature!
Go for Mat
. It should be easy to translate code from the IplImage
thingy to the Mat
thingy if you are using some IDE that has Intellisense (it drops down a list of possible functions, variables, etc as you type)
I would highly recommend using Mat
. I've been using it for a while, and it's great. The member functions and the matrix expressions make things much simpler than dealing with IplImage
and as you said it's a catch-all data type.
Go for Mat
!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With