Log in or register to post comments

Determine number of current tracked targets

September 27, 2013 - 2:27pm #1

Hello-

This is probably less of a "can i" question and more of specifically "how to." My coding skills aren't that strong.

I'm trying to activate an info screen when Vuforia can't find any targets. I know how to do this per ImageTarget (via DefaultTrackableEventHandler). However, I have 5 targets in my scene which may or may not be tracked simultaneously. So I basically I need ot know when there are no targets being tracked.

I've traced this to the function getNumTrackableResults () but I can't figure out how to use it. 

Any sample code or help would be appreciated, particularly specifically how to get this value inside DefaultTrackableEventHandler.cs. I'd fire my info screen when the number of Trackable Results = 0.

Thanks!

Determine number of current tracked targets

July 13, 2016 - 5:29pm #14

Including all of the following removed the errors I was getting:

using UnityEngine;
using Vuforia;
using System.Collections.Generic;

Determine number of current tracked targets

May 28, 2014 - 10:24am #13

I have update my project today to the last version and  now the next code

 

trackableStateMng = TrackerManager.Instance.GetStateManager ();
    
 IEnumerable<TrackableBehaviouractiveTrackables = trackableStateMng.GetActiveTrackableBehaviours ();

 

do not work any more, activeTrackables is always empty even when the OnTrackableFound() is called.

 

 

Any idea or solution??

 

Thank you

Determine number of current tracked targets

October 4, 2013 - 8:51am #12
Here is how I have done in my side, it seems working :
 
StateManager sm = TrackerManager.Instance.GetStateManager();

IList<TrackableBehaviour> activeTrackables = (IList<TrackableBehaviour>) sm.GetActiveTrackableBehaviours();

if(activeTrackables.Count==0)
{
     //CURRENTLY NOT TRACKING
}
else
{
     //CURRENTLY IN TRACKING
}

 

(In fact, I use the Alessandro solution, but I use TrackableBehaviour instead of TrackableResult  )

Determine number of current tracked targets

October 3, 2013 - 7:05pm #11

I have yet to get the built-in active trackables code working, but I did create a workaround:

Bascially I created a list of DefaultTrackableEventHandler scripts. When a particular instance acquires a taget, it gets added. When it loses it, it gets removed. When the list length is 0, I know nothing is being tracked, so I can show my info screen. It's redundant since Vuforia is already doing that internally, but works for my needs.

 

Determine number of current tracked targets

October 3, 2013 - 8:59am #10

Re-imported Vuforia, then added the lines of code back, and same error....

Determine number of current tracked targets

October 3, 2013 - 8:23am #9

Verified on all three. 

I don't think I've modified any other code, but where does TrackableResult come from? Should I verify something in another script?

I'll also try re-importing Vuforia just to make sure.

Determine number of current tracked targets

October 3, 2013 - 12:54am #8

Just to summarize, verify that:

  • you have these statements:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
  • that your class extends MonoBehaviour
  • that you don't have any other errors in your Project, as sometimes this error could a consequence of other errors in other scripts

 

 

Determine number of current tracked targets

October 2, 2013 - 11:12am #7

Sure did. I apologize that i don't have a better grasp of what's going on...not sure how to troubleshoot this.

Determine number of current tracked targets

October 2, 2013 - 10:43am #6

Did you also add 

using UnityEngine;

?

That's all you need normally.

 

Determine number of current tracked targets

October 2, 2013 - 8:59am #5

Thanks! That fixed that error.

Now I have this one: The type or namespace name `TrackableResult' could not be found. Are you missing a using directive or an assembly reference?

Any thoughts?

Determine number of current tracked targets

October 2, 2013 - 12:04am #4

You should be able to fix this error by adding this statement at the top of the script:

using System.Collections.Generic;

 

 

Determine number of current tracked targets

October 1, 2013 - 4:41pm #3

So this is what I have inside the OnTrackingLost function of DefaultTrackableEventHandler:

	StateManager sm = TrackerManager.Instance.GetStateManager();
	IEnumerable<TrackableResult> activeTrackables = sm.GetActiveTrackableResults();
		
	if (defaultText && activeTrackables==0) defaultText.SetIsOut(true);

And I get the error: The type or namespace name `IEnumerable`1' could not be found. Are you missing a using directive or an assembly reference?

Do I need an include or using line? Any ideas?

dp

Determine number of current tracked targets

September 29, 2013 - 1:21am #2

You can achieve that by retrieving the number of trackable behaviours (in Unity), using the State Manager API:

StateManager sm = TrackerManager.Instance.GetStateManager();

IEnumerable<TrackableResult> activeTrackables = sm.GetActiveTrackableResults();

Then if the number of activeTrackables (i.e. the number of targets currently being tracked) is zero, you will known that there are no targets tracked in your view.

 

Log in or register to post comments