Ask Your Question

Speed of Face dectection

asked 2012-07-09 06:36:57 -0500

dommy gravatar image

updated 2017-09-10 16:42:52 -0500

Hi, i am a c# developer (Sorry) and using EMGU's wrapper around OpenCV for face detection - it gets good results. But, each time I call the detect method the RAM goes up quite a lot (especially if I am monitoring 4 cameras at the same time). I was wondering my approach to minimize the RAM. I have thought of putting the face detection routine in a service (though I doubt this would reduce the RAM usage) and/or accessing the Face Detection routine via a C++ DLL. This C++ DLL will have face_detect.cpp (that comes with OpenCV) but configured as a DLL and not as a Win App. I am struggling to do this. I can make a call to the DLL from c# (and I have tested returning vector<int> OK). But as soon as I add the OpenCV stuff it errors on the c# side. Obviously, my knowledge of linking of libraries is not good enough (I think i need to use static libraries?). BUT, before I continue I wanted to know if there is any merit in following this in regards to RAM deduction.

Any suggestions please?



edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2012-07-10 01:29:01 -0500

Kirill Kornyakov gravatar image

Most likely that switch to C++ version will not help. I don't have experience with EMGU, but most likely that they use thin wrappers for OpenCV, that means that C# classes keep everything on the native level and memory footprint of classes doesn't differ significantly. But I may be wrong about their particular implementation...

So, you should investigate why your app is consuming so much memory. I can suggest you the following:

  1. Check how memory consumption changes if you disable Face Detectors one by one, but stay with multiple cameras and other pipeline. May be detectors itself doesn't consume RAM, may be your problem in other parts of application.
  2. Check that you don't do memory (image, matrix) allocations on every iteration. You should preallocate all required buffers and reuse them between iterations. You can also analyze the behaviour of the garbage collector, may be your implementation forces it to continuously delete reallocated memory.
  3. Do not keep copies of color images. Convert them to the grayscale from the very beginning and do all the processing in this format.
  4. You can also try to use smaller resolution as icedecker suggests, but control the quality.
  5. And you can try to use LBP cascade instead of Haar. May be its memory footprint will be smaller.
edit flag offensive delete link more

answered 2012-07-09 16:41:53 -0500

icedecker gravatar image

You can try to downsize the frame to, for example, 320x240 pixels. Face detection doesn't need to use high resolution.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools


Asked: 2012-07-09 06:36:57 -0500

Seen: 591 times

Last updated: Jul 10 '12