Detect upright people using HOG features
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.
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|
Define and set up your people detector object using the constructor.
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.
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.
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.
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.
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.
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:
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.
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]
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.
|clone||Create alpha blender object with same property values|
|isLocked||Locked status for input attributes and nontunable properties|
|release||Allow property value and input characteristics changes|
|step||Detect upright people using HOG features|
Create a people detector, and load the input image.
peopleDetector = vision.PeopleDetector; I = imread('visionteam1.jpg');
Detect people using the people detector object.
[bboxes, scores] = step(peopleDetector, I);
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);
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');
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.