OpenCV: IplImage versus Mat, which to use?

后端 未结 11 1120
一整个雨季
一整个雨季 2020-12-13 01:56

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 sho

相关标签:
11条回答
  • 2020-12-13 02:15

    Iplimage is some structure of C interface in Opencv, and Mat is more suitable for C++ program and support some C++ styles like ref parameter and stream operator, etc. Although they are all object oriented programming, Mat includes more methods itself than Iplimage does, like create and release, which Ipliamge would call some cvXXX interface to complete. Moreover, Mat is a new structure from Opencv2, which I think is symbol of development for the old ones. I wish it help.

    0 讨论(0)
  • 2020-12-13 02:17

    Mat is much easier and easier to use. It represents the image as a matrix. it is faster too. I would recommend Mat over IplImage.

    0 讨论(0)
  • 2020-12-13 02:18

    I'd suggest Mat. The garbage collection is automatic, and thus the application is more reliable and has fewer memory leaks. Also, Mat is a newer way of data storage, so if you are a newbie, just starting off with OpenCV, Mat is newer, and requires less careful coding to make a complete application.

    Compatibility is one thing that Mat will be a tad worse in. IplImage has been available longer and thus, has a greater compatibility with most things. I believe you can use IplImage with Mat too, and if not, IplImage>Mat is also quite simple to perform.

    Since Iplimage has been available for a much longer period of time, you will probably find a greater selection of samples.

    Here are my two cents: As a rookie(still learning tricks) in vision processing with OpenCV, pick one, Mat or IplImage and get really good at it. However, learn at least the basics of the other so you know what to do if you need to use a function that doesn't not compatible with the other.

    But to repeat myself, if you are a newbie, try to start with Mat. Since it is a newer implementation, it is easier to learn and get right!

    0 讨论(0)
  • 2020-12-13 02:22

    Quick update:

    With the advent of OpenCV 4, the answer to the question will be more straightforward as the IplImage and all of what they now call "the legacy C API" will be progressively removed. In OpenCV 4.0 "alpha", IplImage is already gone - as is CvMat.

    So, if you work with OpenCV4.0+, use the Mat Class... because you don't have the choice.

    [NB: Of course, if you still use older version of OpenCV, the question is still relevant.]

    0 讨论(0)
  • 2020-12-13 02:28

    When writing a Blob detection routine I noticed that using

    IplImage* img;
    uchar* image_src = (uchar*)img->imageData;
    image_src[x+y*width] = ...;
    

    Is much faster than using

    Mat image;
    image.at<uchar>(x,y) = ...;
    

    About 5x faster. Some of this may be because I used a nested X,Y loop for Mat and a single loop for IplImage. But if you have to write any routines that work directly off pixels I would stick with IplImage.

    0 讨论(0)
提交回复
热议问题