HI,
How to get current image target name and size in unity .
Please help me.
Hi,
I am new to vuforia, I tried this script but I getting below error
Attachment | Size |
---|---|
![]() | 195.25 KB |
Can you try this script, attaching it to the ARCamera ?
public class TargetLister : MonoBehaviour { // Use this for initialization void Start () { } // Update is called once per frame void Update () { StateManager sm = TrackerManager.Instance.GetStateManager(); IEnumerable<TrackableBehaviour> tbs = sm.GetActiveTrackableBehaviours(); foreach(TrackableBehaviour tb in tbs) { string name = tb.TrackableName; if (tb.GetType().Equals(TrackableType.IMAGE_TARGET)) { ImageTarget it = tb.Trackable as ImageTarget; Vector2 size = it.GetSize (); Debug.Log ("Active image target:" + name + " -size: " + size.x + ", " + size.y); } } } }
This works for me.
Hi,
I'm try putting my code in Update() method of DefaulTrackableEventHandler script.
and I get the same error.
what's wrong?
There is a private member variable named mTrackableBehaviour of DefaultTrackableeventHandler class.
i'm try using string name = mTrackableBehaviour.Trackable.Name; get the imagetarget name.
But I always obtain predefined image targte's name ,it's not the result I want.
Can you try putting your code in one of the esisting scripts of our samples, for instance in the DefaulTrackableEventHandler script that is attached to each trackable in the ImageTargets sample ?
just to see if you obtain th same error in that case...
Can you add this line at the beginning of your file:
using System.Collections.Generic;
?
hi AlessandroB,
Thanks for your help. but I still can not get the target name.
Follow is my code:
StateManagerImpl stateManager = (StateManagerImpl) TrackerManager.Instance.GetStateManager();
IEnumerable<TrackableBehaviour> trackableBehaviour = stateManager.GetActiveTrackableBehaviours();
string name = trackableBehaviour.Trackable.Name();
There is an error:
error CS1061: Type `System.Collections.Generic.IEnumerable<TrackableBehaviour>' does not contain a definition for `Trackable' and no extension method `Trackable' of type `System.Collections.Generic.IEnumerable<TrackableBehaviour>' could be found (are you missing a using directive or an assembly reference?)
I'm a newer.
what maybe the problem?
Hi,
in order to get the currently tracked targets, you can use the GetActiveTrackableBehaviours() method of the StateManager class, see API reference:
https://developer.vuforia.com/resources/api/unity/class_state_manager
Then, for a given trackable you can get the name using the Name() method of the Trackable class, see API reference:
https://developer.vuforia.com/resources/api/unity/interface_trackable
i.e. string name = trackable.Name();
If your trackable is an Image Target, then you can cast your trackable to an instance of ImageTarget and then can obtain its size using the GetSize() method of the ImageTarget class:
https://developer.vuforia.com/resources/api/unity/interface_trackable
This thread is very old (the last post before yours is dated2013) and it refers to an old version of Vuforia (2.x). The API has changed a little bit in newer versions; the TrackableType type no longer exists in Vuforia 3.x and 4.x.
In Vuforia 3.0 and 4.0, you can check if a Trackable is of a specific type by simply checking the class type of the Trackable (as in normal C# programming);
for example:
if (trackable is ImageTarget) ...