Image Tracker

Related documentations
Target Manager
Recommended Conditions for Target Images
Tracker Coordinate System

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

Create Instants
Start / Stop Tracker
Use Tracking Information
Set Target Image
Add / Replace Target Image
Train Target Image Instantly
Change Tracking Mode

Create Instants

>ImageTrackerViewController.mm

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

Start / Stop 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];
    ...
}

Use 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];
    
    MasTrackedImage *trackedImage = [trackingState getImage];
    [backgroundCameraQuad draw:trackedImage 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];
            }
            ...
        }
    }
    ...
}

Set 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];
}

Add / Replace Target Image

  1. Create a map file refer to Documentation > Tools > 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.

Train Target Image Instantly

If you want to use a raw image file as an image target without an offline training process via Target Manager, enter a JSON object as the first parameter of addTrackerData().

A sample JSON format is like below.

{
    "image":"add_image",
    "image_path":"ImageTarget/Blocks.png",
    "image_width":0.26,
}

The "image":"add_image" pair should be located at first. The value of "image_path" is an image path and the value of "image_width" is a real width (meter unit) of an image target.
A sample code is like below.

 [trackingManager addTrackerData:@"{\"image\":\"add_image\",\"image_path\":\"ImageTarget/Blocks.png\",\"image_width\":0.26}"];

The instant training permits only jpg and png formats. An image width as a pixel size should be more than 320 and the best is 640.

※ Instant training of an image takes twice as much time as loading a 2dmap.
※ You must call loadTrackerData () after calling addTrackerData ().

Change Tracking Mode

5 Tracking Modes of Image Tracker:

NORMAL_TRACKING, EXTENDED_TRACKING, MULTI_TRACKING, JITTER_REDUCTION_ACTIVATION, JITTER_REDUCTION_DEACTIVATIO

  • NORMAL_TRACKING: Default Setting. Traceable one target image.
[trackingManager setTrackingOption:NORMAL_TRACKING];
  • EXTENDED_TRACKING: Traceable even at the far distance from the target image.
[trackingManager setTrackingOption:EXTENDED_TRACKING];
  • MULTI_TRACKING: Possible to recognize and track up to three target images at the same time.
[trackingManager setTrackingOption:MULTI_TRACKING];
  • JITTER_REDUCTION_ACTIVATION: Jitter reduction.
[trackingManager setTrackingOption: JITTER_REDUCTION_DEACTIVATION: Disable the jitter reduction option.

  • JITTER_REDUCTION_DEACTIVATION: disable reduce Jitter.
[trackingManager setTrackingOption: JITTER_REDUCTION_DEACTIVATION];