imread problem

asked 2016-11-09 01:41:56 -0600

Bob H gravatar image

Having problem with imread. So I tried the code from the tutorial. Still didn't work. (Image was empty) Changed the libraries to the debug version. Now the tutorial version worked. Using VisualStudio 2012. Tried to embed the same code in an MFC application. Seems to work with the debug libraries. But when I close the program, I get a huge number of memory leaks. Commented out the imread, and the number of memory leaks decreased substantially. Commented out the Mat declaration for the image, and all the memory leaks go away. Just having the Mat declared gives me memory leaks. Using it causes even more memory leaks. There must be some way to destruct the Mat image at program termination to not have any memory leaks. Anybody have any ideas?

edit retag flag offensive close merge delete

Comments

1

can you try without mfc first ? (avoid that, like the menace it is)

berak gravatar imageberak ( 2016-11-09 02:05:50 -0600 )edit

I first tried the tutorial with a console application. With the debug libraries it worked. Same code embedded in an MFC application resulted in numerous memory leaks. Don't know what you have against MFC. I have programmed with it for many years quite successfully. I have developed a number of successful Image and video processing codes that way using Intel's IPP. When I started with video processing, OpenCV didn't have much functionality. But I thought I'd give it another try. However, even things that should be easy, seem to be not so easy.

Bob H gravatar imageBob H ( 2016-11-09 11:39:04 -0600 )edit

Just to add a little more. I went back and used the C Version (cvLoadImage with IplImage). It loaded the image, but had the same memory leaks with the debug libraries. Changed back to the release libraries, and it still loads the image just fine but doesn't have the memory leaks. Also tried cvLoadImageM with CvMat. Same result as the cvLoadImage. Things now work. So imread and the debug libraries seem to be the problems.

Bob H gravatar imageBob H ( 2016-11-09 12:15:30 -0600 )edit

^^more and more it turns out to be a problem, how you link opencv libs ( or use the std::c++ libs in your project)

(please check again: are you accidentally linking debug libs to a release build (or the other way?)

any chance, you build against the wronng c-runtime ?)

berak gravatar imageberak ( 2016-11-09 12:23:14 -0600 )edit

I am doing a debug build. Linking the debug OpenCV libraries with the debug build results in the memory leaks. Linking the release OpenCV libraries with the debug build does not result in memory leaks. But then the imread function does not return an image that way, and cvLoadImage does return an image and no memory leaks.

Bob H gravatar imageBob H ( 2016-11-09 12:45:12 -0600 )edit

I have a blog about this http://www.cnblogs.com/jsxyhelu/p/GOMFCTemplate2.html but it is in chinese,may use google to read it.

jsxyhelu gravatar imagejsxyhelu ( 2017-02-20 09:45:12 -0600 )edit