Visual SLAM

Related documentations
Map Manager
Tracker Coordinate System in Unity
Visual SLAM Learning Guide

The Visual SLAM(Simultaneous Localization and Mapping) creates a map by scanning 3D space.

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

Start / Stop Tracker
Start / Stop Map Creation & Map Saving
Set Rendering Options
GitHub Unity Scene Example

Start / Stop Tracker

To start / stop tracker, refer to the following code.

>VisualSLAMSample.cs

void Start ()
{
    ...
    TrackerManager.GetInstance().StartTracker(TrackerManager.TRACKER_TYPE_SLAM);
    ...
}

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

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

Start / Stop Map Creation & Map Saving

  • To start a map generation, refer to the following code.
TrackerManager.GetInstance().FindSurface();
  • To stop a map generation, refer to the following code.
TrackerManager.GetInstance().QuitFindingSurface();
  • Saving map is only possible while tracking. Refer to the following code for the file storage location when you save the generated map data as a file.

>VisualSLAMSample.cs

public void SaveSurfaceData(string imageFileName)
{
    SurfaceThumbnail surfaceThumbnail = TrackerManager.GetInstance().SaveSurfaceData(imageFileName);
    int width = surfaceThumbnail.GetWidth();
    int height = surfaceThumbnail.GetHeight();
    byte[] thumbnailData = surfaceThumbnail.GetData();

    Texture2D tex = new Texture2D(width, height, TextureFormat.RGB24, false);

    for (int y = 0; y < height; y++)
    {
        for (int x = 0; x < width; x++)
        {
            int index = y * width + x;
            tex.SetPixel(x, height - y, new Color(thumbnailData[index] / 255.0f, thumbnailData[index] / 255.0f, thumbnailData[index] / 255.0f));
        }
    }
    tex.Apply();

    FileStream fileSave = new FileStream(Application.dataPath + "/" + imageFileName + ".png", FileMode.Create);
    BinaryWriter binary = new BinaryWriter(fileSave);

    binary.Write(tex.EncodeToPNG());
    fileSave.Close();
}

Set Rendering Options

Feature points, SLAM initialization progress, and axis can be created with 'FeaturePoint', 'Axis' class. Refer to the following code.

>VisualSLAMSample.cs

void Start()
{
    ...
    BackgroundRenderer.GetInstance().SetRenderingOption(BackgroundRenderer.RenderingOption.FEATURE_RENDERER, BackgroundRenderer.RenderingOption.PROGRESS_RENDERER, BackgroundRenderer.RenderingOption.SURFACE_MESH_RENDERER);
    ...
}

See BackgroundRenderer.RenderingOption enum for option settings.

Preferably, use landscape left mode (screen orientation) for Visual SLAM.

GitHub Unity Scene Example

GitHub Unity Scene Example: https://github.com/maxstdev/MaxstARSDK_Unity_Sample.git

More

  • ExtraVisualSLAMBrush
  • ExtraVisualSLAMKnight