Log in or register to post comments

Tracking two or more images

November 4, 2019 - 8:09am #1

Hi, wondering if someone can help me out with a simple AR app. I have Unity version 2019.2.11 (latest).

I have created a database and added two target images with 5 star ratings. I successfully created one target image with a video inside a quad. I used the following script (sorry ignore the p tags) to play the video when the image is targeted, and paused when the camera is off the image. For some reason I can't target two images with the same or different video. When targeting the first image, the video with audio plays until I scan the second image which has no video but just a white screen where the video should be. When I go back to the first image, the video seems to be playing because there is audio but the screen is black. Max Simultaneous Tracked Images and Objects are set to 2. It seems to work in Unity editor but not on my Samsung tablet with Android 7.0 installed. Any suggestions would be appreciated!

 

/*==============================================================================</p>
<p>Copyright (c) 2017 PTC Inc. All Rights Reserved.</p>
<p>Copyright (c) 2010-2014 Qualcomm Connected Experiences, Inc.</p>
<p>All Rights Reserved.</p>
<p>Confidential and Proprietary - Protected under copyright and other laws.</p>
<p>==============================================================================*/</p>
<p>using UnityEngine;</p>
<p>using Vuforia;</p>
<p>using UnityEngine.Video;      //added</p>
<p>/// <summary></p>
<p>///     A custom handler that implements the ITrackableEventHandler interface.</p>
<p>/// </summary></p>
<p>public class DefaultTrackableEventHandler : MonoBehaviour, ITrackableEventHandler</p>
<p>{</p>
<p>    #region PRIVATE_MEMBER_VARIABLES</p>
<p>    protected TrackableBehaviour mTrackableBehaviour;</p>
<p>    #endregion // PRIVATE_MEMBER_VARIABLES</p>
<p>    #region UNTIY_MONOBEHAVIOUR_METHODS</p>
<p>    protected virtual void Start()</p>
<p>    {</p>
<p>        mTrackableBehaviour = GetComponent<TrackableBehaviour>();</p>
<p>        if (mTrackableBehaviour)</p>
<p>            mTrackableBehaviour.RegisterTrackableEventHandler(this);</p>
<p>    }</p>
<p>    #endregion // UNTIY_MONOBEHAVIOUR_METHODS</p>
<p>    #region PUBLIC_METHODS</p>
<p>    /// <summary></p>
<p>    ///     Implementation of the ITrackableEventHandler function called when the</p>
<p>    ///     tracking state changes.</p>
<p>    /// </summary></p>
<p>    public void OnTrackableStateChanged(</p>
<p>        TrackableBehaviour.Status previousStatus,</p>
<p>        TrackableBehaviour.Status newStatus)</p>
<p>    {</p>
<p>        if (newStatus == TrackableBehaviour.Status.DETECTED ||</p>
<p>            newStatus == TrackableBehaviour.Status.TRACKED ||</p>
<p>            newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED)</p>
<p>        {</p>
<p>            Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " found");</p>
<p>            OnTrackingFound();</p>
<p>        }</p>
<p>        else if (previousStatus == TrackableBehaviour.Status.TRACKED &&</p>
<p>                 newStatus == TrackableBehaviour.Status.NO_POSE)</p>
<p>        {</p>
<p>            Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " lost");</p>
<p>            OnTrackingLost();</p>
<p>        }</p>
<p>        else</p>
<p>        {</p>
<p>            // For combo of previousStatus=UNKNOWN + newStatus=UNKNOWN|NOT_FOUND</p>
<p>            // Vuforia is starting, but tracking has not been lost or found yet</p>
<p>            // Call OnTrackingLost() to hide the augmentations</p>
<p>            OnTrackingLost();</p>
<p>        }</p>
<p>    }</p>
<p>    #endregion // PUBLIC_METHODS</p>
<p>    #region PRIVATE_METHODS</p>
<p>    protected virtual void OnTrackingFound()</p>
<p>    {</p>
<p>        var rendererComponents = GetComponentsInChildren<Renderer>(true);</p>
<p>        var colliderComponents = GetComponentsInChildren<Collider>(true);</p>
<p>        var canvasComponents = GetComponentsInChildren<Canvas>(true);</p>
<p>        foreach (var component in rendererComponents)</p>
<p>            component.enabled = true;</p>
<p>        // Enable colliders:</p>
<p>        foreach (var component in colliderComponents)</p>
<p>            component.enabled = true;</p>
<p>        // Enable canvas':</p>
<p>        foreach (var component in canvasComponents)</p>
<p>            component.enabled = true;</p>
<p>        // added</p>
<p>        if (mTrackableBehaviour.gameObject.GetComponentInChildren<VideoPlayer>() != null)</p>
<p>        {</p>
<p>            mTrackableBehaviour.gameObject.GetComponentInChildren<VideoPlayer>().Play();</p>
<p>        }</p>
<p>    }</p>
<p>    protected virtual void OnTrackingLost()</p>
<p>    {</p>
<p>        var rendererComponents = GetComponentsInChildren<Renderer>(true);</p>
<p>        var colliderComponents = GetComponentsInChildren<Collider>(true);</p>
<p>        var canvasComponents = GetComponentsInChildren<Canvas>(true);</p>
<p>        // Disable rendering:</p>
<p>        foreach (var component in rendererComponents)</p>
<p>            component.enabled = false;</p>
<p>        // Disable colliders:</p>
<p>        foreach (var component in colliderComponents)</p>
<p>            component.enabled = false;</p>
<p>        // Disable canvas':</p>
<p>        foreach (var component in canvasComponents)</p>
<p>            component.enabled = false;</p>
<p>        // added</p>
<p>        if (mTrackableBehaviour.gameObject.GetComponentInChildren<VideoPlayer>() != null)</p>
<p>        {</p>
<p>            mTrackableBehaviour.gameObject.GetComponentInChildren<VideoPlayer>().Pause();</p>
<p>        }</p>
<p>    }</p>
<p>    #endregion // PRIVATE_METHODS</p>
<p>}</p>
<p>

 

