ofxCvHaarFinder

ofxCvHaarFinder allows you to check an image for a match to a Haar classifier. The Haar Classifier is a data file generated from a training process where an application is "taught" how to recognize something in different contexts. This can be things like recognizing whether a certain sound is a word being spoken by a user, whether a gesture is a certain shape, or, in the image shown below, whether a pattern of pixels constitute a face.

face detection

A very basic set-up of an application using ofxCvHaarFinder would look like so:

app::setup() {
   haarFinder.setup("haarcascade.xml"); // must be in /data/
}

app::update() {
   haarFinder.findHaarObjects(imageToExamine);
}

app::draw() {
  for(int i = 0; i < haarFinder.blobs.size(); i++) {
     ofRect( haarFinder.blobs[i].boundingRect );
  }
}

ofxCvHaarFinder methods

ofxCvHaarFinder()

ofxCvHaarFinder::ofxCvHaarFinder()

Constructor.

ofxCvHaarFinder(...)

ofxCvHaarFinder::ofxCvHaarFinder(const ofxCvHaarFinder &finder)

Copy constructor.

~ofxCvHaarFinder()

ofxCvHaarFinder::~ofxCvHaarFinder()

Destructor.

setup(...)

void ofxCvHaarFinder::setup(string haarFile)

This loads a Haar cascade file into the finder. This needs to be done before the Haar finder can be used with images.

setScaleHaar(...)

void ofxCvHaarFinder::setScaleHaar(float scaleHaar)

setNeighbors(...)

void ofxCvHaarFinder::setNeighbors(unsigned neighbors)

Minimum number (minus 1) of neighbor rectangles that makes up an object. All the groups of a smaller number of rectangles than min_neighbors-1 are rejected. If min_neighbors is 0, the function does not any grouping at all and returns all the detected candidate rectangles, that might be useful if you want to do a customized grouping.

findHaarObjects(...)

int ofxCvHaarFinder::findHaarObjects(ofImage &input, int minWidth=0, int minHeight=0)

Takes an input ofImage object and allows you to set the minimum width and height of areas that should be returned.

camera.grabFrame();
if(camera.isFrameNew())
{
    img.setFromPixels(grab.getPixelsRef());
    finder.findHaarObjects(img);
}

findHaarObjects(...)

int ofxCvHaarFinder::findHaarObjects(const ofxCvGrayscaleImage &input, int minWidth=0, int minHeight=0)

Takes an input ofxCvGrayscaleImage object and allows you to set the minimum width and height of areas that should be returned.

findHaarObjects(...)

int ofxCvHaarFinder::findHaarObjects(const ofxCvGrayscaleImage &input, ofRectangle &roi, int minWidth=0, int minHeight=0)

Takes an input ofxCvGrayscaleImage object and allows you to set the minimum width and height of areas that should be returned and a region of interest as an ofRectangle that you would like to limit haar finding to.

colorImg.setFromPixels(vidGrabber.getPixelsRef());
grayImage = colorImg; // convert our color image to a grayscale image

faceFinder.findHaarObjects(grayImage);

for(int i = 0; i < faceFinder.blobs.size(); i++) {
    ofRectangle roi = faceFinder.blobs[i].boundingRect;
    eyeFinder.findHaarObjects(grayImage, roi);
}

findHaarObjects(...)

int ofxCvHaarFinder::findHaarObjects(const ofxCvGrayscaleImage &, int x, int y, int w, int h, int minWidth=0, int minHeight=0)

Takes an input ofxCvGrayscaleImage object and allows you to set the minimum width and height of areas that should be returned and a region of interest as an ofRectangle that you would like to limit haar finding to.

findHaarObjects(...)

int ofxCvHaarFinder::findHaarObjects(ofPixels &input, int minWidth=0, int minHeight=0)

Takes an input ofPixels object and allows you to set the minimum width and height of areas that should be returned.

getWidth()

float ofxCvHaarFinder::getWidth()

Returns the width of the image area that is being examined.

getHeight()

float ofxCvHaarFinder::getHeight()

Returns the height of the image area that is being examined.

draw(...)

void ofxCvHaarFinder::draw(float x, float y)

Draws any detected objects to the screen with a rectangle, like so:

Draw faces

ofxCvHaarFinder variables

ofxCvBlob blobs

ofxCvBlob ofxCvHaarFinder::blobs

Provides access to the all the blobs detected in the last run of findHaarObjects() via a vector.