Two Stage Hybrid Tracker

From ImageWiki

Jump to: navigation, search

This page describes how DIKU's implementation of the Two Stage Hybrid Tracker (TSHT) can be used in C++. Here the tracker is described as a black-box. This means that only the programmers interface will be described, while algorithmic details aren't given. The tracking method is, however, very briefly described.

The implementation can be found in the "Robot Eksperimentarium" SVN in Examples/misc/ (the files are called and tsht.h).


Short algorithmic description

The tracker is a hybrid between the two well-known tracking algorithms, the Meanshift and the Particle Filter.

Meanshift is a simple and computationally efficient tracker, that (unfortunately) often gets misled. The only parameter needed by the meanshift algorithm is the size of the object that is to be tracked. The output from the meanshift tracker is the object position and a measure of the object size.

The Particle Filter is a technique for hypothesis selection. In tracking a hypothesis is the object position. The Particle Filter weights each hypothesis so good hypotheses gets large weights and bad hypotheses gets small weights. In the next iteration of the algorithm hypotheses are selected at random, but large weighted hypotheses has a large chance of being selected. So, good hypotheses survive while bad hypotheses die.

The Two Stage Hybrid Tracker is a hybrid between these two algorithms. A series of Meanshift trackers are executed, and the Particle Filter selects which of these trackers should be used in the next iteration.

The Tracking API

The tracker is implemented in the C++ class 'tsht' that has the following public interface

class tsht {
    // Constructor and destructor
    tsht(CvPoint initial_position, unsigned int radius=10, unsigned int num_samples=50);

    // The tracking functionality
    status update(IplImage *probmap);
    void reinitialize(CvPoint new_position, float uncertainty=10);

    // Get information about the tracked object
    CvPoint object_position();
    float object_size();
    const CvPoint* get_samples();

In the following, each of the public functions are described.

Constructor and destructor

The object constructor takes three arguments

  • CvPoint initial_position contains the objects position in the first frame.
  • unsigned int radius informs the tracker about the size of the object. It is assumed that the object is a 2*radius + 1 by 2*radius + 1 square.
  • unsigned int num_samples is the number of particles in the Particle Filter. Large values of num_samples gives a more stable tracking, but comes at the cost of increasing computationally demands.

The following code starts the tracking of an 11x11 object centered in (100, 100):

tsht tracker(cvPoint(100, 100), 5);

The object destructor needs no explanation.


This function does the tracking. The argument IplImage *probmap is a probability map that describes the object position. So, to use the tracker you need to create an image in which each pixel contains a value the describes how likely it is that the object is located in the pixel. It is assumed that the image is an 8 bit gray scale image. This means that it is highly likely that the object is in pixels with values of 255, and highly unlikely in pixels with values of 0.

The function either returns LOST_OBJECT or OK.


This function reinitializes the tracker. The object position is set to new_position. Large values of uncertainty means that the tracker isn't very certain on the position of the object. Usually this function is needed if the tracker no longer is able to find the object (tsht::update return LOST_OBJECT).


This function returns the currently best estimate of the objects current position.


Funktionen returnerer et tal der repræsenterer objektets størrelse. Der er vigtigt at indse at tallet ikke er objektets størrelse, men blot et tal der repræsenterer dette. Der skal altså ikke laves nogle geometriske overvejelser ud fra dette tal.


The function returns a pointer to the first element of an array of CvPoint's. Each point is a hypothesis in the Particle Filter. Usually you don't need to use this function.

Program sketch

A program using the tracker will often look something like this

#include "highgui.h"
#include "tsht.h"

int main()
    CvCapture *cam = cvCaptureFromCAM(-1);
    tsht tracker(cvPoint(100,100), 10, 150);

    while (cvWaitKey(4) == -1) {
        IplImage *input = cvQueryFrame(cam);
        IplImage *P = compute_probmap(input);

    return 0;

Here compute_probmap is a function that computes a probability map describing the objects position. To use the tracker you need to create this function.


Hybrid Particle Filter and Mean Shift tracker with adaptive transition model
Emilio Maggio og Andrea Cavallaro
Acoustics, Speech, and Signal Processing, 2005. Proceedings. (ICASSP apos;05). IEEE International Conference on
Volume 2, Issue , March 18-23, 2005 Page(s): 221 - 224
Download as PDF

Personal tools