Topic locked

Please explain step by step how to use Vuforia Cloud!

December 14, 2012 - 7:05am #1

Hello, Please explain step by step how to use Vuforia Cloud! I downloaded the example, but still did not understand, I can not figure out how to make that recognition of my work with the target cloud (. I did everything as in the example cloudrecognition-2-0-6, but still there are a lot of places are not clear for the beginner and nowhere in the documentation I could not find anything about the difficulties I encountered (Example cloudrecognition-2-0-6, there is an object CloudRecoTarget (I could not find this prefab, where can I get it?) - where it listed the Target ID of the target with my database? Or indicate not in it? In ContentManager in Augumentation Object - insert a 3D model that I hung on the target? Then it turns out how I will target the cloud as I need and ContentManager with different 3D models for the Target grows exactly? And for the link to be inserted in the ContentManager to Json server url? I understand not CloudRecognition yavletsya cloud Target? By the target is CloudRecoTarget? I just need to understand how it is done, the problem is that I can not understand the principle of the recognition of the Target in the cloud (what, where, etc.)I'm sorry for my English, I write through a translator, but I really need help, Vuforia Cloud is very cool!

Please explain step by step how to use Vuforia Cloud!

January 30, 2015 - 5:02am #38

... Whoops, seems I just forgot to register my ITrackableEventHandler on Start()... Problem solved! 

Good to hear ;-)

 

Please explain step by step how to use Vuforia Cloud!

January 30, 2015 - 1:44am #37

Hi guys. I am starting out with vuforia's cloud recognition sample. I successfully catch the moment when new target is found, i.e. ICloudRecoEventHandler::OnNewSearchResult() is called. Now, I want to get to know when the same marker is found again, but cannot find the right place in the code. Thought it is supposed to be here ITrackableEventHandler::OnTrackableStateChanged(), but seems like it doesn't work out.

Thanks, Justis

 

EDIT: Whoops, seems I just forgot to register my ITrackableEventHandler on Start()... Problem solved! 

 

Please explain step by step how to use Vuforia Cloud!

December 1, 2013 - 3:15am #36

Hello I have a problem, I redid CloudRecoEventHandler, everything turned out, cloud recognition works, but after I close the recognition results, object which on overlaps the Target does not disappear from the screen. Help please, I'm desperate

 

/*==============================================================================
Copyright (c) 2012-2013 QUALCOMM Austria Research Center GmbH.
All Rights Reserved.
==============================================================================*/

using System;
using UnityEngine;
using System.Collections;

/// <summary>
/// This MonoBehaviour implements the Cloud Reco Event handling for this sample.
/// It registers itself at the CloudRecoBehaviour and is notified of new search results as well as error messages
/// The current state is visualized and new results are enabled using the TargetFinder API.
/// </summary>
public class CloudRecoEventHandler : MonoBehaviour, ICloudRecoEventHandler
{
    #region PRIVATE_MEMBER_VARIABLES

    // CloudRecoBehaviour reference to avoid lookups
    private CloudRecoBehaviour mCloudRecoBehaviour;
    // ImageTracker reference to avoid lookups
    private ImageTracker mImageTracker;
	
	private string BundleURL = "";
	public GameObject bundleHolder;
    // reference to the cloud reco scene manager component:
    //private ContentManager mContentManager;

    //  array that all textures are loaded into on startup
    private Texture mRequestingTexture;

    // the parent gameobject of the referenced ImageTargetTemplate - reused for all target search results
    private GameObject mParentOfImageTargetTemplate;

    #endregion // PRIVATE_MEMBER_VARIABLES



    #region EXPOSED_PUBLIC_VARIABLES

    /// <summary>
    /// can be set in the Unity inspector to reference a ImageTargetBehaviour that is used for augmentations of new cloud reco results.
    /// </summary>
    public ImageTargetBehaviour ImageTargetTemplate;

    #endregion



    #region ICloudRecoEventHandler_IMPLEMENTATION

    /// <summary>
    /// called when TargetFinder has been initialized successfully
    /// </summary>
    public void OnInitialized()
    {
        // get a reference to the Image Tracker, remember it
        mImageTracker = (ImageTracker)TrackerManager.Instance.GetTracker(Tracker.Type.IMAGE_TRACKER);
        //mContentManager = (ContentManager)FindObjectOfType(typeof(ContentManager));
    }

    /// <summary>
    /// visualize initialization errors
    /// </summary>
    public void OnInitError(TargetFinder.InitState initError)
    {
        switch (initError)
        {
            case TargetFinder.InitState.INIT_ERROR_NO_NETWORK_CONNECTION:
                ErrorMsg.New("Network Unavailable", "Failed to initialize CloudReco because the device has no network connection.", LoadAboutScene);
                break;
            case TargetFinder.InitState.INIT_ERROR_SERVICE_NOT_AVAILABLE:
                ErrorMsg.New("Service Unavailable", "Failed to initialize CloudReco because the service is not available.", LoadAboutScene);
                break;
        }
    }

    /// <summary>
    /// visualize update errors
    /// </summary>
    public void OnUpdateError(TargetFinder.UpdateState updateError)
    {
        switch (updateError)
        {
            case TargetFinder.UpdateState.UPDATE_ERROR_AUTHORIZATION_FAILED:
                ErrorMsg.New("Authorization Error","The cloud recognition service access keys are incorrect or have expired.");
                break;
            case TargetFinder.UpdateState.UPDATE_ERROR_BAD_FRAME_QUALITY:
                ErrorMsg.New("Poor Camera Image","The camera does not have enough detail, please try again later");
                break;
            case TargetFinder.UpdateState.UPDATE_ERROR_NO_NETWORK_CONNECTION:
                ErrorMsg.New("Network Unavailable","Please check your internet connection and try again.");
                break;
            case TargetFinder.UpdateState.UPDATE_ERROR_PROJECT_SUSPENDED:
                ErrorMsg.New("Authorization Error","The cloud recognition service has been suspended.");
                break;
            case TargetFinder.UpdateState.UPDATE_ERROR_REQUEST_TIMEOUT:
                ErrorMsg.New("Request Timeout","The network request has timed out, please check your internet connection and try again.");
                break;
            case TargetFinder.UpdateState.UPDATE_ERROR_SERVICE_NOT_AVAILABLE:
                ErrorMsg.New("Service Unavailable","The service is unavailable, please try again later.");
                break;
            case TargetFinder.UpdateState.UPDATE_ERROR_TIMESTAMP_OUT_OF_RANGE:
                ErrorMsg.New("Clock Sync Error","Please update the date and time and try again.");
                break;
            case TargetFinder.UpdateState.UPDATE_ERROR_UPDATE_SDK:
                ErrorMsg.New("Unsupported Version","The application is using an unsupported version of Vuforia.");
                break;
        }
    }

    /// <summary>
    /// when we start scanning, unregister Trackable from the ImageTargetTemplate, then delete all trackables
    /// </summary>
    public void OnStateChanged(bool scanning)
    {
        if (scanning)
        {
            // clear all known trackables
            mImageTracker.TargetFinder.ClearTrackables(false);

            // hide the ImageTargetTemplate
            //mContentManager.HideObject();
        }
    }

    /// <summary>
    /// Handles new search results
    /// </summary>
    /// <param name="targetSearchResult"></param>
    public void OnNewSearchResult(TargetFinder.TargetSearchResult targetSearchResult)
    {
        // This code demonstrates how to reuse an ImageTargetBehaviour for new search results and modifying it according to the metadata
        // Depending on your application, it can make more sense to duplicate the ImageTargetBehaviour using Instantiate(), 
        // or to create a new ImageTargetBehaviour for each new result

        // Vuforia will return a new object with the right script automatically if you use
        // TargetFinder.EnableTracking(TargetSearchResult result, string gameObjectName)
        
        //Check if the metadata isn't null
        if(targetSearchResult.MetaData == null)
        {
            return;
        }
		
		BundleURL = targetSearchResult.MetaData;
        // enable the new result with the same ImageTargetBehaviour:
        ImageTargetBehaviour imageTargetBehaviour = mImageTracker.TargetFinder.EnableTracking(targetSearchResult, mParentOfImageTargetTemplate);

        if (imageTargetBehaviour != null)
        {
            // stop the target finder
            mCloudRecoBehaviour.CloudRecoEnabled = false;
            
            // Calls the TargetCreated Method of the SceneManager object to start loading
            // the BookData from the JSON
           // mContentManager.TargetCreated(targetSearchResult.MetaData);
        }
		StartCoroutine("DownloadBundle");
    }
	
	IEnumerator DownloadBundle (){
		if (bundleHolder.transform.childCount > 0)
			Destroy(bundleHolder.transform.GetChild(0).gameObject);
		// Wait for the Caching system to be ready
		while (!Caching.ready)
			yield return null;

		// Load the AssetBundle file from Cache if it exists with the same version or download and store it in the cache
		using(WWW www = WWW.LoadFromCacheOrDownload (BundleURL, 1)){
			yield return www;
			if (www.error != null)
				throw new Exception("WWW download had an error:" + www.error);


            AssetBundle bundle = www.assetBundle;
            GameObject loaded = (GameObject)Instantiate(bundle.mainAsset);
			foreach(Transform child in bundleHolder.transform) {
			    Destroy(child);
			}
            loaded.transform.parent = bundleHolder.transform;
            
            loaded.transform.localPosition = Vector3.zero;
            loaded.transform.localScale = Vector3.one*10;
            loaded.transform.localRotation = Quaternion.identity;
		}
	}

    #endregion // ICloudRecoEventHandler_IMPLEMENTATION



    #region UNTIY_MONOBEHAVIOUR_METHODS

    /// <summary>
    /// register for events at the CloudRecoBehaviour
    /// </summary>
    void Start()
    {
        // look up the gameobject containing the ImageTargetTemplate:
        mParentOfImageTargetTemplate = ImageTargetTemplate.gameObject;

        // intialize the ErrorMsg class
        ErrorMsg.Init();

        // register this event handler at the cloud reco behaviour
        CloudRecoBehaviour cloudRecoBehaviour = GetComponent<CloudRecoBehaviour>();
        if (cloudRecoBehaviour)
        {
            cloudRecoBehaviour.RegisterEventHandler(this);
        }

        // remember cloudRecoBehaviour for later
        mCloudRecoBehaviour = cloudRecoBehaviour;

        // load and remember all used textures:
        mRequestingTexture = Resources.Load("UserInterface/TextureRequesting") as Texture;
    }
	
	void Awake()
	{
		bundleHolder = GameObject.Find("BundleHolder");		
	}

    /// <summary>
    /// draw the sample GUI and error messages
    /// </summary>
    void OnGUI()
    {
        if (mCloudRecoBehaviour.CloudRecoInitialized && mImageTracker.TargetFinder.IsRequesting())
        {
            // draw the requesting texture
            DrawTexture(mRequestingTexture);
        }

        // draw error messages in case there were any
        ErrorMsg.Draw();
    }

    #endregion // UNTIY_MONOBEHAVIOUR_METHODS



    #region PRIVATE_METHODS

    /// <summary>
    /// draws a textures using UnityGUI
    /// </summary>
    private void DrawTexture(Texture texture)
    {
        // scale texture up by device dependent factor
        int smallerScreenDimension = Screen.width < Screen.height ? Screen.width : Screen.height;
        float deviceDependentScale = smallerScreenDimension / 480f;

        // draw texture at center with given verticalPosition and scale:
        float width = texture.width * deviceDependentScale;
        float height = texture.height * deviceDependentScale;
        float left = (Screen.width * 0.5f) - (width * 0.5f);
        float top = (Screen.height * 0.9f) - (height * 0.5f);
        GUI.DrawTexture(new Rect(left, top, width, height), texture);
    }

    /// <summary>
    /// Loads the about scene.
    /// </summary>
    private void LoadAboutScene()
    {
        Application.LoadLevel("Vuforia-2-AboutScreen");
    }

    #endregion // PRIVATE_METHODS
}

 

 

 

 

Please explain step by step how to use Vuforia Cloud!

October 30, 2013 - 5:19am #35

Glad that you are successful with the cube. 

To handle more complex 3D models (and apply the same approach) my suggestion is to study and learn Unity; in their website you can find excellent material and tutorials that can get you started very quickly.

 

Please explain step by step how to use Vuforia Cloud!

October 30, 2013 - 5:13am #34

yes im successful with your suggestion..... but it dosent work with different model, like a teapot or dragon

is thera another way for creating complex model?? GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);

