Skip to content

Instantly share code, notes, and snippets.

@veev
Created February 2, 2012 07:30
Show Gist options
  • Save veev/1722182 to your computer and use it in GitHub Desktop.
Save veev/1722182 to your computer and use it in GitHub Desktop.
//make sure that OpenCV can find a face
if (finder.blobs.size() > 0) {
//then make a new image that is the width and height of the face bounding box
imageFace.allocate(finder.blobs[0].boundingRect.x, finder.blobs[0].boundingRect.y, OF_IMAGE_COLOR_ALPHA);
//unsigned char * origPixels = image.getPixels();
//make a new data type for the new image's pixels
unsigned char * copyPixels = imageFace.getPixels();
//declare an index to keep track of the new image's pixels that are within the bounding box
int imageFaceIndex = 0;
//loop through the first image's cols and rows
for(int row = 0; row < image.getHeight(); row++) {
for(int col = 0; col < image.getWidth(); col++) {
//keep track of index
int offset = row * image.getWidth() + col;
//check to see if "pixel" is within bounds of face detected Rect
if (row > finder.blobs[0].boundingRect.x &&
row < (finder.blobs[0].boundingRect.x + finder.blobs[0].boundingRect.width) &&
col < finder.blobs[0].boundingRect.y &&
col > (finder.blobs[0].boundingRect.y + finder.blobs[0].boundingRect.height)) {
//if so, then copy the RGBA pixels from the original data to new image pixels
data[offset*4] = copyPixels[imageFaceIndex*4];
data[offset*4 + 1] = copyPixels[imageFaceIndex*4 + 1];
data[offset*4 + 2] = copyPixels[imageFaceIndex*4 + 2];
data[offset*4 + 3] = copyPixels[imageFaceIndex*4 + 3];
//increment to the next pixel that satisfies the bounding box
imageFaceIndex++;
}
}
}
}
}
}
//cout << imageBelowWindow()[0] << endl;
imageFace.update();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment