SIGABRT error using openCV

Hi all,

I am using openFrameworks to simulate the effect of a silhouette on a wall but with a 3-4 second delay. I’m using the openCV addon to create a grayscale image of the person in front of the camera. This almost exactly replicates the openCV example:

  
	  
colourImg.setFromPixels(vidGrabber.getPixels(), _width, _height);  
grayScaleImg = colourImg;		  
grayScaleImg.absDiff(blankImg, grayScaleImg);  
grayScaleImg.threshold(threshold);    
  

I am then using the grayscale pixels values of this and the colour values of an image of a wall within an RGBA ofTexture. It all seems to run fine for about ten minutes at which point I get the following error:

penumbraDebug(628,0xa0782500) malloc: *** mmap(size=307200) failed (error code=12)
*** error: can’t allocate region
*** set a breakpoint in malloc_error_break to debug
terminate called after throwing an instance of ‘std::bad_alloc’
what(): std::bad_alloc
Program received signal: “SIGABRT”.
sharedlibrary apply-load-rules all
warning: Could not find object file “/Users/theo/Documents/CODE/__OPENFRAMEWORKS/SANDBOX/COMPILE_LIBRARIES/buildGlutFramework/libForeground.a(macx_foreground.o)” - no debug information available for “/Users/mcast/Code/GLUT-ToPost/macx_foreground.m”.

warning: Could not find object file “/Developer/usr/lib/gcc/i686-apple-darwin9/4.0.1/libgcc.a(_eprintf.o)” - no debug information available for “/var/tmp/gcc/gcc-5493~1/src/gcc/libgcc2.c”.

Not quite sure what is going wrong here. The full code is included below.

Thanks in advance,

Gareth

  
  
//--------------------------------------------------------------  
void testApp::setup(){  
	  
	  
	ofBackground(0, 0, 0);  
	_width					= 640;  
	_height					= 480;  
	  
	maxFramesInBuffer		= 50;  
	currentBufferFrame		= 0;  
	threshold				= 80;  
  
	pixelBuffer = new unsigned char * [maxFramesInBuffer];   
	firstFull = false;  
	  
	vidGrabber.initGrabber(_width,_height);  
	  
	mergedPixels.allocate(_width, _height, GL_RGBA); //texture  
	colourImg.allocate(_width, _height);		//ofxCvColorImage  
	grayScaleImg.allocate(_width, _height);	//ofxCvGrayscaleImage  
	blankImg.allocate(_width, _height);		//ofxCvGrayscaleImage - For diff  
	  
	//@TODO replace with image of wall from camera.  
	cam_mask.loadImage("whitewall_640x480.jpg");  
	colourPixels = cam_mask.getPixels();   
	  
	//Fill with blank pixels  
	unsigned char * blankImgPixels = new unsigned char[_width*_height];  
	for (int i = 0; i < _height; i++)   
		for (int j = 0; j < _width; j++)   
			blankImgPixels[i*j] = 0;  
	  
	blankImg.setFromPixels(blankImgPixels, _width, _height); //get blank image during setup	  
}  
  
//--------------------------------------------------------------  
void testApp::update(){  
	  
	  
	vidGrabber.grabFrame();  
	  
	if (vidGrabber.isFrameNew())  
	{		  
		unsigned char * grayVidPixels = new unsigned char[_width*_height];  
		  
		colourImg.setFromPixels(vidGrabber.getPixels(), _width, _height);  
		grayScaleImg = colourImg;		  
		grayScaleImg.absDiff(blankImg, grayScaleImg);  
		grayScaleImg.threshold(threshold);  
		grayVidPixels = grayScaleImg.getPixels();	  
		  
		pixelBuffer[currentBufferFrame] = new unsigned char[_width*_height*4];    
		  
		for (int i = 0; i < _width; i++){   
			for (int j = 0; j < _height; j++){   
				int pos = (j * _width + i); 				  
				pixelBuffer[currentBufferFrame][(pos*4)] = colourPixels[pos * 3];   
				pixelBuffer[currentBufferFrame][(pos*4+1)] = colourPixels[pos * 3+1];   
				pixelBuffer[currentBufferFrame][(pos*4+2)] = colourPixels[pos * 3+2];				  
				pixelBuffer[currentBufferFrame][(pos*4+3)] = (grayVidPixels[pos] == 0) ? 90 : grayVidPixels[pos];   
			}   
		}   
		  
		if(currentBufferFrame == maxFramesInBuffer)  
			firstFull = true;  
		  
		//pausing whilst frame buffers.   
		if(firstFull == true)  
		{  
			int playFrame;  
			playFrame = (currentBufferFrame == maxFramesInBuffer) ? 0 : currentBufferFrame+1;  
			mergedPixels.loadData(pixelBuffer[playFrame], _width, _height, GL_RGBA);	  
			delete [] pixelBuffer[(currentBufferFrame == maxFramesInBuffer) ? 0 : currentBufferFrame+1];  
		}		  
		  
		  
		if(currentBufferFrame >= maxFramesInBuffer)  
			currentBufferFrame = 0;  
		else  
			currentBufferFrame++;  
	}	  
}  
  
//--------------------------------------------------------------  
void testApp::draw(){  
	ofEnableAlphaBlending();  
	mergedPixels.draw(0,0,_width, _height);  
	ofDisableAlphaBlending();  
}