Image Tracker

The Image Tracker recognizes and tracks planar images. It can demonstrate not only 3D objects but also videos, even the transparent one.

Create Instants
Starting / Stopping the Tracker
Using the Tracking Information
Setting a Target Image
Adding / Replacing a Target Image
Changing Tracking Mode

Create Instants

>ImageTrackerViewController.mm

- (void)viewDidLoad
{
    ...
    trackingManager = [[MasTrackerManager alloc] init];
    cameraDevice = [[MasCameraDevice alloc] init];
    backgroundRenderer = [[MasBackgroundRenderer alloc] init];
    [MasMaxstAR onSurfaceCreated];
}

Starting / Stopping the Tracker

To start / stop Tracker after loading the map, refer to the following code.

>ImageTrackerViewController.mm

- (void)resumeAR
{
    ...
    [trackingManager startTracker:TRACKER_TYPE_IMAGE];
}

- (void)pauseAR
{
    [trackingManager stopTracker];
    ...
}

Using the Tracking Information

In the folder where SDK is installed, go to ‘data > SDKSample > Original > ImageTarget' folder, and there is sample target image. Print the image.

If you use the sample code, the following content will be augmented for each image.

  • Blocks.jpg: The alpha video is augmented.
  • Lego.jpg: The normal video is augmented.
  • Glacier.jpg: The cube with the texture is augmented.

To apply tracking results to augmented objects, refer to the following code.

>ImageTrackerViewController.mm

- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
{
    ...
    MasTrackingState *trackingState = [trackingManager updateTrackingState];
    MasTrackingResult *result = [trackingState getTrackingResult];
    
    MasBackgroundTexture *backgroundTexture = [backgroundRenderer getBackgroundTexture];
    [backgroundRenderer begin:backgroundTexture];
    [backgroundRenderer renderBackgroundToTexture];
    [backgroundRenderer end];
    
    [backgroundQuad draw:backgroundTexture projectionMatrix:[cameraDevice getBackgroundPlaneProjectionMatrix]];

    matrix_float4x4 projectionMatrix = [cameraDevice getProjectionMatrix];
    int trackingCount = [result getCount];
    
    if(trackingCount > 0)
    {
        for (int i = 0; i < trackingCount; i++)
        {
            MasTrackable *trackable = [result getTrackable:i];
            
            if([[trackable getName] isEqual: @"Lego"])
            {
                ...
            }
            else if([[trackable getName] isEqual: @"Blocks"])
            {
                ...
            }
            else if([[trackable getName] isEqual: @"Glacier"])
            {
                [texturedCube setProjectionMatrix:projectionMatrix];
                [texturedCube setPoseMatrix:[trackable getPose]];
                [texturedCube setTranslation:0.0f y:0.0f z:-0.025f];
                [texturedCube setScale:0.15f y:0.15f z:0.05f];
                [texturedCube draw];
            }
            ...
        }
    }
    ...
}

Setting a Target Image

By calling function addTrackerData to register the map file and calling function loadTrackerData, the target image can be tracked. To set a target image, refer to the following code.

>ImageTrackerViewController.mm

- (void)startEngine
{
    ...
    NSString *blocksTrackerMapPath = [[NSBundle mainBundle] pathForResource:@"Blocks" ofType:@"2dmap" inDirectory:@"data/SDKSample"];
    NSString *glacierTrackerMapPath = [[NSBundle mainBundle] pathForResource:@"Glacier" ofType:@"2dmap" inDirectory:@"data/SDKSample"];
    NSString *legoTrackerMapPath = [[NSBundle mainBundle] pathForResource:@"Lego" ofType:@"2dmap" inDirectory:@"data/SDKSample"];
    
    [trackingManager startTracker:TRACKER_TYPE_IMAGE];

    [trackingManager setTrackingOption:NORMAL_TRACKING];
    [trackingManager addTrackerData:blocksTrackerMapPath];
    [trackingManager addTrackerData:glacierTrackerMapPath];
    [trackingManager addTrackerData:legoTrackerMapPath];

    [trackingManager loadTrackerData];
}

Adding / Replacing a Target Image

  1. Create a map file refer to Documentation > Target Manager.

  2. Download the file you created.

  3. Unzip the downloaded file and copy it to the desired path.

  4. Set a target image.

Changing Tracking Mode

Image Tracker has three Tracking modes : normal, extended, and multi.

The default setting is normal mode.

  • normal mode: This is the normal image tracker.
[trackingManager setTrackingOption:NORMAL_TRACKING];
  • extended mode: This function is traceable even when the distance from the target image is far away.
[trackingManager setTrackingOption:EXTENDED_TRACKING];
  • multi mode: This function allows you to recognize and track up to three target images at the same time.
[trackingManager setTrackingOption:MULTI_TRACKING];