Main Content


Initialize video frame and points to track



initialize(pointTracker,points,I) initializes points to track and sets the initial video frame. The function sets the M-by-2 points array of [x y] coordinates with the points to track, and sets the initial video frame, I.

If you want to use the point tracker as a persistent variable, you must call initialize only during creation. If you call initialize in a loop, the previous state is lost and therefore, the tracker cannot maintain tracking.


collapse all

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

videoReader = VideoReader('visionface.avi');
videoPlayer = vision.VideoPlayer('Position',[100,100,680,520]);

Read the first video frame, which contains the object, define the region.

objectFrame = readFrame(videoReader);
objectRegion = [264,122,93,93];

As an alternative, you can use the following commands to select the object region using a mouse. The object must occupy the majority of the region:

figure; imshow(objectFrame);


Show initial frame with a red bounding box.

objectImage = insertShape(objectFrame,'rectangle',objectRegion,'ShapeColor','red');
title('Red box shows object region');

Detect interest points in the object region.

points = detectMinEigenFeatures(im2gray(objectFrame),'ROI',objectRegion);

Display the detected points.

pointImage = insertMarker(objectFrame,points.Location,'+','MarkerColor','white');
title('Detected interest points');

Create a tracker object.

tracker = vision.PointTracker('MaxBidirectionalError',1);

Initialize the tracker.


Read, track, display points, and results in each video frame.

while hasFrame(videoReader)
      frame = readFrame(videoReader);
      [points,validity] = tracker(frame);
      out = insertMarker(frame,points(validity, :),'+');

Release the video player.


Input Arguments

collapse all

Point tracker, specified as a vision.PointTracker object.

Points, specified as an M-by-2 array of [x y] coordinates that correspond to the locations of the points in the input frame, I.

Video frame, specified as grayscale or truecolor (RGB) and must be the same size as the images read into the tracker.

Version History

Introduced in R2012b