Search Unity

Help Wanted Get detected image marker(s) name and detection strength

Discussion in 'Unity MARS' started by Raptcha911, Sep 30, 2021.

  1. Raptcha911

    Raptcha911

    Joined:
    Sep 19, 2014
    Posts:
    19
    Hello,

    I have a few image markers in my app and I need help finding the name of the detected image(s). I was not able to find it that easily in the C# API.

    Also, when multiple markers are detected, I want to select the most stable one that is tracked, so that I can place my object on it.

    Any help would be really appreciated.

    Thank you.
     
  2. CiaranWills

    CiaranWills

    Unity Technologies

    Joined:
    Apr 24, 2020
    Posts:
    84
    Unfortunately we don't get any quality information from the underlying system (AR Foundation) other than the tracking state being tracking or limited. You can use a condition on the proxy to filter out limited, which depending on the platform may or may not be helpful.

    By the name do you mean the name of the image asset? You can also set a label on each image in the MARS Marker Library. If you have the MarkerGuid for the image you should be able to get the marker library from the MARS Session and find the matching marker definition.
     
  3. Raptcha911

    Raptcha911

    Joined:
    Sep 19, 2014
    Posts:
    19
    I see. That should still be fine. I have another question in relation to this. If I have, say 5 different markers in the scene. Once all of them are acquired, is there a way to determine which of the 5 markers are currently being tracked? (Will the tracking state be 'UNKNOWN' for the markers that are currently out of the camera view)

    I do have the label property set for each of the image in the library, but I see the GUID only on the proxy itself. Can I not get the Label property directly from the QueryResult?
     
    Last edited: Oct 1, 2021
  4. CiaranWills

    CiaranWills

    Unity Technologies

    Joined:
    Apr 24, 2020
    Posts:
    84
    Unfortunately what happens when a marker goes out of view is platform dependent. If I recall ARCore will keep reporting it's estimated world position but with tracking state limited, but ARKit stops updating altogether. You may need to test on your platform to find what works for you; we're looking at ways to make this a more consistent experience.

    For the marker names, here's an example that gets the label given a QueryResult:
    Code (CSharp):
    1.  
    2. using Unity.MARS;
    3. using Unity.MARS.Data;
    4. using Unity.MARS.Query;
    5. using UnityEngine;
    6.  
    7. public class MarkerTest : MonoBehaviour, IUsesMARSTrackableData<MRMarker>
    8. {
    9.     Proxy m_Proxy;
    10.  
    11.     void Start()
    12.     {
    13.         m_Proxy = GetComponent<Proxy>();
    14.     }
    15.  
    16.     void Update()
    17.     {
    18.         var data = m_Proxy.currentData;
    19.         if (data != null)
    20.             Debug.Log(MarkerFromQueryResult(data));
    21.     }
    22.  
    23.     string MarkerFromQueryResult(QueryResult result)
    24.     {
    25.         var marker = result.ResolveValue<MRMarker>(this);
    26.         foreach (var markerDefinition in MARSSession.Instance.MarkerLibrary)
    27.         {
    28.             if (markerDefinition.MarkerId == marker.markerId)
    29.                 return markerDefinition.Label;
    30.         }
    31.         return null;
    32.     }
    33. }
    34.  
     
unityunity