News Download Projects Publications Community Documentation
home > documentation > tutorial 1: tracking stability
Next: Tutorial 2: Camera and Marker Relationships
Tutorial 1: Tracking Stability

We have seen before how to create a simple ARToolKit program. Now we want introduce an important feature of ARToolKit: the history function. Go to the bin directory and run the simpleTest2 program. You will see something similar to the screenshot in Figure 1.

Figure 1: The simpleTest2 Program

You will notice no immediate difference with the simpleTest program. However, if you move the pattern close to the camera (as in Figure 2) and press 'c', a difference appears. In one case the cube seems very stable and in the other case it seems to jitter around slightly. In the former case we are using a history function, in the latter not.

Figure 2: A closer view reveals jittering when the history function is not used.

In this tutorial introduce how to use the history functions of ARToolKit.

Using the History Functions

Open the simpleTest2.c program in examples/simple2. In the mainLoop function you will be find this new function call:

/* get the transformation between the marker and the real camera */
if( mode == 0 || contF == 0 ) {
    arGetTransMat(&marker_info[k], patt_center,
        patt_width, patt_trans);
} else {
    arGetTransMatCont(&marker_info[k], patt_trans, patt_center,
        patt_width, patt_trans);

contF = 1;

The arGetTransMatCont function uses information from the previous image frame to reduce the jittering of the marker. With arGetTransMat, only the information from the current image frame is used to compute the position of the marker. When using the history function, the result will be less accurate because the history information increases performance at the expense of accuracy.

ARToolKit provides another function based on history, but for the detection phase. We have already introduced this function, it is arDetectMarker. The corresponding function that does not use a history if arDetectMarkerLite. As before, using a history will reduce the accuracy, but offer more stability and is a little faster.

Replace the arDetectMarker call with this one:

/* detect the markers in the video frame */
if( arDetectMarkerLite(dataPtr, thresh,
        &marker_info, &marker_num) < 0 ) {

Recompile simpleTest2 and position the marker so that it faces the camera (as in Figure 3). You will notice than the cube does more and more "popping".

Figure 3: A closer view reveals jittering when the history function is not used.

The popping effect is due to the lost information from the last frame, and the bad orientation of the marker is not sufficient for the detection step. Even if template matching was not done successfully, if there is a tracked marker with almost same size and same position in previous frame, the marker is regarded as a same marker of previous frame.