OpenCV: IplImage versus Mat, which to use?

后端 未结 11 1119
一整个雨季
一整个雨季 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:05

    I would say this would actually depend on the platform that you are going to run your application on. If you are developing an application for an embedded system you would be more likely to use C. In that case you would have to use IplImage. Quoting from the tutorial:

    The main downside of the C++ interface is that many embedded development systems at the moment support only C. Therefore, unless you are targeting embedded platforms, there’s no point to using the old methods (unless you’re a masochist programmer and you’re asking for trouble).

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

    I began to use opencv about in 2012 or so .So I began with Mat,which is powerful and easy to use.BUT to read or reuse these code that was "old",i had to kown sth about iplimages,it is easy to use,also. But the future is Mat,I think.And dont forget Mat in a CLASS,that means,you dont need to release a Mat.On the other hand,you SHOULD to free a implimage. My English is poor,sorry.

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

    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)

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

    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!

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

    I believe using cv::Mat is much more convenient. it is more generic. We can see IplImage being a subset of cv::Mat. The default datatype for IplImage is unsigned integer while that for cv::Mat is double. So it is much more easy to use Mat for any kind of mathematical operation.

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

    thanks for the help.

    I also discovered since posting this question that a function with a Mat as a argument can take an IplImage directly in the place of that Mat argument, which makes it pretty easy to update your code in chunks if it's already broken into convenient functions. Just change the function arguments from IplImage* to Mat, then modify the function to work on a Mat. Other code calling that function should still work fine (it has in my experience).

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