And one thing in your code, how to add texture in model 3d?

thx for reply my question....its very helpful

Please explain step by step how to use Vuforia Cloud!

October 30, 2013 - 12:28am #33

The code snippet I posted below is a complete but simplified example of how things can be setup to handle Cloud Reco augmentations;

it is not the same code you find in the video tutorial, however you can easily adapt it to fit into your own script.

The important part is that you need destroy the game object of your augmentation (e.g. the cube) when the state changes and the scanning flag becomes true. 

Please explain step by step how to use Vuforia Cloud!

October 29, 2013 - 8:22am #32

is thats method is different from video tutorial ??  -> https://developer.vuforia.com/resources/tutorials/creating-cloud-recognition-apps-unity

because im following thats tutorial,.. like add model, positioning, and using simpleCReventHandler,cs . so idont use setup local transformation

in your method is possible add switch case  in simpleCREventHandler,cs ??

 

Please explain step by step how to use Vuforia Cloud!

October 29, 2013 - 3:48am #31

Yes, usually the CR Event Handler is the right place; it all depends how you structure your App code however.

See this code snippet as an example of doing what you are trying to achieve:

/*==============================================================================
Copyright (c) 2013 QUALCOMM Austria Research Center GmbH.
All Rights Reserved.
Confidential and Proprietary - QUALCOMM Austria Research Center GmbH.
==============================================================================*/

