Start a new topic

How to get Image Target metadata in Unity?

Hi
By subscribing to OnImageRecognised I'm able to get ImageTarget.name and ID.
When I create an image target I can add meta data in a json file. But I can't figure out how to retrieve it in Unity.


This is my function that gets called by OnImageRecognised and the code that's there works just fine. I thought I would be able to get the meta data by doing something like
"target.metada"

 public void OnImageTargetFound(ImageTarget target)
    {
        myText.text = "Image target found: " + target.Name + ", ID: " + target.ID;
    }

 All I want to achieve for now, is to get an ID for the image target, that isn't a string and doesn't change upon each recognition. I assume that is necessary to efficiently distringuish between hundreds of targets during runtime.

I'm using Wikitude 9.0.0 and Unity 2019.2.5f.


Hi Aske,


did you add custom metadata in the json file? The necessary metadata is already accessible like in the example below for 9.0 Professional Edition:

        public void OnImageTargetFound(ImageTarget target)
        {
            myText.text = "Image target found: " + target.Name + ", ID: " + target.ID
            myText.text += ", Height: " + target.PhysicalTargetHeight;
            myText.text += ", Scale: " + target.Scale;
            // There are also helper methods like this.
            myText.text += ", Distance to target: " + target.ComputeCameraDistanceToTarget();
        }


In Expert Edition you have additional data for cylindrical targets. Nothing else is parsed beside these attributes.


But to return to your initial goal, the ID you get for the target is already unique for each detected target. To distinguish just between the target itself, you could use its name.

Kind regards,
Gökhan

Hi Gökhan


Thank you for your response.


I have made it work using the name. I just thought it would be better to use integer IDs.
In your example you use variables and methods already in image target class.

I thought I could define variables in the json file and then reach them through my scripts. But I don't see from your answer how that could be achieved. I have limited experience with json so I might be missing something obvious here.

Now I did try to insert data at an image target, however I don't know the syntax and couldn't easily find it.
Given that I have made it work without meta data, I wouldn't spend more time on it.
If you're willing to try and explain it to me again I'd appreciate it because I'm curious about and would probably need it in the future.


Best regards
Aske

Hi Aske,


Importing custom data from the json file into the image target object is not possible as explained. Only the variables needed for the image target(s) are extracted from the file. 

However, to read out custom data added to the json file, you could simply use JsonUtility from Unity in the SDK professional edition or the LitJson library included in the expert edition (which you can access through the Wikitude.LitJson namespace).


Kind regards,

Gökhan

Login or Signup to post a comment