Documentation Center

  • Trial Software
  • Product Updates

vision.CascadeObjectDetector System object

Package: vision

Detect objects using the Viola-Jones algorithm

Description

The cascade object detector uses the Viola-Jones algorithm to detect people's faces, noses, eyes, mouth, or upper body. You can also use the trainCascadeObjectDetector function to train a custom classifier to use with this System object. For details on how the function works, see Train a Cascade Object Detector.

Construction

detector = vision.CascadeObjectDetector creates a System object, detector, that detects objects using the Viola-Jones algorithm. The ClassificationModel property controls the type of object to detect. By default, the detector is configured to detect faces.

detector = vision.CascadeObjectDetector(MODEL) creates a System object, detector, configured to detect objects defined by the input string, MODEL. The MODEL input describes the type of object to detect. There are several valid MODEL strings, such as 'FrontalFaceCART', 'UpperBody', and 'ProfileFace'. See the ClassificationModel property description for a full list of available models.

detector = vision.CascadeObjectDetector(XMLFILE) creates a System object, detector, and configures it to use the custom classification model specified with the XMLFILE input. The XMLFILE can be created using the trainCascadeObjectDetector function or OpenCV (Open Source Computer Vision) training functionality. You must specify a full or relative path to the XMLFILE, if it is not on the MATLAB® path.

detector = vision.CascadeObjectDetector(Name,Value) configures the cascade object detector object properties. You specify these properties as one or more name-value pair arguments. Unspecified properties have default values.

Code Generation Support
Supports MATLAB Function block: No
Generated code for this function uses a precompiled platform-specific shared library.
Code Generation Support, Usage Notes, and Limitations

To detect a feature:

  1. Define and set up your cascade object detector using the constructor.

  2. Call the step method with the input image, I, the cascade object detector object, detector, points PTS, and any optional properties. See the syntax below for using the step method.

Use the step syntax with input image, I, the selected Cascade object detector object, and any optional properties to perform detection.

BBOX = step(detector,I) returns BBOX, an M-by-4 matrix defining M bounding boxes containing the detected objects. This method performs multiscale object detection on the input image, I. Each row of the output matrix, BBOX, contains a four-element vector, [x y width height], that specifies in pixels, the upper-left corner and size of a bounding box. The input image I, must be a grayscale or truecolor (RGB) image.

Properties

ClassificationModel

Trained cascade classification model

Specify the name of the model as a string. This value sets the classification model for the detector. You may set this string to an XML file containing a custom classification model, or to one of the valid model strings listed below. You can train a custom classification model using the trainCascadeObjectDetector function. The function can train the model using Haar-like features, histograms of oriented gradients (HOG), or local binary patterns (LBP). For details on how to use the function, see Train a Cascade Object Detector.

 Frontal Face (CART)

 Frontal Face (LBP)

 Upper Body

 Eye Pair

 Single Eye

 Single Eye (CART)

 Profile Face

 Mouth

 Nose

Default: FrontalFaceCART

MinSize

Size of smallest detectable object

Specify the size of the smallest object to detect. This value must be given in pixels, as a two-element vector, [height width]. It must be greater than or equal to the image size used to train the model. Use this property to reduce computation time when you know the minimum object size prior to processing the image. When you do not specify a value for this property, the detector sets it to the size of the image used to train the classification model. This property is tunable.

For details explaining the relationship between setting the size of the detectable object and the ScaleFactor property, see Algorithms section.

Default: []

MaxSize

Size of largest detectable object

Specify the size of the largest object to detect. This value must be given in pixels, as a two-element vector, [height width]. Use this property to reduce computation time when you know the maximum object size prior to processing the image. When you do not specify a value for this property, the detector sets it to size(I). This property is tunable.

For details explaining the relationship between setting the size of the detectable object and the ScaleFactor property, see the Algorithms section.

Default: []

ScaleFactor

Scaling for multiscale object detection

Specify a factor, with a value greater than 1.0001, to incrementally scale the search region. You can set the scale factor to an ideal value using:

size(I)/(size(I)-0.5)

The detector scales the search region at increments between MinSize and MaxSize using the following relationship:

search region = round((Training Size)*(ScaleFactorN))

