Unity-Technologies / arfoundation-samples

Example content for Unity projects based on AR Foundation
Other
2.99k stars 1.11k forks source link

Image tracking and QR codes #989

Closed devrandomzero closed 1 year ago

devrandomzero commented 2 years ago

Hi, I've already asked this in the Unity forum but maybe I'll be more lucky here.. In my current project I'm using image tracking only for image detection and not for the tracking part. By documentation AR Foundation permits to track (detect in my case) a maximum number of 20 images but I need to detect simultaneously more images, between 30 and 40. Just to be clear I don't need tracking at all because every detection needs to happen just once and when it happens it just opens a popup on screen with some text (no prefab with a 3D model is spawing). So here's my two questions: 1) Because I'm just detecting the image, is the maximum number of 20 images simultaneously still counting as a hard limit? 2) If yes, is it possibile to use maybe a QR code scanner alongside AR Foundation (like in some kind of parallel mode) without compromise the AR functionality?

Obviously I'm open to suggestions for other ways to deal with this.

Thank you in advance

Bye

ankur-unity commented 2 years ago

The limitations on the maximum number of simultaneously tracked images is imposed by the platform SDKs. For example, ARCore only track up to 20 images simultaneously: https://developers.google.com/ar/develop/augmented-images#moving-images. This value can not be changed in ARCore.

ARKit, on the other hand, track a maximum of 4 images simultaneously: https://developer.apple.com/documentation/arkit/argeotrackingconfiguration/3566285-maximumnumberoftrackedimages?language=objc. This value if set to 0 by default. You can use ARTrackedImageManager.requestedMaxNumberOfMovingImages to set this to a nonzero value. Setting a value higher than 4 will still track a maximum of 4 images simultaneously.

devrandomzero commented 2 years ago

The limitations on the maximum number of simultaneously tracked images is imposed by the platform SDKs. For example, ARCore only track up to 20 images simultaneously: https://developers.google.com/ar/develop/augmented-images#moving-images. This value can not be changed in ARCore.

ARKit, on the other hand, track a maximum of 4 images simultaneously: https://developer.apple.com/documentation/arkit/argeotrackingconfiguration/3566285-maximumnumberoftrackedimages?language=objc. This value if set to 0 by default. You can use ARTrackedImageManager.requestedMaxNumberOfMovingImages to set this to a nonzero value. Setting a value higher than 4 will still track a maximum of 4 images simultaneously.

Thank you for your answer, at this point the only thing I can do is to use the QR code scanner side by side with the AR.

tdmowrer commented 2 years ago

To clarify, ARKit can detect many more than 4 images, but it can only track 4 simultaneously in realtime. ARKit has a very specific definition of "track":

The word track in the property name refers to how the framework closely monitors the image's physical position and orientation for any changes.

So you can set the max number of moving images to zero and it will still detect them:

...with this property set to 0, ARKit creates image anchors for observed reference images but their positions only update infrequently, such as once every couple of seconds.

I don't think Apple have explicitly said what, if any, limit exists on the number of simultaneously detectable images there are.

ARCore is a little more vague, but they do seem to make a similar distinction:

ARCore can track up to 20 images simultaneously. ARCore will not simultaneously detect or track multiple instances of the same image.

"detect" or "track" -- I've never tried, but I suspect that means they will continue to detect new images but only "track" (as in, provide per frame updates) 20 at a time.

Since your use case only involves the initial detection and not actively tracking moving images, you might want to give it a go.

devrandomzero commented 2 years ago

Thank you Tim for your answer, I will surely try that, maybe this way I could avoid QR codes altogether. Another question, to avoid a performance hit do you think it's possible to completely stop detection and/or tracking for a single image? For reference I'm using the code snippet from the AR Foundation Unity wiki:

private void OnTrackedImagesChanged(ARTrackedImagesChangedEventArgs eventArgs)
{
    foreach (var trackedImage in eventArgs.added)
    {
          // Raise an event (System.Action)
    }
}

At the moment the first time that an Image is detected I only raise an event. What I'm still trying to understand is: 1) every image is never detected twice, right? 2) after that is detected, how can I disable its tracking? I already know that I cannot remove images from the reference library at runtime.

Thank you so much for your help

Bye

tdmowrer commented 2 years ago

I believe the only way to stop tracking an image would be to use an image library that doesn't contain that image (but there's also no way to remove an image from an existing library).

devrandomzero commented 2 years ago

Thank you Tim, I hope that in the future the devs will add the possibility to remove an image from the library at runtime.

For now maybe I could recreate the library everytime I detect an image, in the end the app it's quite simple/lightweight per se so it doesn't require a strong realtime interaction between the AR and the environment. What do you think? Maybe is better if I use an async/await method instead of a coroutine like I'm using at the moment?

"detect" or "track" -- I've never tried, but I suspect that means they will continue to detect new images but only "track" (as in, provide per frame updates) 20 at a time.

Since your use case only involves the initial detection and not actively tracking moving images, you might want to give it a go.

About this I can confirm to you that ARFoundation + ARCore can succesfully detect more than 20 images (the test I did was with 23).

Thank you again for your help

Bye

ankur-unity commented 1 year ago

Closing as resolved. Feel free to reopen if you have more questions.

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.