Image-based Relocalization Sample
Note: It is highly recommended to read the Map-based Relocalization Sample first because it explains many of the same concepts that is used in this sample. This tutorial will not go over the same concepts that is already explained there.
This sample will use image-based relocalization to find an image marker and use its real world position as a shared anchor. This sample will also show a cube on the shared anchor position on successful relocalization. After the shared anchor is found, the SDK will move the AR origin (0, 0, 0) to the position of the shared anchor. For image-based shared anchors, this location in the real world space is the place of the image marker.
Understanding the Scene
Scene Hierarchy
We can see that it is very similar to the hierarchy from Map-based Relocalization Sample. The most noticable difference that can be seen right away is that it doesn't have the ScoreUpdater
object, and this is because we do not support RelocalizationScore
for image-based relocalization. All the other objects and behaviors are the same, and only differs in the setting of ARSharedAnchorManager
.
AR Shared Anchor Manager
On the ARSharedAnchorManager
component, we can see that it now has ARTrackedImageManager
component attached to it. Image-based relocalization is built on top of AR Foundation's image tracking capabilities. To setup image-based relocalization, we need to assign ARTrackedImageManager
to it, and choose one of the images available in the ReferenceImageLibrary
to use as the shared anchor.
Starting/Stopping Relocalization
Starting an image-based relocalization uses a slightly different API than for map-based.
// Grab an instance of ARSharedAnchorManager
private ARSharedAnchorManager _sharedAnchorManager;
// Start image-based relocalization using the default
// reference image set in the inspector
_sharedAnchorManager.StartImageRelocalization();
// Alternatively, you can start image-based relocalization
// using referenceImage as input parameter
XRReferenceImage referenceImage;
_sharedAnchorManager.StartImageRelocalization(referenceImage);
// Stop any running relocalization process and
// reset the shared anchor status
_sharedAnchorManager.ResetSharedAnchor();
Handling Events
Any event handling is done the same way as explained in the previous tutorial for map-based relocalization sample. Please refer to Handling Events to learn more.
Building the Sample
There are some settings we need to do before we can build our application. Please refer to this guide on how to build your application.
Running the Sample
Run the sample on a device, and verify the app's behaviour by scanning the image marker that you have set. You should be able to see a cube on the shared anchor position, which is the image marker location.