Detect objects using the Viola-Jones algorithm
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.
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.
Define and set up your cascade object detector using the constructor.
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.
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.
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.
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.
Scaling for multiscale object detection
Specify the factor used to incrementally scale the search region. 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.
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.
|clone||Create cascade object detector object with same property values|
|getNumInputs||Number of expected inputs to step method|
|getNumOutputs||Number of outputs from step method|
|isLocked||Locked status for input attributes and non-tunable properties|
|release||Allow property value and input characteristics changes|
|step||Detect objects using the Viola-Jones algorithm|
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');
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
bodyDetector = vision.CascadeObjectDetector('UpperBody'); bodyDetector.MinSize = [60 60]; bodyDetector.ScaleFactor = 1.05;
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');
 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.
 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.
 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.
 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.
 Yu Shiqi "Eye Detection." Shiqi Yu's Homepage.http://yushiqi.cn/research/eyedetection
 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.
 OpenCV (Open Source Computer Vision Library), OpenCV.