Public Member Functions | Protected Member Functions

OpenCVHaarDetector Class Reference
[Auxilliary Tools]

Auxilliary Tool: A specific object detector that uses OpenCV's Haar Cascade Classifier to detect objects. The performance / behavior of the object detector is stored in an XML file, which is passed in in the constructor. The XML file provided in the data directory may be used for finding faces, or you can use OpenCV to train your own. More...

#include <OpenCVHaarDetector.h>

Inheritance diagram for OpenCVHaarDetector:
Inheritance graph
[legend]
Collaboration diagram for OpenCVHaarDetector:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 OpenCVHaarDetector ()
 Placeholder Constructor.
 OpenCVHaarDetector (const char *filename)
 Constructor.
 OpenCVHaarDetector (OpenCVHaarDetector *detectorToCopy)
 Deep Copy Constructor: Create a Haar detector that is identical to the one copied.
 ~OpenCVHaarDetector ()
 Default Destructor.
std::vector< cv::Rect > detectObjects (IplImage *image)
 Virtual Method for overridden from parent class (ObjectDetector). Applies the cvHaarDetectObjects() method to the provided image patch.
void setHaarCascadeScaleFactor (double factor)
 Sets the factor by which the image-patch-search-scale is increased. Should be greater than 1. By default, the scale factor is 1.1, meaning that faces are searched for at sizes that increase by 10%.
void setHaarCascadeMinSize (int size)
 Sets the minimum patch size at which the classifier searches for the object. By default, this is 0, meaning that the smallest size appropriate to XML file is used. In the case of the frontal face detector provided, this happens to be 20x20 pixels.
void setDetectorSource (std::string newFileName)
 Change the file used by the object detector for doing detecting. This is critical if a weights file is located at an absolute path that may have changed from training time.

Protected Member Functions

void readFromStream (std::istream &in)
 Virtual Method for inheriting classes to override: An object detector should be able to read in its properties from a file, and reinitialize itself appropriately.
void addToStream (std::ostream &out)
 Virtual Method for inheriting classes to override: An object detector should be able to serialize itself to be saved in a file.

Detailed Description

Auxilliary Tool: A specific object detector that uses OpenCV's Haar Cascade Classifier to detect objects. The performance / behavior of the object detector is stored in an XML file, which is passed in in the constructor. The XML file provided in the data directory may be used for finding faces, or you can use OpenCV to train your own.

Author:
Nicholas Butko
Date:
2010
Version:
0.4

Constructor & Destructor Documentation

OpenCVHaarDetector::OpenCVHaarDetector (  )

Placeholder Constructor.

Used to create a placeholder for an object detector, which can then be read from a file stream using the >> operator. Typical usage for this constructor is:

detector = new OpenCVHaarDetector();
in >> detector;

OpenCVHaarDetector::OpenCVHaarDetector ( const char *  filename )

Constructor.

Used to create an object detector out of a previously stored XML file.

Parameters:
filenameThe name of the XML file that contains all of the features / weights / etc. needed by the Haar Cascaded Object Detector. The provided file, "data/haarcascade_frontalface_alt2.xml" is distributed with OpenCV. OpenCV can be used to train detectors of objects other than frontal faces.
OpenCVHaarDetector::~OpenCVHaarDetector (  )

Default Destructor.

Deallocates all memory associated with the haar detector.


Member Function Documentation

vector< Rect > OpenCVHaarDetector::detectObjects ( IplImage *  image ) [virtual]

Virtual Method for overridden from parent class (ObjectDetector). Applies the cvHaarDetectObjects() method to the provided image patch.

Parameters:
imageThe image to be searched for some target object.
Returns:
A CvSeq* array of CvRect, each specifying the location of the object detector's target. Each CvRect should specify the top-left pixel corner of an object's bounding box, and also the height and width of the bounding box. The Object's location is taken to be the center of this bounding box.

Implements ObjectDetector.

void OpenCVHaarDetector::setDetectorSource ( std::string  newFileName ) [virtual]

Change the file used by the object detector for doing detecting. This is critical if a weights file is located at an absolute path that may have changed from training time.

When an ObjectDetector is loaded from disk, it will try to reload its weights file from the same source used in training. If this fails, a warning will be printed, and the detector's source will need to be set.

Implements ObjectDetector.

void OpenCVHaarDetector::setHaarCascadeMinSize ( int  size )

Sets the minimum patch size at which the classifier searches for the object. By default, this is 0, meaning that the smallest size appropriate to XML file is used. In the case of the frontal face detector provided, this happens to be 20x20 pixels.

Parameters:
sizeThe width/height of the smallest patches to try to detect the object.
void OpenCVHaarDetector::setHaarCascadeScaleFactor ( double  factor )

Sets the factor by which the image-patch-search-scale is increased. Should be greater than 1. By default, the scale factor is 1.1, meaning that faces are searched for at sizes that increase by 10%.

Parameters:
factorThe size-granularity of object search.

The documentation for this class was generated from the following files: