Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

vision.HistogramBasedTracker System object

Histogram-based object tracking

Description

The histogram-based tracker incorporates the continuously adaptive mean shift (CAMShift) algorithm for object tracking. It uses the histogram of pixel values to identify the tracked object.

To track an object:

  1. Create the vision.HistogramBasedTracker object and set its properties.

  2. Call the object with arguments, as if it were a function.

To learn more about how System objects work, see What Are System Objects? (MATLAB).

Creation

Syntax

hbtracker = vision.HistogramBasedTracker
hbtracker = vision.HistogramBasedTracker(Name,Value)

Description

example

hbtracker = vision.HistogramBasedTracker returns a tracker that tracks an object by using the CAMShift algorithm. It uses the histogram of pixel values to identify the tracked object. To initialize the tracking process, you must use the initializeObject function to specify an exemplar image of the object.

hbtracker = vision.HistogramBasedTracker(Name,Value) creates a people detector object, tracker, with additional options specified by one or more Name,Value pair arguments.

Name is a property name and Value is the corresponding value. Name must appear inside single quotes (''). You can specify several name-value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: hbtracker = vision.HistogramBasedTracker('ObjectHistogram',[])

Properties

expand all

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 (MATLAB).

Normalized pixel value histogram, specified as an N-element vector. This vector specifies the normalized histogram of the object's pixel values. Histogram values must be normalized to a value between 0 and 1. You can use the initializeObject method to set the property.

Tunable: Yes

Usage

Syntax

bbox = hbtracker(I)
[bbox,orientation] = hbtracker(I)
[bbox,orientation,score] = hbtracker(I)

Description

bbox = hbtracker(I) returns a bounding box, of the tracked object. Before using the tracker, you must identify the object to track, and set the initial search window. Use the initializeObject function to do this.

[bbox,orientation] = hbtracker(I) additionally returns the angle between the x-axis and the major axis of the ellipse that has the same second-order moments as the object. The returned angle is between –pi/2 and pi/2.

[bbox,orientation,score] = hbtracker(I) additionally returns the confidence score for the returned bounding box that contains the tracked object.

Input Arguments

expand all

Video frame, specified as grayscale or truecolor (RGB).

Output Arguments

expand all

Bounding box, returned as a four-element vector in the format, [x y width height].

Orientation, returned as an angle between –pi/2 and pi/2. The angle is measured from the x-axis and the major axis of the ellipse that has the same second-order moments as the object.

Score, returned as a scalar in the range [0 1]. A value of 1 corresponds to the maximum confidence. 1.

Object Functions

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 obj, use this syntax:

release(obj)

expand all

initializeObjectSet object to track
initializeSearchWindowSet object to track
stepRun System object algorithm
releaseRelease resources and allow changes to System object property values and input characteristics
resetReset internal states of System object

Examples

expand all

Track and display a face in each frame of an input video.

Create System objects for reading and displaying video and for drawing a bounding box of the object.

videoFileReader = vision.VideoFileReader('vipcolorsegmentation.avi');
videoPlayer = vision.VideoPlayer();
shapeInserter = vision.ShapeInserter('BorderColor','Custom', ...
    'CustomBorderColor',[1 0 0]);

Read the first video frame, which contains the object. Convert the image to HSV color space. Then define and display the object region.

objectFrame = videoFileReader(); 
objectHSV = rgb2hsv(objectFrame); 
objectRegion = [40, 45, 25, 25];  
objectImage = shapeInserter(objectFrame, objectRegion);

figure
imshow(objectImage)
title('Red box shows object region')

(Optionally, you can select the object region using your mouse. The object must occupy the majority of the region. Use the following command.)

% figure; 
% imshow(objectFrame); 
% objectRegion=round(getPosition(imrect))

Set the object, based on the hue channel of the first video frame.

tracker = vision.HistogramBasedTracker;
initializeObject(tracker, objectHSV(:,:,1) , objectRegion);

Track and display the object in each video frame. The while loop reads each image frame, converts the image to HSV color space, then tracks the object in the hue channel where it is distinct from the background. Finally, the example draws a box around the object and displays the results.

while ~isDone(videoFileReader)
  frame = videoFileReader();          
  hsv = rgb2hsv(frame);                   
  bbox = tracker(hsv(:,:,1));       
                                        
  out = shapeInserter(frame,bbox); 
  videoPlayer(out);                 
end

Release the video reader and player.

release(videoPlayer);

release(videoFileReader);

Extended Capabilities

See Also

| |

Introduced in R2012a