Log in or register to post comments

how to automatic restart scanning cloud recognition

July 6, 2019 - 8:53am #1

hello

 

how to create a cloud handler script can automatically restart scanning when the target is lost? because on the cloud handler script to restart scanning must press the button restart scanning.

 

</p>
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Vuforia;

public class CloudHandler : MonoBehaviour, IObjectRecoEventHandler
{

    private CloudRecoBehaviour mCloudRecoBehaviour;
    private bool mIsScanning = false;
    public static string mTargetMetadata;
    public ImageTargetBehaviour ImageTargetTemplate;
    // Use this for initialization
    void Start()
    {
       
        // register this event handler at the cloud reco behaviour
        mCloudRecoBehaviour = GetComponent<CloudRecoBehaviour>();

        if (mCloudRecoBehaviour)
        {
            mCloudRecoBehaviour.RegisterEventHandler(this);
        }
    }

    public void OnInitialized(TargetFinder targetFinder)
    {
        Debug.Log("Cloud Reco initialized");
    }

    public void OnInitError(TargetFinder.InitState initError)
    {
        Debug.Log("Cloud Reco Init Error" + initError.ToString());
    }

    public void OnUpdateError(TargetFinder.UpdateState updateError)
    {
        Debug.Log("Cloud Reco Update Error" + updateError.ToString());
    }

    public void OnStateChanged(bool scanning)
    {
        mIsScanning = scanning;
        if (scanning)
        {
            // clear all known trackables
            var tracker = TrackerManager.Instance.GetTracker<ObjectTracker>();
            tracker.TargetFinder.ClearTrackables(false);
        }
    }

    // Here we handle a cloud target recognition event
    public void OnNewSearchResult(TargetFinder.TargetSearchResult targetSearchResult)
    {
        TargetFinder.CloudRecoSearchResult cloudRecoSearchResult =
            (TargetFinder.CloudRecoSearchResult)targetSearchResult;
        // do something with the target metadata
        mTargetMetadata = cloudRecoSearchResult.MetaData;
        // stop the target finder (i.e. stop scanning the cloud)
        mCloudRecoBehaviour.CloudRecoEnabled = false;

        if (ImageTargetTemplate)
        {
            // enable the new result with the same ImageTargetBehaviour:
            ObjectTracker tracker = TrackerManager.Instance.GetTracker<ObjectTracker>();
            ImageTargetBehaviour imageTargetBehaviour =
             (ImageTargetBehaviour)tracker.TargetFinder.EnableTracking(
             targetSearchResult, ImageTargetTemplate.gameObject);
        }
    }

    void OnGUI()
    {
        // so that user can restart cloud scanning
        if (!mIsScanning)
        {
            // Display metadata of latest detected cloud-target
            GUI.Box(new Rect(100, 200, 200, 50), mTargetMetadata);
            if (GUI.Button(new Rect(100, 300, 200, 50), "Restart Scanning"))
             {
                // Restart TargetFinder
                mCloudRecoBehaviour.CloudRecoEnabled = true;
             }
        }
    }
}

<p>

how to automatic restart scanning cloud recognition

March 23, 2020 - 7:42am #3

Hi,

If I'm not mistaken in the Unity Core Samples, the cloud reco is starting automatically once the target is lost.

Please review our Cloud Reco scene.

Thank you.

Vuforia Engine Support

how to automatic restart scanning cloud recognition

March 18, 2020 - 9:50pm #2

Any luck?

Log in or register to post comments