using UnityEngine;
using System.Collections;

public class CubeCloudHandler : MonoBehaviour, ICloudRecoEventHandler {

	private CloudRecoBehaviour mCloudRecoBehaviour;
	private bool mIsScanning = false;
	
	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() {
		Debug.Log ("Cloud Reco initialized");
	}

    public void OnInitError(TargetFinder.InitState initError) {
		// handle error
	}

    public void OnUpdateError(TargetFinder.UpdateState updateError) {
		// handle error
	}

    public void OnStateChanged(bool scanning) {
		mIsScanning = scanning;
		
		if (scanning) {
            // clear all known trackables
			ImageTracker tracker = TrackerManager.Instance.GetTracker(Tracker.Type.IMAGE_TRACKER) as ImageTracker;
            tracker.TargetFinder.ClearTrackables(false);
			
			// Remove the augmentation (cube object)
			if (ImageTargetTemplate) {
				Transform cube = ImageTargetTemplate.transform.FindChild("MyAugmentation");	
				if (cube) {
					GameObject.Destroy(cube.gameObject);	
				}
			}
        }
	}
	
	// Here we handle a target reco event
    public void OnNewSearchResult(TargetFinder.TargetSearchResult targetSearchResult) {
		// stop the target finder
        mCloudRecoBehaviour.CloudRecoEnabled = false;
		
		// Build augmentation based on target
		if (ImageTargetTemplate) {
			// enable the new result with the same ImageTargetBehaviour:
			ImageTracker tracker = TrackerManager.Instance.GetTracker(Tracker.Type.IMAGE_TRACKER) as ImageTracker;
        	ImageTargetBehaviour imageTargetBehaviour = tracker.TargetFinder.EnableTracking(targetSearchResult, ImageTargetTemplate.gameObject);
			
			// Create a simple cube
			GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
			cube.name = "MyAugmentation";
			
			// Attach cube as child of the cloud image target
			cube.transform.parent = imageTargetBehaviour.gameObject.transform;
			
			// Setup local transformation
			cube.transform.localPosition = new Vector3(0.0f, 0.0f, 0.0f);
			cube.transform.localScale = new Vector3(0.2f, 0.2f, 0.2f);
			cube.transform.localRotation = Quaternion.identity;
			
			// Enable cube
			cube.SetActive(true);
		}
	}
	
	void OnGUI() {
		// If not scanning, show button 
		// so that user can restart scanning
		if (!mIsScanning) {
			if (GUI.Button(new Rect(100,100,200,50), "Restart Scanning")) {
				// Restart TargetFinder
				mCloudRecoBehaviour.CloudRecoEnabled = true;
			}
		}
	}
}

 

Please explain step by step how to use Vuforia Cloud!

October 29, 2013 - 3:34am #30

Where i must put that code?? in CREventHandler.cs ?? or??

Sory im new in unity,...im lstarted in 8 hours ago :P

Please explain step by step how to use Vuforia Cloud!

October 29, 2013 - 3:09am #29

You need to destroy the game object (cube) when closing:

GameObject.Destroy ( cubeGameObject );

 

Please explain step by step how to use Vuforia Cloud!

October 28, 2013 - 9:30pm #28

Hi...

im newbie using unity, im trying to learning about sample CR with unity,...when i try to add 3D model (cube), it always showing in the first time but when camera detect image target the position of cube move to the target, and when close button clicked the cube not disapear.

