background subtraction for face tracking (haarfinder)?

Is it possible to do background subtraction for face tracking using ofxOpenCV and a haarfinder? The example code uses background subtraction for the contour finder, but feeding that difference image into haarfinder doesn’t work so well. I tried creating a color difference image only to find that absDiff() isn’t supported for color images.

Am I missing something? Seems like this would be a common need. Of course maybe it’s just really hard :slight_smile:


To do background subtraction, just capture the pixels from the camera into a grayscale ofPixels at the beginning of your run and then do absDiff() with the incoming frame pixels (in grayscale) and then run the faceDetection on the result of absDiff(). You can do ofxCvHaarFinder::findHaarObjects() on a grayscale image (actually any image passed in is converted to a grayscale), so the resulting grayscale image can be passed to that either as an ofxCvGrayscaleImage or as ofPixels.

Are you doing this in hopes of speeding up the face detection? From what I have tried, isolating the user from the background and feeding it to the HaarFinder didn’t seem to help much.