Object Tracker

Related documentations
Visual SLAM Tool
Tracker Coordinate System in Unity
Visual SLAM Learning Guide

The Object Tracker loads the map file and renders a 3D object on it.

Please refer Visual SLAM Learning Guide to create a map more precisely while scanning 3D space.

Make Object Tracker Scene
Set Map
Add / Replace Map
Start / Stop Tracker
Use Tracking Information
Change Tracking Mode

Make Object Tracker Scene

  1. Install the MAXST AR SDK for Unity.

  2. Create the new scene.

  3. Delete the Main Camera that exists by default and add 'Assets > MaxstAR > Prefabs > ARCamera, ObjectTrackable' to the scene.

    objectPrefab

    ※ If you build an application, you must add a License Key to ARCamera.

  4. Create an empty object and add 'Assets > MaxstARSamples > Scripts > ObjetTrackerSample' as a component.

    objectSample

  5. Place the map file created by Visual SLAM scene in Assets > StreamingAssets > MaxstAR, and drag map file to Inspector of ObjectTrackable to set map file. Enter -1 for the Real Size. Press the Load button to set the map in the map viewer described later.
    ※ If the map file is not placed under the StreamingAssets folder, the map file is not recognized.

    ObjectMapSetting

  6. After the map file is loaded, you can see pins with which the trained object is overlaid in Scene View and Game View. You can check some pins in the red rectangles in the below figure.

    after_load.PNG

  7. In MapViewer's Inspector, 'Show Mesh' option is checked as default. Choose a keyframe where you can work easily with moving the slider bar.

    inspector.PNG

    ※ MapViewer

    • If you set a map file in ObjectTrackable, MapViewer is automatically created as a child of ObjectTrackable.

    • Keyframe Id: When creating a map, the camera looks at the target in various directions. At this time, a Keyframe is created for each direction that satisfies a certain condition. If you change Keyframe Id, Mesh / Image of the Keyframe is displayed in Game View. By positioning Cube in each Keyframe, you can position Cube more precisely.

    • Show Mesh: If checked, the image displayed in the Game View changes to Mesh.

    • Transparent: If checked, Mesh / Image becomes transparent.

  8. Place a virtual object as a child of ObjectTrackable. 'maxst_cube' is placed as default.

  9. The position of a pin means where to locate a virtual object while someone creates an object map via Visual SLAM Tool. Place a virtual object referring to pin positions.

    arrangement.PNG

  10. Build and run the app. Then, point the camera at the target object and the virtual content will augment where you place it.

  11. If you have a webcam connected, you can test it in the Unity Editor environment by pressing the Play button in Unity.

※ You can download the target Object from the Object Target link.

Set Map

By calling addTrackerData () to register the map file and calling loadTrackerData (), Space can be tracked. To set a map, refer to the following code.

>ObjectTrackerSample.cs

private void AddTrackerData()
{
    foreach (var trackable in objectTrackablesMap)
    {
        if (trackable.Value.TrackerDataFileName.Length == 0)
        {
            continue;
        }

        if (trackable.Value.StorageType == StorageType.AbsolutePath)
        {
            TrackerManager.GetInstance().AddTrackerData(trackable.Value.TrackerDataFileName);
        }
        else
        {
            if (Application.platform == RuntimePlatform.Android)
            {
                TrackerManager.GetInstance().AddTrackerData(trackable.Value.TrackerDataFileName, true);
            }
            else
            {
                TrackerManager.GetInstance().AddTrackerData(Application.streamingAssetsPath + "/" + trackable.Value.TrackerDataFileName);
            }
        }
    }

    TrackerManager.GetInstance().LoadTrackerData();
}

Note - Map Compatibility
Starting with Visual Slam Tool 5.1.0, the file format for 3dmaps has changed. 3dmaps created in Visual Slam Tool 5.1.0 or later are supported by AR SDK 6.2.x or later. If you want to continue using AR SDK 6.0.x or earlier, please use Visual Slam Tool 5.0.8 Android.
Also, you can only add 3dmaps from the same version to Object Tracker.


Set Package

If you are using a multi-object map, packaging it in a 3dpkg file will greatly improve map loading speed and object recognition speed.
Create a 3dpkg with MapPackager, call AddTrackerData() to register the package file, and call LoadTrackerData() to make the target object ready for tracking. See the following code for how to set up an object package.

private IEnumerator AddTrackerData()
{
    string packagePath = ... // The file must exist in the streaming asset.

    yield return new WaitForEndOfFrame();

    if (Application.platform == RuntimePlatform.Android)
    {
        List<string> fileList = new List<string>();
        yield return StartCoroutine(MaxstARUtil.ExtractAssets(packagePath, fileList));
        TrackerManager.GetInstance().AddTrackerData(fileList[0], false);
    }
    else
    {
        TrackerManager.GetInstance().AddTrackerData(Application.streamingAssetsPath + "/" + packagePath);
    }

    TrackerManager.GetInstance().LoadTrackerData();
}

※ Object Package(3dpkg) is available from AR SDK 6.1.0.
※ Only 3dmaps created in Visual Slam Tool 5.1.0 or later can be packaged as 3dpkg.
※ Only one 3dpkg can be added to Object Tracker.

Add / Replace Map

  1. Create a map file refer to Visual SLAM Tool

  2. Copy the received map file to the desired path.

  3. Set a map.

  4. You can load a new map with AddTrackerData (), LoadTrackerData (), and delete the loaded map with RemoveTrackerData ().

  5. Up to three 3dmaps can be loaded, and three loaded maps can be tracked one at a time. It is not tracked at the same time.

Start / Stop Tracker

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

>ObjectTrackerSample.cs

void Update()
{
    ...
    if (!startTrackerDone)
    {
        TrackerManager.GetInstance().StartTracker(TrackerManager.TRACKER_TYPE_OBJECT);
        ...
    }
    ...
}

void OnApplicationPause(bool pause)
{
    ...
    TrackerManager.GetInstance().StopTracker();
    ...
}

void OnDestroy()
{
    TrackerManager.GetInstance().StopTracker();
    TrackerManager.GetInstance().DestroyTracker();
    ...
}

Use Tracking Information

To use the Tracking information, refer to the following code.

>ObjectTrackerSample.cs

void Update()
{
    ...
    TrackingState state = TrackerManager.GetInstance().UpdateTrackingState();
    TrackingResult trackingResult = state.GetTrackingResult(); 

    for (int i = 0; i < trackingResult.GetCount(); i++)
    {
        Trackable trackable = trackingResult.GetTrackable(i);

        if (!objectTrackablesMap.ContainsKey(trackable.GetName()))
        {
            return;
        }

        objectTrackablesMap[trackable.GetName()].OnTrackSuccess(trackable.GetId(), trackable.GetName(), trackable.GetPose());
    }
}

Change Tracking Mode

2 Tracking Modes of Object Tracker:

NORMAL_TRACKING, EXTENDED_TRACKING

  • EXTENDED_TRACKING: learn and extend the real-time learning beyond the object to the surrounding environment. When the current camera frame does not have enough feature points for the object, the surrounding environment can be used to estimate the location of the object.
TrackerManager.GetInstance().SetTrackingOption(TrackerManager.TrackingOption.EXTENDED_TRACKING);
  • NORMAL_TRACKING: Track only a trained object.
TrackerManager.GetInstance().SetTrackingOption(TrackerManager.TrackingOption.NORMAL_TRACKING);