SS in attachments

 

AttachmentSize
Image icon Screenshot_2013-10-29-11-13-46.png473.39 KB

Please explain step by step how to use Vuforia Cloud!

July 10, 2013 - 3:35pm #27

Hi again, 

Although I have managed to use the tutorial as an example, and replicate those results, I still want to use assetBundles to download augmentations at runtime based on CloudRecognized image target's metadata. This is the addition to the simplecloudrecoeventhandler script that I tried, but so far have not managed an augmentation. It is not an issue with recognition as I have tested the images, and Unity informs me that trackables have been detected, so I think the problem lies in my script. The goal is to download the asset bundle from a link in the metadata of the image targeted (each metadata will be different) and put the assets into the scene under the image target, and I'm not sure that I'm achieving that with this code, please advise. (relevant changes in IEnumerator and OnNewSearchResult)

 

using System;

using UnityEngine;

using System.Collections;

 

/// <summary>

/// This MonoBehaviour implements the Cloud Reco Event handling for this sample.

/// It registers itself at the CloudRecoBehaviour and is notified of new search results.

/// </summary>

public class SimpleCloudRecoEventHandler : MonoBehaviour, ICloudRecoEventHandler

{

    #region PRIVATE_MEMBER_VARIABLES

 

    // CloudRecoBehaviour reference to avoid lookups

    private CloudRecoBehaviour mCloudRecoBehaviour;

    // ImageTracker reference to avoid lookups

    private ImageTracker mImageTracker;

 

//private GameObject cube, sphere;

 

    #endregion // PRIVATE_MEMBER_VARIABLES

 

 

 

    #region EXPOSED_PUBLIC_VARIABLES

 

    /// <summary>

    /// can be set in the Unity inspector to reference a ImageTargetBehaviour that is used for augmentations of new cloud reco results.

    /// </summary>

    public ImageTargetBehaviour ImageTargetTemplate;

public string BundleURL;

public int version;

public string AssetName;

 

    #endregion

 

     #region UNTIY_MONOBEHAVIOUR_METHODS

 

    /// <summary>

    /// register for events at the CloudRecoBehaviour

    /// </summary>

    void Start()

    {

        // register this event handler at the cloud reco behaviour

        CloudRecoBehaviour cloudRecoBehaviour = GetComponent<CloudRecoBehaviour>();

        if (cloudRecoBehaviour)

        {

            cloudRecoBehaviour.RegisterEventHandler(this);

        }

 

        // remember cloudRecoBehaviour for later

        mCloudRecoBehaviour = cloudRecoBehaviour;

    }

 

    #endregion // UNTIY_MONOBEHAVIOUR_METHODS

 

 

 

    #region ICloudRecoEventHandler_IMPLEMENTATION

 

    /// <summary>

    /// called when TargetFinder has been initialized successfully

    /// </summary>

    public void OnInitialized()

    {

        // get a reference to the Image Tracker, remember it

        mImageTracker = (ImageTracker)TrackerManager.Instance.GetTracker(Tracker.Type.IMAGE_TRACKER);

    }

 

    /// <summary>

    /// visualize initialization errors

    /// </summary>

    public void OnInitError(TargetFinder.InitState initError)

    {

    }

 

    /// <summary>

    /// visualize update errors

    /// </summary>

    public void OnUpdateError(TargetFinder.UpdateState updateError)

    {

    }

 

    /// <summary>

    /// when we start scanning, unregister Trackable from the ImageTargetTemplate, then delete all trackables

    /// </summary>

    public void OnStateChanged(bool scanning)

    {

    }

 

public IEnumerator downloadBundle(TargetFinder.TargetSearchResult targetSearchResult) {

 

BundleURL = targetSearchResult.MetaData;

 

using (WWW www = new WWW(BundleURL)) {

yield return www;

if (www.error != null)

throw new Exception ("WWW download had an error:" + www.error);

AssetBundle bundle = www.assetBundle;

if (AssetName == "")

Instantiate (bundle.mainAsset);

 

 

 

else

Instantiate(bundle.Load(AssetName));

//Unload the AssetBundles compressed contents to conserve memory

bundle.Unload(false);

}

}

 

    /// <summary>

    /// Handles new search results

    /// </summary>

    /// <param name="targetSearchResult"></param>

    public void OnNewSearchResult(TargetFinder.TargetSearchResult targetSearchResult)

    {

        // duplicate the referenced image target

        GameObject newImageTarget = Instantiate(ImageTargetTemplate.gameObject) as GameObject;

 

        // enable the new result with the same ImageTargetBehaviour:

        ImageTargetBehaviour imageTargetBehaviour = mImageTracker.TargetFinder.EnableTracking(targetSearchResult, newImageTarget);

 

 

        if (imageTargetBehaviour != null)

        {

            // stop the target finder

            mCloudRecoBehaviour.CloudRecoEnabled = false;

        }

    }

 

    #endregion // ICloudRecoEventHandler_IMPLEMENTATION

 

/*public void Hide (GameObject obj)

{

 

Renderer[] rendererComponents = obj.GetComponentsInChildren<Renderer>();

 

//Disable rendering:

foreach (Renderer component in rendererComponents)

{

component.enabled = false;

}

 

} */

 

 

 

}

Please explain step by step how to use Vuforia Cloud!

June 18, 2013 - 9:03am #26

The examples for using Asset Bundles are helpful, however they do not explain how one might specify that the needed URL be from the target metadata. http://docs.unity3d.com/Documentation/Manual/DownloadingAssetBundles.html Instead, in these examples, after the code is loaded to an empty GameObject, the BundleURL is meant to be specified in the Inspector. Going back to the sample to see how things are loaded and executed from the metadata is confusing since it is done in many places (Event Handler, Content Manager, TargetFinder) and is then parsed into many more bits of information. I feel that there should be a much simpler method when the augmentation object is straightforward. Like you mentioned:

