Search Unity

Bug Image TrackingState stay in TrackingState.Tracking even if the image is no longer visible

Discussion in 'AR' started by fbergonzinigames, Jul 25, 2022.

  1. fbergonzinigames

    fbergonzinigames

    Joined:
    Apr 3, 2020
    Posts:
    12
    Good evening, I am writing because I think I have found a bug which consists in the fact that the traking state of an trakingimage, in certain circumstances, remains in traking even if the image is no longer visible.

    I recreated the problem using a video. I used the AR foundation sample and made some minor tweaks to make the problem more evident.

    Code (CSharp):
    1. void UpdateInfo(ARTrackedImage trackedImage)
    2.         {
    3.             // Set canvas camera
    4.             var canvas = trackedImage.GetComponentInChildren<Canvas>();
    5.             canvas.worldCamera = worldSpaceCanvasCamera;
    6.        
    7.             //CHANGE
    8.             canvas.enabled = true;
    9.             // Update information about the tracked image
    10.             var text = canvas.GetComponentInChildren<Text>();
    11.             text.text = string.Format(
    12.                 "{0}\ntrackingState: {1}\nGUID: {2}\nReference size: {3} cm\nDetected size: {4} cm",
    13.                 trackedImage.referenceImage.name,
    14.                 trackedImage.trackingState,
    15.                 trackedImage.referenceImage.guid,
    16.                 trackedImage.referenceImage.size * 100f,
    17.                 trackedImage.size * 100f);
    18.             var planeParentGo = trackedImage.transform.GetChild(0).gameObject;
    19.             var planeGo = planeParentGo.transform.GetChild(0).gameObject;
    20.             // CHANGE
    21.             if (trackedImage.trackingState == TrackingState.Tracking)
    22.             {
    23.                 planeGo.SetActive(true);
    24.                 // The image extents is only valid when the image is being tracked
    25.                 trackedImage.transform.localScale = new Vector3(trackedImage.size.x, 1f, trackedImage.size.y);
    26.                 // Set the texture
    27.                 var material = planeGo.GetComponentInChildren<MeshRenderer>().material;
    28.                 material.mainTexture = (trackedImage.referenceImage.texture == null) ? defaultTexture : trackedImage.referenceImage.texture;
    29.             }
    30.             else
    31.             {
    32.                 planeGo.SetActive(false);
    33.                 canvas.enabled = false;
    34.             }
    35.         }



    As shown in the video, when I frame an image and switch to the next one, for some reason the traking state of the first image remains in traking when it should go into limited since the image is no longer visible.

    This problem occurs when two images of the same size overlap quickly.
     
  2. KyryloKuzyk

    KyryloKuzyk

    Joined:
    Nov 4, 2013
    Posts:
    1,144
  3. fbergonzinigames

    fbergonzinigames

    Joined:
    Apr 3, 2020
    Posts:
    12
  4. andyb-unity

    andyb-unity

    Unity Technologies

    Joined:
    Feb 10, 2022
    Posts:
    1,062
    The behavior of ARCore and ARKit cannot be overridden. You could request a feature change to Google and/or Apple, respectively.

    The best way to determine if the image is visible is to calculate whether your point of interest is in the Camera's view frustum. You might be able to use
    Renderer.isVisible
    to accomplish this: https://docs.unity3d.com/ScriptReference/Renderer-isVisible.html
     
    KyryloKuzyk and fbergonzinigames like this.
  5. fbergonzinigames

    fbergonzinigames

    Joined:
    Apr 3, 2020
    Posts:
    12
    Thank you, that is what i needed.
     
    Last edited: Jul 27, 2022