Can I integrate custom image tracking with AR Foundation?

Hi there!

I have a use case where I want to use a QR code as a reference image for tracking (preferrably within AR Foundation). The catch is, that the exact content of the QR code is not known in advance, so I can’t just add it as a reference image. Nevertheless, my QR code scanning library is pretty much able to precisely locate all four corners of the code on the 2D camera image in real time. I also know the physical size of the qr code.

Given this information, is there a way (ideally platform independent) to calculate the location and orientation of the code in 3D, so that I can place virtual content on it?
Thank you!

Edit: So, I ended up writing a plugin for this. If you are facing a similar issue, you may want to have a look :wink:

Yes, ARCore and ARKit support adding images at runtime.
https://docs.unity3d.com/Packages/com.unity.xr.arfoundation@3.0/api/UnityEngine.XR.ARFoundation.MutableRuntimeReferenceImageLibraryExtensions.html#UnityEngine_XR_ARFoundation_MutableRuntimeReferenceImageLibraryExtensions_ScheduleAddImageJob_MutableRuntimeReferenceImageLibrary_Texture2D_System_String_System_Nullable_System_Single__JobHandle_

Here an example:

if (trackedImageManager.descriptor.supportsMutableLibrary) {
    var mutableLib = trackedImageManager.referenceLibrary as MutableRuntimeReferenceImageLibrary;
    var imageWidth = 0.05f;
    mutableLib.ScheduleAddImageJob(texture, "image_name", imageWidth);
}