//Check if the metadata isn't null
if(targetSearchResult.MetaData == null)
{
    // retrieve the URL from .Metadata and do something
}

Although in my case I'm unsure about the "retrieve the URL from .Metadata and do something" part. Maybe the answer is to grab the URL and redefine the BundleURL as the metadata URL? I'm still unsure of how this would be done.

Additionally, although I have managed to recognize cloud targets with the simple event handler, I am not able to recongnize another target within the same run. In the sample this is achieved by clearing all data when the augmentation is closed out of . Is there a way to clear tracking data when the target is no longer in view so that the user can switch to a new target?

Please explain step by step how to use Vuforia Cloud!

June 13, 2013 - 3:52pm #25

AssetBundles are a type of archive that you compile using a build script that identifies which assets in a scene a/o project should be packaged into the resulting archive. This build process is typically performed in the Unity Editor. You can then host the resulting AssetBundle archive on your server and download it to your app at runtime. For your purposes, you'll be using explicitly named assets because you are not trying to download an entire scene.

Be sure to read the relevant tutorial..

http://docs.unity3d.com/Documentation/Manual/AssetBundlesIntro.html

Please explain step by step how to use Vuforia Cloud!

June 13, 2013 - 1:31pm #24

I am trying to understand how AssetBundles work, but am already lost. For my purposes (reading metadata url, placing linked object) would I need BuildPipeline.BuildStreamedSceneAssetBundle or BuildPipeline.BuildAssetBundleExplicitAssetNames?

The explanation for either of these does not explain where the code goes. A new prefab?

I am a bit confused about the AssetBundle process. Should I bring my models into Unity and edit them first then bundle them into the image target metadata do be loaded at run time? Or will Unity create an AssetBundle from the .dxf file in my metada then automatically download it during runtime? If I'm correct, the sample doesn't use AssetBundles. Why not?

Unrelated: What is the maximum object file size for my purposes?

Please explain step by step how to use Vuforia Cloud!

June 13, 2013 - 12:29pm #23

Just remove that reference from CloudRecoBehaviour, it shouldn't be there.

The CloudRecoEventHandler will register itself w/ the CloudRecoBehaviour - both are necessary.

Please explain step by step how to use Vuforia Cloud!

June 13, 2013 - 8:52am #22

Hi again,

When I tried to use this code, I found that there was already a SimpleCloudRecoEventHandler class in the prefab script CloudRecoBehavior.cs. I can try simply renaming the new class in the CloudRecoEvenHandler, but I am worried that because these have similar properties, they will interfere with each other. Because we've made a new Event Handler, does the existing class in CloudRecoBehavior need to be disabled?

Thanks,

Audrey

CloudRecoBehavior code is attached for reference.

AttachmentSize
PDF icon CloudRecoBehaviour.pdf22.36 KB

Please explain step by step how to use Vuforia Cloud!

June 12, 2013 - 3:39pm #21

Make sure that you don't have another instance of the Unity editor running that has your project loaded. If so, close one, if not close restart Unity.

Please explain step by step how to use Vuforia Cloud!

June 12, 2013 - 3:03pm #20

Ah, OK.

I've just attempted to create the new script that you suggested, but when I debug, I keep getting the error: "It looks like another Unity instance is running with this project open. Multiple Unity instances can't open the same project. Project:/Users/....." (the last part is the current project's location on my computer). I thought perhaps this was do to another script having the same name, but I received the same error when I changed it. Is this normal?

Thank you for being so helpful and prompt.

Please explain step by step how to use Vuforia Cloud!

June 12, 2013 - 2:25pm #19

Yes the event handler is the script presented earlier in the thread. I've posted another example below. The ICloudRecoEventHandler isn't working because it's an interface class and needs to be implemented as follows..


using System;
using UnityEngine;

/// <summary>
/// This MonoBehaviour implements the Cloud Reco Event handling for this sample.
/// It registers itself at the CloudRecoBehaviour and is notified of new search results.
/// </summary>
public class SimpleCloudRecoEventHandler : MonoBehaviour, ICloudRecoEventHandler
{
    #region PRIVATE_MEMBER_VARIABLES

    // CloudRecoBehaviour reference to avoid lookups
    private CloudRecoBehaviour mCloudRecoBehaviour;
    // ImageTracker reference to avoid lookups
    private ImageTracker mImageTracker;

    #endregion // PRIVATE_MEMBER_VARIABLES



    #region EXPOSED_PUBLIC_VARIABLES

    /// <summary>
    /// can be set in the Unity inspector to reference a ImageTargetBehaviour that is used for augmentations of new cloud reco results.
    /// </summary>
    public ImageTargetBehaviour ImageTargetTemplate;

    #endregion



    #region ICloudRecoEventHandler_IMPLEMENTATION

    /// <summary>
    /// called when TargetFinder has been initialized successfully
    /// </summary>
    public void OnInitialized()
    {
        // get a reference to the Image Tracker, remember it
        mImageTracker = (ImageTracker)TrackerManager.Instance.GetTracker(Tracker.Type.IMAGE_TRACKER);
    }

    /// <summary>
    /// visualize initialization errors
    /// </summary>
    public void OnInitError(TargetFinder.InitState initError)
    {
    }

    /// <summary>
    /// visualize update errors
    /// </summary>
    public void OnUpdateError(TargetFinder.UpdateState updateError)
    {
    }

    /// <summary>
    /// when we start scanning, unregister Trackable from the ImageTargetTemplate, then delete all trackables
    /// </summary>
    public void OnStateChanged(bool scanning)
    {
    }

