Hi all, I'm trying to look through a series of still images for face detection using the OpenCV library. It's working great and (I believe) I'm correctly passing the pixel array of my PImage, as suggested by the documentation to avoid memory issues on the Mac (
http://ubaa.net/shared/processing/opencv/opencv_loadimage.html)
The relevant code:
- void setup() {
- oc = new OpenCV(this);
- // allocate memory for image's pixels
- oc.allocate(tempImage.width, tempImage.height);
- }
- void draw() {
- PImage tempImage = loadImage("ImageWithFace.jpg");
- oc.copy(tempImage.pixels, tempImage.width, 0,0, tempImage.width, tempImage.height, 0,0, tempImage.width, tempImage.height);
- oc.cascade(OpenCV.CASCADE_FRONTALFACE_ALT2);
- Rectangle[] faces = oc.detect(1.2, 2, OpenCV.HAAR_DO_CANNY_PRUNING, 60,60);
- image(oc.image(), 0,0);
- // this is followed by drawing the rectangles, etc
- // then load the next image, repeat the process
- }
This works and I get a match. However, after running the draw() for a few minutes I get a memory error and the sketch quits:
- java(766,0xb3733000) malloc: *** mmap(size=266240) failed (error code=12)
- *** error: can't allocate region
- *** set a breakpoint in malloc_error_break to debug
- OpenCV ERROR: Insufficient memory (Out of memory)
Is there a call to clear the allocated memory before putting in the next image? I would have thought loading a new pixel array would overwrite the existing data, but perhaps not. Am I missing something obvious? Other suggestions?
2