I have experienced some memory managment ambiguitys with opencv. You could do this with the new opencv c++ classes:
cv::Mat theimage = cvLoadImage("rawimage.pgm",CV_LOAD_IMAGE_ANYDEPTH);
now what I don t understand if I do the following I will get an error:
theimage.deallocate();
maybe this is wrong. I have made some experiments and when I release the Mat object:
theimage.release();
the IplImage object still remains in the memory. Is there some way to say to the cv::Mat object destroy the IplImage object or is my first line of code wrong (since there I have lost the pointer for the IplImage object) ? I have seen a lot of exemples in the internet where people use the first line of code. Many explains how to convert but no one explains what happens with the memory !
Tthe problem is that I have many classes that are using the IplImage object (I started my project using that). And I understand why cv::Mat is better than IplImage.
--EDIT--
In the internet I have found following solution for the mixing:
cv::Ptr<IplImage> tmp = cvLoadImage("rawimage.pgm",CV_LOAD_IMAGE_ANYDEPTH);
cv::Mat theimage(tmp);
I think this could solve some of my problems but makes my code a bit unreadable and is in my opinion stil dangerous. If tmp gets deallocated before cv::Mat I will use some corrupt objects (I didn t test that but I think it is so). The easy way would be to use a copy:
cv::Mat theimage(tmp,true);
this is the only solution that I found but for me it feels wrong...