Ask Your Question
0

are there memory leaks in Java detectMultiScale()?

asked 2016-12-04 21:06:01 -0600

mcwu0628 gravatar image

I'm trying to write a android app with face detection and I found memory leaks exist after calling detectMultiScale() can anyone tell me how to fix this problem?

I have searched solution related to the issue like calling System.gc() after detectMultiScale(). but it didn't work.

edit retag flag offensive close merge delete

Comments

can you show your code ?

it's unlikely, that there's a leak in detectMultiScale(), but it happens often, that folks forget to release() temporary, local Mat's.

berak gravatar imageberak ( 2016-12-05 03:15:31 -0600 )edit

Hey I have already knew how to avoid the memory leak. in my case, I call detectMultiScale() a lot times so that occurs failed to allocate memory

here is my code:

patternCascadeClassifier.detectMultiScale(grayImage, patternRects, 1.06, 1,
        Objdetect.CASCADE_SCALE_IMAGE|Objdetect.CASCADE_DO_CANNY_PRUNING,
        new Size(10, 10), new Size(50, 50));

// in my opinion, its necessary to reload cascade xml to release the related resources
patternCascadeClassifier.load(file.getAbsolutePath());
mcwu0628 gravatar imagemcwu0628 ( 2016-12-06 03:58:34 -0600 )edit

Could provide more info like snippets of code or screenshots of performance monitoring?

kevto gravatar imagekevto ( 2016-12-21 02:26:01 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
-1

answered 2017-02-02 06:46:54 -0600

plamen gravatar image

Hello! I am using openCV with .Net C# wrapper. On Windows 10 when I load the cascade xml I use it multiple times in a loop and after that I dispose() the object, which releases its resources. But when i load and dispose multiple times at different stages of my application, I have noticed that it doesn't releases all the memory. Execute this peace of code multiple times and you will start seeing memory increase. The odd thing is that when I run the same code on Linux machine under the mono environment the memory stays the fairly the same. I am 101% sure that i dispose all the images which are used in the process. My code looks something like this:

CascadeClassifier cascadeClassifier = new CascadeClassifier(resourceManager.FRONTAL_FACE_ALT_PATH);  
Rectangle localR = new Rectangle();
while (isWindowOpen && !faceFound)
   {
       Mat localImage;                    

       localImage = new Mat(workingImage, new Rectangle(new Point(0, 0), workingImage.Size));
       CvInvoke.CvtColor(localImage, localImage, ColorConversion.Bgr2Gray);
       workingImage.Dispose();
       CvInvoke.EqualizeHist(localImage, localImage);
       Rectangle[] faces = cascadeClassifier.DetectMultiScale(localImage, 1.1, 10, Size.Empty);                
       localImage.Dispose();                    

       Thread.Sleep(20);
   }
cascadeClassifier.Dispose();
edit flag offensive delete link more

Comments

sorry, but:

  • this does not answer the question..
  • there is NO support for ANY c# wrappers from opencv AT ALL
berak gravatar imageberak ( 2017-02-02 06:51:32 -0600 )edit

I didn't want to post this as answer. I just wanted to share with you that I have the same memory leak as mcwu0628. My C# code just calls functions from C++ openCV code and I dispose everything that I can and i still have memory leak. My guess is that there is something wrong inside openCV cascadeClassifier.detectMultiscale() function when it is called multiple times under Windows. The reason I post a comment is so that someone can take a look at it and see if there is something wrong.

plamen gravatar imageplamen ( 2017-02-09 05:01:39 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-12-04 21:06:01 -0600

Seen: 460 times

Last updated: Dec 04 '16