Visual SLAM
The Visual SLAM(Simultaneous Localization and Mapping) creates a map by scanning 3D space.
Starting / Stopping the Tracker Starting / Stopping map generation, Saving map Setting Rendering Options
Starting / Stopping the 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();
}
Starting / Stopping map generation, Saving map
- To start a map generation, refer to the following code.
TrackerManager.GetInstance().FindSurface();
- To stop generating a map, refer to the following code.
TrackerManager.GetInstance().QuitFindingSurface();
- Saving map is only possible while tracking. When saving the generated map data to a file, refer to the following code for the file storage location.
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();
}
Setting Rendering Options
Feature points, SLAM initialization progress, Axis, and Surface mesh information can be displayed by option setting. 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.
