k this is kind of noob of me since I really haven't worked on C and objective c all that much.
Mat mymat(myIplImage, true);
This apparently not only declares mymat as a local variable but also copies the contents over from myIplImage. The problems I can't make of the synt开发者_开发技巧ax. I would be more comfortable if it were something like this:
Mat mymat = new Mat(myIplImage, true); // in c++
Can you explain what happened in the background for the original statement?
Thanks,
This is C++ actually. The first statement does basically the same thing as the second statement except that you don't handle the memory yourself, that is you don't have to delete mymat
when you don't need it anymore, it will be destructed automatically when it goes out of scope.
As stated by Simon, the first version handles the memory allocation for you. In the first version, behind the scenes, there's probably a new
call or malloc
or something similar in the constructor, and a delete
or free
call in the destructor for Mat. That way, if you're just making one Mat (as opposed to an array of them), you don't need to think much about the allocation.
Keep in mind you can always look at the source for the Mat constructor or any other portions of OpenCV if you ever want to get all the nitty gritty details.
精彩评论