How to get the pixels inside of a blob or screen area?

Hi of people,

Im working in a kinect project base on poppets technique animation and i need to save the pixels inside a blob to a .png image, any ideas?

thanks in advance

have a nice day :slight_smile:

Monk

you’ll probably want to mask the whole camera image with the blob; i’d probably do it with glBlendFunc().

Any pointers to a good glBlendFunc example? When I do something like this I am probably doing it the hard/slow way

  
  
  
for (int i = 0; i<contourFinder->blobs.size(); i++)   
{  
	ofxCvBlob blob = contourFinder->blobs[i];  
	cvColorImage.setROI(blob.boundingRect);  
	cvGrayImageFromColorImage.setROI(blob.boundingRect);  
	int w = blob.boundingRect.width;  
	int h = blob.boundingRect.height;  
	unsigned char * pixels = new unsigned char[w*h*4];  
	unsigned char * colorPixels = cvColorImage.getPixels();  
	unsigned char * alphaPixels = cvGrayImageFromColorImage.getRoiPixels();  
	for (int c = 0; c < w; c++){  
		for (int r = 0; r < h; r++)  
		{  
			int pos = (r * w + c);  
			pixels[pos*4] = colorPixels[pos * 3];  
			pixels[pos*4+1] = colorPixels[pos * 3+1];  
			pixels[pos*4+2] = colorPixels[pos * 3+2];  
			pixels[pos*4+3] = alphaPixels[pos];  
		}  
	}  
	  
	  
	ofImage carImage;  
	carImage.setFromPixels(pixels, w, h, OF_IMAGE_COLOR_ALPHA);  
//you could probably carImage.saveImage("image.png"); here  
	cvColorImage.resetROI();  
	cvGrayImageFromColorImage.resetROI();  
	  
	delete [] pixels;  
	  
	colorPixels = NULL;  
	delete colorPixels;  
	  
	alphaPixels = NULL;  
	delete alphaPixels;  
}  
  

Hi jvcleave,

I will try and will return will my results

:slight_smile:

Thanks a lot,

monk