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.
To detect people in an image:
vision.PeopleDetector object and set its properties.
Call the object with arguments, as if it were a function.
To learn more about how System objects work, see What Are System Objects?.
returns a people detector object,
peopleDetector = vision.PeopleDetector
peopleDetector, that tracks a set
of points in a video.
creates a people detector object and sets the
peopleDetector = vision.PeopleDetector(
ClassificationModel property to
sets properties using one or more name-value pairs. Enclose each property name in
quotes. For example,
peopleDetector = vision.PeopleDetector(
Unless otherwise indicated, properties are nontunable, which means you cannot change their
values after calling the object. Objects lock when you call them, and the
release function unlocks them.
If a property is tunable, you can change its value at any time.
For more information on changing property values, see System Design in MATLAB Using System Objects.
ClassificationModel— Name of classification model
Name of classification model, specified as
'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.
ClassificationThreshold— People classification threshold
1(default) | nonnegative scalar value
People classification threshold, specified as a nonnegative scalar 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
MinSize— Smallest region containing a person
(default) | two-element vector
Smallest region containing a person, specified in pixels as a two-element vector, [height width]. Set this property to the minimum size region containing a person. You can reduce computation time when you set this property. 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 detector sets it to the image size used to train the classification model.
MaxSize— Largest region containing a person
(default) | two-element vector
Largest region that contains a person, specified in pixels as a two-element vector, [height width]. Set this property to the largest region containing a person. You can reduce computation time when you set this property. 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 detector sets it to the input image size. This property is tunable.
ScaleFactor— Multiscale object detection scaling
1.05(default) | numeric value greater than
Multiscale object detection scaling, specified as a value greater than
1.0001. The scale factor incrementally scales the detection
MaxSize. You can set the scale factor to an ideal value using:
[128 64]for the
[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.
WindowStride— Detection window stride
[8 8](default) | scalar | two-element vector
Detection window stride in pixels, specified as a scalar or a two-element vector,
y]. The detector 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.
MergeDetections— Merge detection control
Merge detection control, specified as
false. This property controls 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
UseROI— Use region of interest
Use region of interest, specified as
false. Set this property to
true to detect
objects within a rectangular region of interest within the input image.
performs multiscale object detection on the input image,
bboxes = peopleDetector(
returns an M-by-4 matrix defining M bounding
boxes. M represents the number of detected people. Each row of the
BBOXES, contains a four-element vector,
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.
additionally returns a confidence value for the detections.
scores] = peopleDetector(
I— Input image
Input image, specified as grayscale or truecolor (RGB).
roi— Rectangular region of interest
Rectangular region of interest within image
I, specified as a
four-element vector, [x
model— Classification model
Classification model, specified as
peopleDetector— People detector
People detector object, returned as an object. The detector detects people in an input image using the Histogram of Oriented Gradient (HOG) features and a trained SVM classifier. The object detects unoccluded people in an upright position.
To use an object function, specify the
System object™ as the first input argument. For
example, to release system resources of a System object named
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] = peopleDetector(I);
Annotate detected people.
I = insertObjectAnnotation(I,'rectangle',bboxes,scores); 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.
Usage notes and limitations:
Generates portable C code using a C++ compiler that links to OpenCV (Version 3.4.0) libraries. See Portable C Code Generation for Functions That Use OpenCV Library.
See System Objects in MATLAB Code Generation (MATLAB Coder).