Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

ARFoundation 2 image tracking with many ref images and many objects

Discussion in 'AR' started by SpiderJones, May 18, 2019.

Thread Status:
Not open for further replies.
  1. Alexis-Dev

    Alexis-Dev

    Joined:
    Apr 16, 2019
    Posts:
    121
    Hi,
    The TrackingState need to be in :

    Code (CSharp):
    1.  
    2. foreach (ARTrackedImage updatedImage in eventArgs.updated)
    3.         {
    4.             if(updatedImage.trackingState == UnityEngine.XR.ARSubsystems.TrackingState.Tracking)
    5.             {
    6.                 // The image is track!
    7.             }
    8.             else if(updatedImage.trackingState == UnityEngine.XR.ARSubsystems.TrackingState.Limited)
    9.             {
    10.                // Tracking is limited, so the image isn't track but the device try to keep position and rotation with sensor. put destroy function here
    11.             }
    12.             else
    13.             {
    14.                 // Tracking is none, but if I remember it's never called (put destroy function here)
    15.             }
    16.         }
    17.  
    I hope that help you!

    Best,
    Alexis
     
  2. Alexis-Dev

    Alexis-Dev

    Joined:
    Apr 16, 2019
    Posts:
    121
    Can you show me your code?
     
  3. xadvy

    xadvy

    Joined:
    Feb 6, 2019
    Posts:
    2
    Hey fabisfab,

    I think you just forgot to use the same variable to access the
    .trackingstate
    in the other if()-statements above. Instead of
    trackedObject.trackingState
    try
    updatedImage.trackingState
    . If you look closely at the code @Alexis-Dev postet, you can see, that he used
    updatedImage
    as well.
    And for the Debug.Log() you just need to set a semicolon at the end of the line.

    Another valuable tip for anyone having trouble with the images not being detected: check if the filename-extension for the images you load in your ReferenceImageLibrary is ".jpg"! not .JPG, not .jepg, only .jpg.

    Hope this helps :)
     
    Alexis-Dev likes this.
  4. Alexis-Dev

    Alexis-Dev

    Joined:
    Apr 16, 2019
    Posts:
    121
  5. Alexis-Dev

    Alexis-Dev

    Joined:
    Apr 16, 2019
    Posts:
    121
    The eventArgs.removed isn't call when the image isn't track. It's used for an other purpose.

    Te destroy your prefab when your image isn't track change the functions : UpdateLimitedGameObject and UpdateNoneGameObject by DestroyGameObject
     
  6. Alexis-Dev

    Alexis-Dev

    Joined:
    Apr 16, 2019
    Posts:
    121
    You need to instantiate it in UpdateTrackingGameObject.

    Check if it's instantiate, if yes: Update the position and rotation of the prefab, if not: Instantiate it.
     
  7. Alexis-Dev

    Alexis-Dev

    Joined:
    Apr 16, 2019
    Posts:
    121
    hum, I think there a problem.

    Do you Enable and Disable the prefab on tracking/untracking? Or do you Instantiate and Destroy on tracking/untracking?
     
  8. Alexis-Dev

    Alexis-Dev

    Joined:
    Apr 16, 2019
    Posts:
    121
    Ok,

    I'm little confuse because I'm not using multitracking like that actually...

    Go back to:
    Code (CSharp):
    1. foreach (ARTrackedImage updatedImage in eventArgs.updated)
    2.         {
    3.             if(updatedImage.trackingState == UnityEngine.XR.ARSubsystems.TrackingState.Tracking)
    4.             {
    5.                 UpdateTrackingGameObject(updatedImage);
    6.             }
    7.             else if(updatedImage.trackingState == UnityEngine.XR.ARSubsystems.TrackingState.Limited)
    8.             {
    9.                UpdateLimitedGameObject(updatedImage);
    10.             }
    11.             else
    12.             {
    13.                 UpdateNoneGameObject(updatedImage);
    14.             }
    15.         }
    On the prefabs will appear/disappear, add this component and check Destroy On Removal:

    upload_2021-2-1_9-13-37.png
     
  9. FrankvHoof

    FrankvHoof

    Joined:
    Nov 3, 2014
    Posts:
    233
    @Alexis-Dev
    The tracking-state refers to the 'accuracy' of the object that is being tracked:
    Tracking: the device is actively tracking this object and updating it
    Limited: the device is 'having a hard time' finding/tracking this object. Accuracy might be low, or updates might occur less frequently or not at all
    None: the object was found and added, but is not (currently) being updated.

    With regards to added/updated/removed:
    Added: This object was newly discovered
    Updated: The object 'changed'. This can be because it moved, because its location (Pose) became 'more accurate', because its trackingstate changed, etc.
    Removed: The object was 'destroyed'. This can happen if for example the pool of objects is full and old objects are being recycled. The implementation is provider-specific.

    The definitions above can be applied to each Trackable in ARFoundation. For implementation-specific details you should check the documentation for the underlying XR Plugin (e.g. ARCore, ARKit)
     
  10. jeremiahboac

    jeremiahboac

    Joined:
    Aug 9, 2019
    Posts:
    3
    Hello sir! I tried to upload my AR Foundation app on Google Play but only flagship phones can search it, but your application can search using my mid-range phone. Any tips? Thanks
     
  11. SpiderJones

    SpiderJones

    Joined:
    Mar 29, 2014
    Posts:
    198
    I don't know why that is happening. I suggest asking here -> https://github.com/Unity-Technologies/arfoundation-samples/issues
     
  12. Bduinat

    Bduinat

    Joined:
    Nov 26, 2018
    Posts:
    17
    Hi,

    The multiImageTracker works find for me on Android, Using Destroy On removal on my prefab, everything is smooth.
    I've got a problem on iOS, exaclty same setting, but the prefab I display on the marker is flickering, looks like it's loosing tracking all the time. Anyone got this problem or a solution to it ?
     
  13. marcosdana

    marcosdana

    Joined:
    Mar 18, 2019
    Posts:
    4
    Hi!
    I have a problem related to image tracking. When I get too close to the Prefab that is being tracked, even if I still see the image with my phone camera, I completely lose track. Any light on this?
     
  14. dungpham12399

    dungpham12399

    Joined:
    Aug 10, 2021
    Posts:
    11
    Hi, i'm trying make app can switch multi prefab with one image target by button next and button back.Who can help me? thank you
     
  15. Lemmy1234

    Lemmy1234

    Joined:
    Oct 24, 2021
    Posts:
    1
    Hello,

    Just wanting to ask if trackedImage.transform.position always returns (0.0, 0.0, 0.0).
    I managed to spawn 2 different gameobjects for different markers. However I thought that I would get different positions for the gameobject, since the markers are at least 1 meter apart from each other

    Code (CSharp):
    1.    
    2. private void OnTrackedImagesChanged(ARTrackedImagesChangedEventArgs eventArgs)
    3.     {
    4.         var IDAndPrefab = s_ImageGUIDList.Zip(SpawnedObjects, (id, spawnObject) => new { id, spawnObject });
    5.        
    6.         eventArgs.added.ForEach(trackedImage =>
    7.         {
    8.             foreach (var obj in IDAndPrefab)
    9.             {
    10.                 if (trackedImage.referenceImage.guid == obj.id)
    11.                 {
    12.                     GameObject o = Instantiate(obj.spawnObject, trackedImage.transform);
    13.                     debug.text += "position of " +  o.name + " is " + trackedImage.transform.position +"\n"
    14.                 }
    15.             }
    16.         });
    17.     }
    output I get is:
    position of fridge is (0.0, 0.0, 0.0)
    position of washer is (0.0, 0.0, 0.0)
     
Thread Status:
Not open for further replies.