    /// <summary>
    /// Handles new search results
    /// </summary>
    /// <param name="targetSearchResult"></param>
    public void OnNewSearchResult(TargetFinder.TargetSearchResult targetSearchResult)
    {
        // duplicate the referenced image target
        GameObject newImageTarget = Instantiate(ImageTargetTemplate.gameObject) as GameObject;

        // enable the new result with the same ImageTargetBehaviour:
        ImageTargetBehaviour imageTargetBehaviour = mImageTracker.TargetFinder.EnableTracking(targetSearchResult, newImageTarget);

        if (imageTargetBehaviour != null)
        {
            // stop the target finder
            mCloudRecoBehaviour.CloudRecoEnabled = false;
        }
    }

    #endregion // ICloudRecoEventHandler_IMPLEMENTATION



    #region UNTIY_MONOBEHAVIOUR_METHODS

    /// <summary>
    /// register for events at the CloudRecoBehaviour
    /// </summary>
    void Start()
    {
        // register this event handler at the cloud reco behaviour
        CloudRecoBehaviour cloudRecoBehaviour = GetComponent<CloudRecoBehaviour>();
        if (cloudRecoBehaviour)
        {
            cloudRecoBehaviour.RegisterEventHandler(this);
        }

        // remember cloudRecoBehaviour for later
        mCloudRecoBehaviour = cloudRecoBehaviour;
    }

    #endregion // UNTIY_MONOBEHAVIOUR_METHODS

}

 

And yes, if there is an existing CR event handler (e.g. from the CR sample ) disable it.

Please explain step by step how to use Vuforia Cloud!

June 12, 2013 - 2:20pm #18

Thanks,

the event handling script can be dropped onto the CloudRecognition prefab in the scene Hierarchy panel, or by highlighting the CloudRecognition prefab and dragging it onto its Inspector panel. You don't need to use Add Component, and be sure to disable any other event handler on the CR prefab if you are using your own version.

The even handling script that you refer to here is the one that you wrote in an earlier post on this thread?

I actually tried to drag an existing event handler "ICloudRecoEventHandler" into the CR prefab, but got the error: "Can't add script behaviour ICloudRecoHandler. The script class can't be abstract!" If I were to do this correctly, should I disable this existing script, write a new one with the code you posted (not sure where it would go in the Assets), and attach it to the CloudRecognition Prefab in my Hierarchy?

-Audrey

Please explain step by step how to use Vuforia Cloud!

June 12, 2013 - 2:01pm #17

We have a video tutorial for Cloud Reco on the way.

To answer your question, the event handling script can be dropped onto the CloudRecognition prefab in the scene Hierarchy panel, or by highlighting the CloudRecognition prefab and dragging it onto its Inspector panel. You don't need to use Add Component, and be sure to disable any other event handler on the CR prefab if you are using your own version.

Prefabs are configurable components that can encapsulate  multiple scripts and are treated as GameObjects in the scene. The ARCamera, ImageTarget, CloudRecognition etc.. are Vuforia prefabs. You can find them in the Qualcomm Augmented Reality / Prefabs folder.

And you are correct that these instructions are for creating a new Cloud Reco scene, they are not based on the sample. So start with a fresh scene and add the ARCamera and CloudRecognition prefabs, and also add an ImageTarget prefab and define it as a Cloud Reco type in its Inspector panel. Also be sure to add your Cliend Access keys to the CR prefab's Inspector.

Once that is set-up, you can obtain your metadata from the search result within OnNewSearchResult in the event handler as such..

        //Check if the metadata isn't null
        if(targetSearchResult.MetaData == null)
        {
            // retrieve the URL from .Metadata and do something
        }

Take a look at Unity AssetBundles to learn how you can  load assets using a URL - http://docs.unity3d.com/Documentation/Manual/AssetBundlesIntro.html, http://docs.unity3d.com/Documentation/ScriptReference/AssetBundle.html

You'd then need to make the loaded model a child of the instantiated ImageTarget template.

Please explain step by step how to use Vuforia Cloud!

June 12, 2013 - 1:34pm #16

Hi,

I'm trying to use Cloud Recognition and Target Metadata to augment several images with different models (one each). I've put a url link to the corresponding model in a text file for each image metadata (only one model per image), but I have difficulties with how this information is then processed in Unity so that a different model appears for each target. I have been trying to piece together forums, but am not familiar enough with the programming and software to understand each answer. For example, when you say:

 

Then add a CloudRecoEventHandler to your prefab instance ( see below ). This will enable you to capture image search results, which are returned as members of the TargetFinder.TargetSearchResult struct.

 

I'm not sure what you mean by prefab instance. Are you in the script editor, adding a new script? Or is this in the Unity inspector window for the CloudRecognition Prefab where there's an Add Component Option?

Am I correct to think that your example does not build on the sample CR project?

 

Thanks,

Audrey

(for people like me, I think a tutorial video on this subject would be extremely helpful, I have already learned a lot from the other videos)

Please explain step by step how to use Vuforia Cloud!

May 13, 2013 - 7:40am #15

Is there a way however, to let the user create an Image Target and upload this to the Cloud Database?

You need to upload it to your own server, which can then act as a Gateway to upload to the Vuforia Cloud using the VWS API.

 

N

BTW Please in future create a new thread rather than re-use an existing one.

Please explain step by step how to use Vuforia Cloud!

May 13, 2013 - 2:09am #14

DavidBeard, you made it clear that the API for adding Image Targets to the Cloud is a different API than the one for creating Cloud Recognition apps. 

