Documentation

Contents

vision.PeopleDetector System object

Package: vision

Detect upright people using HOG features

Description

The people detector object detects people in an input image using the Histogram of Oriented Gradient (HOG) features and a trained Support Vector Machine (SVM) classifier. The object detects unoccluded people in an upright position.

Construction

peopleDetector = vision.PeopleDetector returns a System object, peopleDetector, that tracks a set of points in a video.

peopleDetector = vision.PeopleDetector(MODEL) creates a peopleDetector System object and sets the ClassificationModel property to MODEL. The input MODEL can be either 'UprightPeople_128x64' or 'UprightPeople_96x48'.

peopleDetector = vision.PeopleDetector(Name,Value) configures the tracker object properties, specified 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 people:

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

  2. Call the step method with the input image, I, and the people detector object, peopleDetector. See the syntax below for using the step method.

BBOXES = step(peopleDetector,I) performs multiscale object detection on the input image, I. The method returns an M-by-4 matrix defining M bounding boxes, where M represents the number of detected people. Each row of the output matrix, BBOXES, contains a four-element vector, [x y width height]. This vector specifies, in pixels, the upper-left corner and size, of a bounding box. When no people are detected, the step method returns an empty vector. The input image, I, must be a grayscale or truecolor (RGB) image.

[BBOXES, SCORES] = step(peopleDetector,I) returns a confidence value for the detections. The M-by-1 vector, SCORES, contain positive values for each bounding box in BBOXES. Larger score values indicate a higher confidence in the detection. The SCORES value depends on how you set the MergeDetections property. When you set the property to true, the people detector algorithm evaluates classification results to produce the SCORES value. When you set the property to false, the detector returns the unaltered classification SCORES.

Properties

ClassificationModel

Name of classification model

Specify the model as either 'UprightPeople_128x64' or 'UprightPeople_96x48'. The pixel dimensions indicate the image size used for training.

The images used to train the models include background pixels around the person. Therefore, the actual size of a detected person is smaller than the training image size.

Default: 'UprightPeople_128x64'

ClassificationThreshold

People classification threshold

Specify as a nonnegative scalar threshold value. Use this threshold to control the classification of individual image subregions during multiscale detection. The threshold controls whether a subregion gets classified as a person. You can increase this value when there are many false detections. The higher the threshold value, the more stringent the requirements are for the classification. Vary the threshold over a range of values to find the optimum value for your data set. Typical values range from 0 to 4. This property is tunable.

Default: 1

MinSize

Smallest region containing a person

Specify a two-element vector, [height width], in pixels for the smallest region containing a person. When you know the minimum person size to detect, you can reduce computation time. To do so, set this property to a value larger than the image size used to train the classification model. When you do not specify this property, the object sets it to the image size used to train the classification model. This property is tunable.

Default: []

MaxSize

Largest region containing a person

Specify a two-element vector, [height width], in pixels for the largest region containing a person. When you know the maximum person size to detect, you can reduce computation time. To do so, set this property to a value smaller than the size of the input image. When you do not specify this property, the object sets it to the input image size. This property is tunable.

Default: []

ScaleFactor

Multiscale object detection scaling

Specify a factor, with a value greater than 1.0001, to incrementally scale the detection resolution between MinSize and MaxSize. You can set the scale factor to an ideal value using:

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


The object calculates the detection resolution at each increment.

round(TrainingSize*(ScaleFactorN))

In this case, the TrainingSize is [128 64] for the 'UprightPeople_128x64' model and [96 48] for the 'UprightPeople_96x48' model. N is the increment. Decreasing the scale factor can increase the detection accuracy. However, doing so increases the computation time. This property is tunable.

Default: 1.05

WindowStride

Detection window stride

Specify a scalar or a two-element vector [x y] in pixels for the detection window stride. The object uses the window stride to slide the detection window across the image. When you specify this value as a vector, the first and second elements are the stride size in the x and y directions. When you specify this value as a scalar, the stride is the same for both x and y. Decreasing the window stride can increase the detection accuracy. However, doing so increases computation time. Increasing the window stride beyond [8 8] can lead to a greater number of missed detections. This property is tunable.

Default: [8 8]

MergeDetections

Merge detection control

Specify a logical scalar to control whether similar detections are merged. Set this property to true to merge bounding boxes using a mean-shift based algorithm. Set this property to false to output the unmerged bounding boxes.

For more flexibility and control of merging parameters, you can use the selectStrongestBbox function in place of the MergeDetections algorithm. To do this, set the MergeDetections property to false. See the Tracking Pedestrians from a Moving Car example, which shows the use of the people detector and the selectStrongestBbox function.

Default: true

Methods

cloneCreate alpha blender object with same property values
isLockedLocked status for input attributes and nontunable properties
release Allow property value and input characteristics changes
stepDetect upright people using HOG features

Examples

expand all

Detect People

  1. Create a people detector, and load the input image.

    peopleDetector = vision.PeopleDetector;
    I = imread('visionteam1.jpg');
    
  2. Detect people using the people detector object.

    [bboxes, scores] = step(peopleDetector, I); 
  3. Create a shape inserter and a score inserter.

    shapeInserter = vision.ShapeInserter('BorderColor','Custom','CustomBorderColor',[255 255 0]);
         
    scoreInserter = vision.TextInserter('Text',' %f','Color', [0 80 255],'LocationSource','Input port','FontSize',16);
    
  4. Draw detected bounding boxes, and insert scores using the inserter objects.

     I = step(shapeInserter, I, int32(bboxes));
     I = step(scoreInserter, I, scores, int32(bboxes(:,1:2))); 
    
    figure, imshow(I)
    title('Detected people and detection scores'); 

References

Dalal, N. and B. Triggs. "Histograms of Oriented Gradients for Human Detection,"Proceedings of IEEE Conference on Computer Vision and Pattern Recognition, June 2005, pp. 886-893.

Was this topic helpful?