Log in or register to post comments

How to detect when an ImageTarget has been detected (activated) via code?

March 25, 2020 - 9:08pm #1

I find myself struggling on how to detect (via code) when specific image targets have been activated, or detected, or scanned, instantiated, whatever is the proper term for when the object is tracked to the image you have in your database. For example if I have 5 different image targets and I want to keep track of how many times each of them have been activated, how can I do this via code?

I know there is "OnTrackingFound" found in "DefaultTrackableEventHandler" however this is for all activated ImageTargets and does not take into account individual ones.

I dont believe there is such a function in the vuforia api so I think this will have to be achieved via some sort of bools in the code but I dont know how to do that either for the same reasons as the title, that I dont know how to detect if an image target has been activated. I cannot put some bool on the Start() method either since those just activate on application launch anyway and not when they are spawned via imageTarget recognition.

How to detect when an ImageTarget has been detected (activated) via code?

March 26, 2020 - 5:11pm #5

Oh I see it now, I didnt even realize that was even there. Thank you very much!

How to detect when an ImageTarget has been detected (activated) via code?

March 26, 2020 - 4:52am #4

You can drop the script on any GameObject, maybe you create a new one.

Then you add in each image target a new event, drag your GameObject inside, select the script and function and give it a number (in your case from 0 to 4, you have to extend the switch statement of course) (see picture attached)

 

AttachmentSize
Image icon snip.PNG21.42 KB

How to detect when an ImageTarget has been detected (activated) via code?

March 26, 2020 - 1:50am #3

@sebben thanks for the quick answer but could you please explain what "call it from OnTargetFound of each Image Target" means? Do I have to put individual scripts on them the ImageTarget or are you talking about the image target behavior in which case I dont know how to access that via script.

How to detect when an ImageTarget has been detected (activated) via code?

March 25, 2020 - 11:18pm #2

Hi,

you could write a script like this:

int a;
int b;

public void count(int imageTargetNumber)

    {
        switch (imageTargetNumber) {
            case 0:
                a++;
                Debug.Log(a);
                break;
            case 1:
                b++;
                Debug.Log(b);
                break;
        }
    }

and call it from OnTargetFound of each Image Target.

I hope that helps.

Log in or register to post comments