Is there a way however, to let the user create an Image Target and upload this to the Cloud Database? Perhaps by accessing the server where the VWS API runs through the native code? (I'm not very familiar with the server side yet )

 

Some help would be really useful. Especially because I haven't seen another easy way to save user-defined targets.

Please explain step by step how to use Vuforia Cloud!

February 27, 2013 - 9:43am #13

Hi, Nalin has already explained it all very well.

Just to add a little clarification about your last question :

how does it know that image 1 the chips has a cube assosiated with it and not a cylinder? 

In CloudReco you don't attach the augmentation (e.g. your 3D models) up-front to the trackables (as opposed to what you would do in the ImageTargets sample);

the association between a target (identified on the Cloud) and its 3D model is typically done via some script logic;

for instance, if you look at the CloudReco sample, you can see two scripts:

  • CloudRecoEventHandler.cs
  • ContentManager.cs

In the CloudRecoEventhandler script, you have a method called OnNewSearchResult; if you look a the code in there, you will see this line:

mContentManager.TargetCreated(targetSearchResult.MetaData);

If you then go to the TargetCreated implementation in the ContentManager script, you will see that the content is dynamically created or updated depending on the target metadata (technically, you could also use the "target-id" or the "target-name" depending on your application scenario);

so, in your example, the actual 3D model (cylinder or cube for instance) to use will be determined at run time through the script logic;

also have a look at the two methods showObject() and hideObject() defined in ContentManager, for inspiration on how to dynamically show and hide 3D objects, as this technique can also turn useful if you want to switch 3Dmodels dynamically.

 

 

Please explain step by step how to use Vuforia Cloud!

February 27, 2013 - 8:25am #12

 

How do I assign the image target to the target id of the uploaded image

You don't.  The whole point is that Cloud Reco searches your Cloud Database that you have set up for all your images and identifies the correct one.

 

So how does it know to attach a specific object to an image target from the cloud if its not defined on the local app?

for example, image 1 has a cube on it and image 2 has a cylinder, image 1 is the chips image target and image 2 is the stones image target. 

how does it know that image 1 the chips has a cube assosiated with it and not a cylinder?

Please explain step by step how to use Vuforia Cloud!

February 27, 2013 - 3:13am #11

hi darrendelorme

Please in future could you create a new topic rather than try to re-use an existing one.  This simply causes confusion and delays response.

To answer your questions:

How do I assign the image target to the target id of the uploaded image

You don't.  The whole point is that Cloud Reco searches your Cloud Database that you have set up for all your images and identifies the correct one.

What are the names of the files I should be altering?

N/A

Also how do I ad multiple image targets under the one image target template in the CloudRecognition inspector

You don't.  Simply add more images to your cloud database and it will pick out the right one for you.

It's also probably worth going over the Developer Guide again... https://developer.vuforia.com/resources/dev-guide/cloud-targets

 

HTH

N

 

 

Please explain step by step how to use Vuforia Cloud!

February 26, 2013 - 10:44pm #10

I created an account and uploaded my image target after I created my cloud database. I added the client access keys to the CloudRecognition prefab from the hierarchy in the inspector. How do I assign the image target to the target id of the uploaded image. What are the names of the files I should be altering? Also how do I ad multiple image targets under the one image target template in the CloudRecognition inspector? 

 

There can only be one CR

December 24, 2012 - 9:53am #9

There can only be one CR target active at a time - you can't track mulitiple CR targets simultaneously.

No I do not need an "how to

December 17, 2012 - 2:40pm #8

No I do not need an "how to instantiate an ImageTarget template in order to apply this template to multiple TargetFinder results dynamically", I need more, how to I use several ImageTarget Template in CloudRecoEventHandler? Ie Now I have a problem, I can use a lot of images for recognition in the database clouds, but recognized and overlap of augmented reality can only be one ImageTarget which I put in ImageTarget Template (in the script CloudRecoEventHandler) - how shove many imagetarget's in Image Target Template (in script CloudRecoEventHandler)?

That API is different from

December 17, 2012 - 2:05pm #7

That API is different from the API used for building CR apps. Rather it is used to develop VWS clients that interact with Cloud Databases, in order to enable developers to upload and manage portfolios of images. These VWS clients will typically run on a server. 

Here is an example of how to instantiate an ImageTarget template in order to apply this template to multiple TargetFinder results dynamically..

 

 

    public void OnNewSearchResult(TargetFinder.TargetSearchResult targetSearchResult)
    {
        // duplicate the referenced image target
        GameObject newImageTarget = Instantiate(ImageTargetTemplate.gameObject) as GameObject;
 
        // enable the new result with the same ImageTargetBehaviour:
        ImageTargetBehaviour imageTargetBehaviour = mImageTracker.TargetFinder.EnableTracking(targetSearchResult, newImageTarget);
 
        if (imageTargetBehaviour != null)
        {
            // stop the target finder
            mCloudRecoBehaviour.CloudRecoEnabled = false;
        }
    }
 
Keep in mind that there can only be one active CR search result at any time.

Thank you, that I have read -

December 17, 2012 - 1:50pm #6

Thank you, that I have read - https://developer.vuforia.com/resources/dev-guide/adding-target-cloud-database-api, but I can not understand how it all goes in the code, can you show me sample code - to recognize more than 1 target with a cloud, thanks in advance. I saw an sample cloudrecognition-2-0-6.unitypackage, it has CloudRecoTarget, I understand that it is possible as that poke some ImageTarget, then throw in CloudRecoTarget CloudRecognition as Image Target Template? I tried to do so but nepoluchaetsya, I don `t know how much thrust in CloudRecoTarget ImageTarget's.

For that I recommend

December 14, 2012 - 1:43pm #5

For that I recommend developing your own VWS Cloud Recognition provisioning client that uses the provisioning and management API to upload your targets in batches. See: https://developer.vuforia.com/resources/dev-guide/adding-target-cloud-database-api

You'll use your server keys in this case, not your client keys. 

How to add many ImageTarget's

December 14, 2012 - 1:39pm #4

How to add many ImageTarget's to a CloudRecognition?

Great thanks :) Now I get it,

