Search Unity

Tracked image won't go away

Discussion in 'AR' started by Antistone, Feb 5, 2020.

Thread Status:
Not open for further replies.
  1. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,836
    I'm trying to do a simple test of image tracking using AR Tracked Image Manager and testing on an Android phone. I can get it to recognize some images and instantiate my prefab on top of them. However, when I take the image away, the prefab remains in the scene (even though the "Destroy On Removal" box is checked on the "AR Tracked Image" component).

    I'm new to AR tracking. Any thoughts on what might be going wrong / things I should check?
     
  2. DeeForce

    DeeForce

    Unity Technologies

    Joined:
    Jul 16, 2018
    Posts:
    15
    With ARKit, the images are removed, ARCore images have tracking status TrackingState.None, and in a future release we will be unifying this behavior :)!
    For now you are doing nothing incorrectly and things will be underway on our end :)
     
  3. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,836
    I don't seem to be getting TrackingState.None. It only changes between TrackingState.Tracking and TrackingState.Limited.

    Even if I cover up the camera so the entire picture is black, or rotate it so that the trackable prefab is completely off-screen, it still claims to be getting limited tracking of the images that it has previously seen.
     
  4. petitbas

    petitbas

    Joined:
    Sep 9, 2014
    Posts:
    17
    So is there a workaround to detect when an image is no longer being tracked (both on Android and iOS)?
     
    beatdesign likes this.
  5. beatdesign

    beatdesign

    Joined:
    Apr 3, 2015
    Posts:
    137
    Anyone?
     
  6. FrankvHoof

    FrankvHoof

    Joined:
    Nov 3, 2014
    Posts:
    258
    @DeeForce "For now you are doing nothing incorrectly"
    I thought the actual implementation was Provider-Specific? I.e. the Provider decides what the 'Update'- and 'Remove'-requirements are?

    You state that you will be unifying ARCore & ARKit, but what does this mean for other Providers?

    @Antistone as far as I'm aware you should not be relying on the Remove to run when the position of your Image moves out of frame. (And unless you have a death-ray I don't think you're actually 'Destroying' your image). For most (if not all) of the Trackables, you should stick to the following:
    - Add: The trackable was first discovered.
    - Update: The trackable has changed. (i.e. the Pose of the Object changed, a Plane changed in size, etc.) This is usually due to an improved understanding of the detected Trackable over time (or due to the object actually moving in the real world).
    - Remove: The trackable was destroyed. This would be specific to both the object and provider. (Example: Plane was removed because it is far away and memory-space is needed)
     
  7. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,836
    I'm no longer attempting to use image-tracking in my app, but in trying to understand the previous reply I've realized I was not originally clear about the practical problem I was experiencing. So, for posterity:

    I hold the image in front of the camera, the game picks it up and instantiates my prefab to show where in the world the image has been detected.

    I remove the image, and the prefab stays there, floating in front of the camera, attached to nothing. And continues to float in front of the camera even as I walk around to different rooms--it's not attached to anything in the real world, just cluttering up my view.

    NOTE: This was a year ago. I haven't tested recently.

    So regardless of any organizational issues of whether the prefab is supposed to be destroyed versus being preserved at the last known location of the tracked image, the practical issue is that Unity was claiming that it can continue to partially-detect the image somewhere in front of the camera even once the image was definitely no longer there.
     
  8. FrankvHoof

    FrankvHoof

    Joined:
    Nov 3, 2014
    Posts:
    258
    "I remove the image, and the prefab stays there, floating in front of the camera, attached to nothing."
    That's weird.. Images are supposed to be returned in worldspace by ARFoundation.. So that would sound like it was somehow still updating the image each frame (which would only happen if the underlying system (e.g. ARCore) was reporting these updates)
     
  9. beatdesign

    beatdesign

    Joined:
    Apr 3, 2015
    Posts:
    137
    Tested with ARFundation 4.3.1, ARCore
    This is the behaviour:
    - Look at marker A: event A.Added is called
    - Continue to look at marker A: event A.updated is called
    - Look away from marker A, go in another room, etc: event A.updated is called. *
    - Look ONLY at marker B: event B.Added is called, and A.updated is called
    - Continue to look ONLY at marker B: event B.updated is called, and event A.updated is called

    [*] this is strange, isn't it? I would expect to see a A.Removed event in this case!
     
    luvcraft likes this.
  10. FrankvHoof

    FrankvHoof

    Joined:
    Nov 3, 2014
    Posts:
    258
    Personally I would expect to have A stop sending Updates. The marker isn't 'removed' from the world, so I wouldn't expect to see A.Removed. It merely went out of view. Updating an object that you cannot see does seem kind of 'impossible' to me though.

    The fact that A is still sending Updates even whilst out of view is completely down to what ARCore is doing within. ARFoundation has nothing to do with that. I'm guessing the Pose isn't changing, but the TrackingState might be?

    Consider an ARTrackable like a Multiplayer Object, and ARCore as the server.
    The Multiplayer Object isn't 'removed' or 'destroyed' just because it's no longer in your viewport. However, if ARCore cannot 'see' the object, it might not update it.
     
  11. bostonvaulter

    bostonvaulter

    Joined:
    Jan 14, 2021
    Posts:
    15
  12. FrankvHoof

    FrankvHoof

    Joined:
    Nov 3, 2014
    Posts:
    258
  13. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,836
    If the corresponding prefab is still visible on the screen, then obviously the position being reported by the tracker is in front of the camera. Checking that won't help.
     
    luvcraft likes this.
  14. FrankvHoof

    FrankvHoof

    Joined:
    Nov 3, 2014
    Posts:
    258
    @Antistone the position returned by ARFoundation is in WorldSpace.
    If the prefab is still on screen, this is due to one of two factors:
    - A bug in ARCore/ARKit, which is providing incorrect values for the Pose. Changing the version of the XRPlugin should resolve this.
    - Your Prefab is a 2D asset spawned on a ScreenSpace-Canvas. It is thus not using the Pose that it got from ARFoundation. That is not a bug in ARFoundation, but a mis-use of ARFoundation in your own code.
     
  15. jamestrue

    jamestrue

    Joined:
    Jan 25, 2017
    Posts:
    5
    Same issue with latest version of kit. Image tracker works but will remain on screen even when covering the camera completely. Addtionally, there is no way to turn on or off any settings to "persist"
     
  16. KyryloKuzyk

    KyryloKuzyk

    Joined:
    Nov 4, 2013
    Posts:
    1,143
    This is expected behavior. ARKit will change the ARTrackedImage.trackingState to Limited when the tracked image is covered or gets out of view.
     
  17. erinKoStudios

    erinKoStudios

    Joined:
    Oct 7, 2018
    Posts:
    3
    With Unity 2020.3, AR Foundation 4.1.7 and ARKit 4.1.7 trackable image prefabs are floating in screen space when trackingState switches to Limited. Aren't AR Foundation positions supposed to be in world space? So if tracking is lost the GameObject should stay where it was in world space, not float in front of the camera? Objects I've spawned on planes track perfectly, but the image trackable is just floating around. Shouldn't it know its world space position relative to all the other tracked objects?

    Another post suggests this is a bug in the version of ARKit? Is there a combination of Unity/package versions where this works properly? E.g. like Vuforia does out of the box? It's been pretty frustrating trying to do something that has just worked in Vuforia for the last decade with AR Foundation, so please any help is much appreciated! Thanks!

    EDIT: It feels like as soon as the trackingState becomes Limited, then the AR scale for the trackable image is wrong. Is there an easy way to re-parent a trackable after its spawned. E.g., to attach it to a plane (which is actually the wall the trackable image is on, but is more reliably tracked than the image for some reason!) It really feels like AR Foundation should be handling this automatically (similar to Vuforia's Extended Tracking).

    EDIT: One other thing, normally we hide the trackable on Limited tracking, but this is a wall sized image, and it seems to become limited if even a small fraction of the image is offscreen. I don't know if this is expected - Vuforia could handle a large section of the image being hidden. So maybe that it the real problem here...
     
    Last edited: Aug 4, 2021
    Brahe_ and Delcasda like this.
Thread Status:
Not open for further replies.