Topic locked

Cloud Recognition Vuforia Not Scanning

Unity Editor
July 4, 2022 - 11:53pm #1

Hello,

I am trying to scan my Image Targets uploaded on the Vuforia Cloud Storage. I am loading my assetbundles from a JSON file which are present on the Google Drive. But whenever I build the app, it doesn't scan the Image target. However the same code was working few weeks back now I need to add some more features but unfortunately I am not able to perform scanning.

SimpleCloudRecoEventHandler.cs

<pre class="brush: csharp">

using UnityEngine;

using Vuforia;

using System.Collections;

using System.Collections.Generic;

using UnityEngine.Networking;

using UnityEngine.UI;

using SimpleJSON;

public class SimpleCloudRecoEventHandler: MonoBehaviour {

    private CloudRecoBehaviour mCloudRecoBehaviour;

    private bool mIsScanning = false;

    private string mTargetMetadata = "";

    public string mTargetId = "";

    public ImageTargetBehaviour ImageTargetTemplate;

    // Register cloud reco callbacks

    void Awake() {

        mCloudRecoBehaviour = GetComponent < CloudRecoBehaviour > ();

        mCloudRecoBehaviour.RegisterOnInitializedEventHandler(OnInitialized);

        mCloudRecoBehaviour.RegisterOnInitErrorEventHandler(OnInitError);

        mCloudRecoBehaviour.RegisterOnUpdateErrorEventHandler(OnUpdateError);

        mCloudRecoBehaviour.RegisterOnStateChangedEventHandler(OnStateChanged);

        mCloudRecoBehaviour.RegisterOnNewSearchResultEventHandler(OnNewSearchResult);

    }

    //Unregister cloud reco callbacks when the handler is destroyed

    void OnDestroy() {

        mCloudRecoBehaviour.UnregisterOnInitializedEventHandler(OnInitialized);

        mCloudRecoBehaviour.UnregisterOnInitErrorEventHandler(OnInitError);

        mCloudRecoBehaviour.UnregisterOnUpdateErrorEventHandler(OnUpdateError);

        mCloudRecoBehaviour.UnregisterOnStateChangedEventHandler(OnStateChanged);

        mCloudRecoBehaviour.UnregisterOnNewSearchResultEventHandler(OnNewSearchResult);

    }

    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.GetTargetFinder < ImageTargetFinder > ().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;

        // Unique target id

        mTargetId = targetSearchResult.UniqueTargetId;

        // stop the target finder (i.e. stop scanning the cloud)

        mCloudRecoBehaviour.CloudRecoEnabled = false;

        // Build augmentation based on target

        if (ImageTargetTemplate) {

            // enable the new result with the same ImageTargetBehaviour:

            ObjectTracker tracker = TrackerManager.Instance.GetTracker < ObjectTracker > ();

            tracker.GetTargetFinder < ImageTargetFinder > ().EnableTracking(targetSearchResult, ImageTargetTemplate.gameObject);

        }

    }

    void OnGUI() {

        // Display current 'scanning' status

        GUI.Box(new Rect(100, 100, 200, 50), mIsScanning ? "Scanning" : "Not scanning");

        // Display metadata of latest detected cloud-target

        //GUI.Box(new Rect(100, 200, 200, 50), "Target ID: " + mTargetId);

        // If not scanning, show button

        // so that user can restart cloud scanning

        if (!mIsScanning) {

            if (GUI.Button(new Rect(600, 2200, 250, 100), "Scan Another ARt")) {

                // Restart TargetFinder

                mCloudRecoBehaviour.CloudRecoEnabled = true;

            }

        }

    }

}

</pre>

Platform: 
Topic locked