December 14, 2012 - 1:21pm #3

Great thanks :) Now I get it, its cool!

 You'll need to sign-up for

December 14, 2012 - 10:42am #2

 

You'll need to sign-up for a free Cloud Recognition developer account and then create a Cloud Database in the Target Manager - https://developer.vuforia.com/targetmanager

This will provide you with a set of keys. You'll use the Client Access Keys to query your database from your Vuforia app, and the Server Access keys to provision and manage your targets on the cloud. 

You can add targets to your Cloud Database from within the Target Manager by selecting Add Target and uploading them to the database.

Once you have your Cloud Database and targets set-up online, simply add your Client Access keys to the Cloud Reco Behaviour component on the CloudRecogntion prefab instance in the Inspector. 

You can find the CloudRecognition prefab in the Qualcomm Augmented Reality / Prefabs folder. Drag this onto your scene hierarchy.

Then add a CloudRecoEventHandler to your prefab instance ( see below ). This will enable you to capture image search results, which are returned as members of the TargetFinder.TargetSearchResult struct.
 
    public struct TargetSearchResult
    {
        // name of the target
        public string TargetName;
        // system-wide unique id of the target.
        public string UniqueTargetId;
        /// width of the target (in 3D scene units)
        public float TargetSize;
        // metadata associated with this target
        public string MetaData;
        //tracking rating for this target
        /**
         *  The tracking rating represents a 5-star rating describing the
         *  suitability of this target for tracking on a scale from 0 to 5. A low
         *  tracking rating may result in poor tracking or unstable augmentation.
         */
        public byte TrackingRating;
        // pointer to native search result
        public IntPtr TargetSearchResultPtr;
    
}
 
To augment the target that's returned, you'll use an Image Target Template, which is simply an ImageTarget instance in your scene that you designate as the template for augmenting your CR targets. You can assign this by dragging the ImageTarget instance from your Hierarchy onto the Image Target Template field of your CloudRecoEventHandler.
 
using System;
using UnityEngine;
 
/// <summary>
/// This MonoBehaviour implements the Cloud Reco Event handling for this sample.
/// It registers itself at the CloudRecoBehaviour and is notified of new search results.
/// </summary>
public class SimpleCloudRecoEventHandler : MonoBehaviour, ICloudRecoEventHandler
{
    #region PRIVATE_MEMBER_VARIABLES
 
    // CloudRecoBehaviour reference to avoid lookups
    private CloudRecoBehaviour mCloudRecoBehaviour;
    // ImageTracker reference to avoid lookups
    private ImageTracker mImageTracker;
 
    #endregion // PRIVATE_MEMBER_VARIABLES
 
 
 
    #region EXPOSED_PUBLIC_VARIABLES
 
    /// <summary>
    /// can be set in the Unity inspector to reference a ImageTargetBehaviour that is used for augmentations of new cloud reco results.
    /// </summary>
    public ImageTargetBehaviour ImageTargetTemplate;
 
    #endregion
 
 
 
    #region ICloudRecoEventHandler_IMPLEMENTATION
 
    /// <summary>
    /// called when TargetFinder has been initialized successfully
    /// </summary>
    public void OnInitialized()
    {
        // get a reference to the Image Tracker, remember it
        mImageTracker = (ImageTracker)TrackerManager.Instance.GetTracker(Tracker.Type.IMAGE_TRACKER);
    }
 
    /// <summary>
    /// initialization errors
    /// </summary>
    public void OnInitError(TargetFinder.InitState initError)
    {
    }
 
    /// <summary>
    ///  update errors
    /// </summary>
    public void OnUpdateError(TargetFinder.UpdateState updateError)
    {
    }
 
    /// <summary>
    /// updates to the scanning state
    /// </summary>
    public void OnStateChanged(bool scanning)
    {
    }
 
    /// <summary>
    /// Handles new search results
    /// </summary>
    /// <param name="targetSearchResult"></param>
    public void OnNewSearchResult(TargetFinder.TargetSearchResult targetSearchResult)
    {
        // duplicate the referenced image target
        GameObject newImageTarget = Instantiate(ImageTargetTemplate.gameObject) as GameObject;
 
        // enable the new result with the same ImageTargetBehaviour:
        ImageTargetBehaviour imageTargetBehaviour = mImageTracker.TargetFinder.EnableTracking(targetSearchResult, newImageTarget);
 
        if (imageTargetBehaviour != null)
        {
            // stop the target finder
            mCloudRecoBehaviour.CloudRecoEnabled = false;
        }
    }
 
    #endregion // ICloudRecoEventHandler_IMPLEMENTATION
 
 
 
    #region UNTIY_MONOBEHAVIOUR_METHODS
 
    /// <summary>
    /// register for events at the CloudRecoBehaviour
    /// </summary>
    void Start()
    {
        // register this event handler at the cloud reco behaviour
        CloudRecoBehaviour cloudRecoBehaviour = GetComponent<CloudRecoBehaviour>();
        if (cloudRecoBehaviour)
        {
            cloudRecoBehaviour.RegisterEventHandler(this);
        }
 
        // remember cloudRecoBehaviour for later
        mCloudRecoBehaviour = cloudRecoBehaviour;
    }
 
    #endregion // UNTIY_MONOBEHAVIOUR_METHODS
 
}
 
Scanning will start automatically. You can control the scanning state by setting CloudRecoBehaviour.CloudRecoEnabled = true || false.
 
You don't need to use the ContentManager object. That's a utility object for the sample that retrieves JSON serialized metadata from a server to customize the augmentations. But it's not necessary for working with the Cloud Recognition service. All you need to develop a CR scene are the CloudRecognition prefab an ImageTarget instance and of course the ARCamera. 
 
Topic locked