Click or drag to resize
Accord.NET (logo)

HaarObjectDetector Class

Viola-Jones Object Detector based on Haar-like features.
Inheritance Hierarchy
SystemObject
  Accord.Vision.DetectionHaarObjectDetector

Namespace:  Accord.Vision.Detection
Assembly:  Accord.Vision (in Accord.Vision.dll) Version: 3.7.0
Syntax
public class HaarObjectDetector : IObjectDetector
Request Example View Source

The HaarObjectDetector type exposes the following members.

Constructors
  NameDescription
Public methodHaarObjectDetector(HaarCascade)
Constructs a new Haar object detector.
Public methodHaarObjectDetector(HaarCascade, Int32)
Constructs a new Haar object detector.
Public methodHaarObjectDetector(HaarCascade, Int32, ObjectDetectorSearchMode)
Constructs a new Haar object detector.
Public methodHaarObjectDetector(HaarCascade, Int32, ObjectDetectorSearchMode, Single)
Constructs a new Haar object detector.
Public methodHaarObjectDetector(HaarCascade, Int32, ObjectDetectorSearchMode, Single, ObjectDetectorScalingMode)
Constructs a new Haar object detector.
Top
Properties
  NameDescription
Public propertyChannel
Gets or sets the color channel to use when processing color images.
Public propertyClassifier
Gets the internal Cascade Classifier used by this detector.
Public propertyDetectedObjects
Gets the detected objects bounding boxes.
Public propertyMaxSize
Maximum window size to consider when searching objects.
Public propertyMinSize
Minimum window size to consider when searching objects.
Public propertyScalingFactor
Gets or sets the scaling factor to rescale the window during search.
Public propertyScalingMode
Gets or sets the desired scaling method.
Public propertySearchMode
Gets or sets the desired searching method.
Public propertySteady
Gets how many frames the object has been detected in a steady position.
Public propertySuppression
Gets or sets the minimum threshold used to suppress rectangles which have not been detected sufficient number of times. This property only has effect when SearchMode is set to Average.
Public propertyUseParallelProcessing
Gets or sets a value indicating whether this HaarObjectDetector should scan the image using multiple threads. This setting can only be changed to true on .NET version which support the Parallel Tasks framework (4.0+).
Top
Methods
  NameDescription
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodProcessFrame(Bitmap)
Performs object detection on the given frame.
Public methodProcessFrame(UnmanagedImage)
Performs object detection on the given frame.
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Extension Methods
  NameDescription
Public Extension MethodHasMethod
Checks whether an object implements a method with the given name.
(Defined by ExtensionMethods.)
Public Extension MethodIsEqual
Compares two objects for equality, performing an elementwise comparison if the elements are vectors or matrices.
(Defined by Matrix.)
Public Extension MethodToT
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)
Top
Remarks

The Viola-Jones object detection framework is the first object detection framework to provide competitive object detection rates in real-time proposed in 2001 by Paul Viola and Michael Jones. Although it can be trained to detect a variety of object classes, it was motivated primarily by the problem of face detection.

The implementation of this code has used Viola and Jones' original publication, the OpenCV Library and the Marilena Project as reference. OpenCV is released under a BSD license, it is free for both academic and commercial use. Please be aware that some particular versions of the Haar object detection framework are patented by Viola and Jones and may be subject to restrictions for use in commercial applications. The code has been implemented with full support for tilted Haar features from the ground up.

References:

Examples
// In order to use a HaarObjectDetector, first we have to tell it
// which type of objects we would like to detect. And in a Haar detector,
// different object classifiers are specified in terms of a HaarCascade.

// The framework comes with some built-in cascades for common body
// parts, such as Face and Nose. However, it is also possible to
// load a cascade from cascade XML definitions in OpenCV 2.0 format.

// In this example, we will be creating a cascade for a Face detector:
var cascade = new Accord.Vision.Detection.Cascades.FaceHaarCascade();

// Note: In the case we would like to load it from XML, we could use:
// var cascade = HaarCascade.FromXml("filename.xml");

// Now, create a new Haar object detector with the cascade:
var detector = new HaarObjectDetector(cascade, minSize: 50, 
    searchMode: ObjectDetectorSearchMode.NoOverlap);

// Note that we have specified that we do not want overlapping objects,
// and that the minimum object an object can have is 50 pixels. Now, we
// can use the detector to classify a new image. For instance, consider
// the famous Lena picture:

Bitmap bmp = Accord.Imaging.Image.Clone(Resources.lena_color);

// We have to call ProcessFrame to detect all rectangles containing the 
// object we are interested in (which in this case, is the face of Lena):
Rectangle[] rectangles = detector.ProcessFrame(bmp);

// The answer will be a single rectangle of dimensions
// 
//   {X = 126 Y = 112 Width = 59 Height = 59}
// 
// which indeed contains the only face in the picture.
See Also