N is the current increment, an integer greater than zero, and Training Size is the image size used to train the classification model. This property is tunable.

Default: 1.1

MergeThreshold

Detection threshold

Specify a threshold value as a scalar integer. This value defines the criteria needed to declare a final detection in an area where there are multiple detections around an object. Groups of colocated detections that meet the threshold are merged to produce one bounding box around the target object. Increasing this threshold may help suppress false detections by requiring that the target object be detected multiple times during the multiscale detection phase. When you set this property to 0, all detections are returned without performing thresholding or merging operation. This property is tunable.

Default: 4

Methods

cloneCreate cascade object detector object with same property values
getNumInputsNumber of expected inputs to step method
getNumOutputsNumber of outputs from step method
isLockedLocked status for input attributes and non-tunable properties
release Allow property value and input characteristics changes
stepDetect objects using the Viola-Jones algorithm

Examples

expand all

Detect Faces in an Image Using the Frontal Face Classification Model

Create a detector object.

    faceDetector = vision.CascadeObjectDetector;

Read input image.

    I = imread('visionteam.jpg');

Detect faces.

    bboxes = step(faceDetector, I);

Annotate detected faces.

   IFaces = insertObjectAnnotation(I, 'rectangle', bboxes, 'Face');
   figure, imshow(IFaces), title('Detected faces');

Detect Upper Body in an Image Using the Upper Body Classification Model.

Create a detector object and set properties.

   bodyDetector = vision.CascadeObjectDetector('UpperBody');
   bodyDetector.MinSize = [60 60];
   bodyDetector.MergeThreshold = 10;

Read input image and detect upper body.

   I2 = imread('visionteam.jpg');
   bboxBody = step(bodyDetector, I2);

Annotate detected upper bodies.

   IBody = insertObjectAnnotation(I2, 'rectangle',bboxBody,'Upper Body');
   figure, imshow(IBody), title('Detected upper bodies');

Algorithms

 Classification Model Training

 Cascade of Classifiers

 Multiscale Object Detection

 Relationship Between MinSize, MaxSize, and ScaleFactor

 Merge Detection Threshold

References

[1] Lienhart R., Kuranov A., and V. Pisarevsky "Empirical Analysis of Detection Cascades of Boosted Classifiers for Rapid Object Detection.", Proceedings of the 25th DAGM Symposium on Pattern Recognition. Magdeburg, Germany, 2003.

[2] Ojala Timo, Pietikäinen Matti, and Mäenpää Topi, "Multiresolution Gray-Scale and Rotation Invariant Texture Classification with Local Binary Patterns" . In IEEE Transactions on Pattern Analysis and Machine Intelligence, 2002. Volume 24, Issue 7, pp. 971-987.

[3] Kruppa H., Castrillon-Santana M., and B. Schiele. "Fast and Robust Face Finding via Local Context". Proceedings of the Joint IEEE International Workshop on Visual Surveillance and Performance Evaluation of Tracking and Surveillance, 2003, pp. 157–164.

[4] Castrillón Marco, Déniz Oscar, Guerra Cayetano, and Hernández Mario, "ENCARA2: Real-time detection of multiple faces at different resolutions in video streams". In Journal of Visual Communication and Image Representation, 2007 (18) 2: pp. 130-140.

[5] Yu Shiqi "Eye Detection." Shiqi Yu's Homepage.

[6] Viola, Paul and Michael J. Jones, "Rapid Object Detection using a Boosted Cascade of Simple Features", Proceedings of the 2001 IEEE Computer Society Conference on Computer Vision and Pattern Recognition, 2001. Volume: 1, pp.511–518.

[7] OpenCV (Open Source Computer Vision Library), OpenCV.

[8] Dalal, N., and B. Triggs, "Histograms of Oriented Gradients for Human Detection". IEEE Computer Society Conference on Computer Vision and Pattern Recognition. Volume 1, (2005), pp. 886–893.

[9] Ojala, T., M. Pietikainen, and T. Maenpaa, "Multiresolution Gray-scale and Rotation Invariant Texture Classification With Local Binary Patterns". IEEE Transactions on Pattern Analysis and Machine Intelligence. Volume 24, No. 7 July 2002, pp. 971–987.

See Also

| | |

More About

External Web Sites

Was this topic helpful?