Tracking two or more images

November 6, 2019 - 2:10am #4

Hi @omnitree,

The AR camera placement in the scene should not affect the targets detection.

Could you please elaborate on the moving part? Do you have animations with the augmentations?

Thank you.

Vuforia Engine Support

 

Tracking two or more images

November 6, 2019 - 1:58am #3

Hi @9metis,

Vuforia currently does not support the ability to track multiple instances of the same Image Target. This is a common feature request that is under evaluation by our product team.

There are a lot dependencies in your scenario that could affected the behavior. Bare with me :). First I would like to confirm that we support detection of multiple distinct image targets/vumarks/objects.

If you detect one by one the targets and the targets are never in the same camera pov,  the behavior is expected. Once you move the pov from the target, tracking is lost and audio will stop.

In order to address this you could activate Extended Tracking/Device Tracker. Documentation on how to below:  https://library.vuforia.com/content/vuforia-library/en/articles/Solution/Configuring-Rotational-Tracking-in-Unity.html

 The Device Tracker provides information about where the device is relative to the world, meaning you are able to track targets past the camera pov once detected.

Please give it a try and let me know.

Thank you.

Vuforia Engine Support

 

Tracking two or more images

November 4, 2019 - 5:22pm #2

I have a similar problem:

I just have two images (cards), each has one 3d model attached to it (two trees: oak and pine).

If I have only one Image on the scene (with World Center Mode: Device), once I press play everything works fine.

If I add second image to the scene then:

1. with WORLD CENTER MODE: DEVICE

 It doesn't work for neither of the images; the 3d models appear only if I place the camera behind them in the scene (if the camera in the scene is directed somewhere else, nothing will appear) and they don't stick to the cards. They just pop up once I put a specific card in front of the camera, but then they dont move (fully static)

2. with WORLD CENTER MODE: FIRST TARGET

the first identified image works properly (3d model appears and it "sticks" to the card), but when I show the 2nd image to the camera the second 3d model appears not on a card but in the fixed position relating to the first card (the same distance to the 1st model as it is situated in the scene)

How can I make those two images work properly and separately?

Thanks!

 

Log in or register to post comments