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, you should add 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. Connect a webcam to PC and press 'play' button. Point the webcam at the target object and check whether your virtual objects are located places where you want.

    augment.PNG

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();
}

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);