Log in or register to post comments

Creating my books JSON - iOS

December 20, 2012 - 6:58am #1

I'm trying to use CloudReco with my own keys, target from cloud with metadata containing only JSON file name. I placed my JSON via MAMP, put my url in CloudReco app, but nothing at all.

I mean it does recognise my target (prejudice with zombies book), gets metadata, but it stops working properly after:

  1. once failed target recognition is not scaning for book - got to crash it and restart
  2. often is not recognising, even if it did with the same light a minute ago
  3. cannot parse data from my localhost's json, even it is acutally part of yours JSON (https://developer.vuforia.com/samples/cloudreco/json/samplebook1.json) - yes, I did change target ID for an appropiate one

Any hints/tutorials ?

Creating my books JSON - iOS

April 25, 2013 - 8:24am #21

It is difficult to say what is wrong here.

My suggestion is to break it down to find out where the problem is:

  • try it with the default cloud database first to see if everything is connecting ok
  • replace the event handle with your own custom one to see if the behaviour is as expected
  • replace the content manager with your own custom one to see if the behaviour is as expected
  • try it with your own cloud db and access keys.

I was able to get the SimpleCloudRecoEventHandler working by starting off with the standard cloud reco scene and stripping out components I did not need.  The other thing that can often be a problem is making sure everything connects up in Unity.

Finally, what does the log say?  How far is it getting?

 

N

 

 

Creating my books JSON - iOS

April 24, 2013 - 9:36pm #20

Hi NalinS,

I've tried your code, but the tracking of the target is not working.

I've entered the client keys.

Here's my customcloudreco:

 


/*==============================================================================
Copyright (c) 2012 QUALCOMM Austria Research Center GmbH.
All Rights Reserved.
Qualcomm Confidential and Proprietary
==============================================================================*/
 
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 CustomCloudRecoEventHandler : MonoBehaviour, ICloudRecoEventHandler
{
    #region PRIVATE_MEMBER_VARIABLES
 
    // CloudRecoBehaviour reference to avoid lookups
    private CloudRecoBehaviour mCloudRecoBehaviour;
    
	// ImageTracker reference to avoid lookups
    private ImageTracker mImageTracker;
	
	 // reference to the cloud reco scene manager component:
    private CustomContentManager mContentManager;
	
	// 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 = (CustomContentManager)FindObjectOfType(typeof(CustomContentManager));
    }
 
    /// <summary>
    /// visualize initialization errors
    /// </summary>
    public void OnInitError(TargetFinder.InitState initError)
    {
		switch (initError)
        {
            case TargetFinder.InitState.INIT_ERROR_NO_NETWORK_CONNECTION:
                CloudErrorMsg.New("Network Unavailable", "Failed to initialize CloudReco because the device has no network connection.", LoadAboutScene);
                break;
            case TargetFinder.InitState.INIT_ERROR_SERVICE_NOT_AVAILABLE:
                CloudErrorMsg.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:
                CloudErrorMsg.New("Authorization Error","The cloud recognition service access keys are incorrect or have expired.");
                break;
            case TargetFinder.UpdateState.UPDATE_ERROR_BAD_FRAME_QUALITY:
                CloudErrorMsg.New("Poor Camera Image","The camera does not have enough detail, please try again later");
                break;
            case TargetFinder.UpdateState.UPDATE_ERROR_NO_NETWORK_CONNECTION:
                CloudErrorMsg.New("Network Unavailable","Please check your internet connection and try again.");
                break;
            case TargetFinder.UpdateState.UPDATE_ERROR_PROJECT_SUSPENDED:
                CloudErrorMsg.New("Authorization Error","The cloud recognition service has been suspended.");
                break;
            case TargetFinder.UpdateState.UPDATE_ERROR_REQUEST_TIMEOUT:
                CloudErrorMsg.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:
                CloudErrorMsg.New("Service Unavailable","The service is unavailable, please try again later.");
                break;
            case TargetFinder.UpdateState.UPDATE_ERROR_TIMESTAMP_OUT_OF_RANGE:
                CloudErrorMsg.New("Clock Sync Error","Please update the date and time and try again.");
                break;
            case TargetFinder.UpdateState.UPDATE_ERROR_UPDATE_SDK:
                CloudErrorMsg.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)
    {
        // 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;
    }
	
	 /// <summary>
    /// Loads the about scene.
    /// </summary>
    private void LoadAboutScene()
    {
        Application.LoadLevel("CloudAboutScreen");
    }

 
    #endregion // UNTIY_MONOBEHAVIOUR_METHODS
 
}

And here's my customcontentmanager:

using UnityEngine;
using System.Collections;

public class CustomContentManager : MonoBehaviour, ITrackableEventHandler 
{
	/// <summary>
    /// The spinning wheel rendered while data is fetched from the server
    /// </summary>
    public Texture LoadingSpinner;
	
	/// <summary>
    /// The background texture behind the spinning wheel
    /// </summary>
    public Texture LoadingBackground;
	
	public GameObject AugmentationObject;
	
	bool tracked;
	
    // Use this for initialization
	void Start () {
		
		TrackableBehaviour trackableBehaviour = AugmentationObject.transform.GetComponent<TrackableBehaviour>();
		if (trackableBehaviour)
        {
            trackableBehaviour.RegisterTrackableEventHandler(this);
        }
		
		HideObject();
	}
	
	// Update is called once per frame
	void Update () {
		
		// Back Key opens the Abouts Screen
        if (Input.GetKeyDown(KeyCode.Escape)) 
        {    
            Application.LoadLevel("CloudAboutScreen");
        }
		
	}
	
	public void OnTrackableStateChanged(
                                    TrackableBehaviour.Status previousStatus,
                                    TrackableBehaviour.Status newStatus)
    {
        if (newStatus == TrackableBehaviour.Status.DETECTED ||
            newStatus == TrackableBehaviour.Status.TRACKED)
        {
            TargetFound();
        }
        else
        {
            TargetLost();
        }
    }
	
	public void HideObject()
    {
        Renderer[] rendererComponents = AugmentationObject.GetComponentsInChildren<Renderer>();
        Collider[] colliderComponents = AugmentationObject.GetComponentsInChildren<Collider>();

        // Enable rendering:
        foreach (Renderer component in rendererComponents)
        {
            component.enabled = false;
        }

        // Enable colliders:
        foreach (Collider component in colliderComponents)
        {
            component.enabled = false;
        }
		
		tracked = false;
    }
	
	private void TargetFound()
    {
        Renderer[] rendererComponents = AugmentationObject.GetComponentsInChildren<Renderer>();
        Collider[] colliderComponents = AugmentationObject.GetComponentsInChildren<Collider>();

        // Enable rendering:
        foreach (Renderer component in rendererComponents)
        {
            component.enabled = true;
        }

        // Enable colliders:
        foreach (Collider component in colliderComponents)
        {
            component.enabled = true;
        }
		tracked = true;
    }

    /// <summary>
    /// Method called from the CloudReco Trackable Event Handler
    /// when a target has been Lost
    /// </summary>
    private void TargetLost()
    {
        Renderer[] rendererComponents = AugmentationObject.GetComponentsInChildren<Renderer>();
        Collider[] colliderComponents = AugmentationObject.GetComponentsInChildren<Collider>();

        // Disable rendering:
        foreach (Renderer component in rendererComponents)
        {
            component.enabled = false;
        }

        // Disable colliders:
        foreach (Collider component in colliderComponents)
        {
            component.enabled = false;
        }
		
		tracked = false;
    }
	
	void OnGUI()
    {
        if(tracked){
	        // Draws the Loading background
	        Rect backgroundRect = new Rect(Screen.width/2.0f -LoadingBackground.width/2f, Screen.height/2.0f - LoadingBackground.height/2f, LoadingBackground.width, LoadingBackground.height);
	        GUI.DrawTexture(backgroundRect,LoadingBackground);
	        
	        // Draws the rotating loading spinner
	        Matrix4x4 oldMatrix = GUI.matrix;
	        float thisAngle = Time.frameCount * 4;
	
	        Rect spinnerRect = new Rect(Screen.width/2.0f -LoadingSpinner.width/2f, Screen.height/2.0f - LoadingSpinner.height/2f, LoadingSpinner.width, LoadingSpinner.height);
	    
	        GUIUtility.RotateAroundPivot (thisAngle, spinnerRect.center);
	        GUI.DrawTexture(spinnerRect, LoadingSpinner);
	        GUI.matrix = oldMatrix;
		}
    }
}

What am I doing wrong?

Creating my books JSON - iOS

April 23, 2013 - 8:44am #19

Thanks for the advice.

Creating my books JSON - iOS

April 23, 2013 - 7:18am #18

No, you cannot really presume anything here.

Each sample is unique, built to show specific functionality but on a common platform.

If you wish to combine several methods of detection it should be possible, but it may take a little more effort than "plug and play".

So really you need to try it and find out.

 

N

Creating my books JSON - iOS

April 23, 2013 - 6:49am #17

So can I presume that everything works the same as ImageTarget with an addition of CR function?

What I mean is I can follow everything in ImageTarget and mix in the CR sample.

Please correct me if I'm wrong.

Creating my books JSON - iOS

April 23, 2013 - 6:41am #16

Everything has a purpose, so it is worth spending some time to understand the sample and what each component actually does,  because it is quite complex.  This will help you decide whether you need it or can make do without it, or perhaps write one of your own.

The event handler I posted does the bare minimum and recognises a cloud target.

 

N

Creating my books JSON - iOS

April 23, 2013 - 6:35am #15

Should I re-build the AnimationManager, ContentManager andthe 2DOverLay back into the project?

I don't see the same effect as from the example initially. 

Please advise.

Thanks.

Creating my books JSON - iOS

April 23, 2013 - 6:28am #14

Have you disabled the attached model in the unity editor?

The script is there to switch it on and off at runtime, but it needs to be off to begin with.

Study the Image Targets sample and you can see how it works.

 

N

Creating my books JSON - iOS

April 23, 2013 - 6:26am #13

Hi NalinS,

I'm using the latest Unity pro version.

From the sample, I took out the 2DOverlayPosition, AnimationsManager and ContentManager as I don't think I need them initially.

I've attached the below script to CloudReco prefab. I am facing a problem with the attached model showing right at the start before the target is being scanned.

Please help.

Bryan

Creating my books JSON - iOS

February 24, 2013 - 2:00pm #12

abhishekkeshri1111,

please could you avoid bombarding the Forum with the same repeated question ?

please follow up in this thread, where it has already been answered to the possible extent:

https://developer.vuforia.com/forum/cloud-recognition/time-update-metadata

 

Creating my books JSON - iOS

February 22, 2013 - 10:32pm #11

hiiiii ,

 

Plz tell that how can we put our own json file in vuforia database.

SimpleCloudRecoEventHandler

December 26, 2012 - 2:24am #10

Ok this is a bit rough and ready - but should be ok for this time of year ;)

If you add a child cube to the cloud reco target and then attach the collowing script to the CloudRecognition prefab, rather than the existing one that deals with the books, then you may find this helpful.

If it works then basically it should enable the children of the Image Target when there is a Cloud Reco Target match i.e. the cube should show.

HTH

N

 

 

/*==============================================================================

Copyright (c) 2012 QUALCOMM Austria Research Center GmbH.

All Rights Reserved.

Qualcomm Confidential and Proprietary

==============================================================================*/

 

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

 

}

 

showing a 3D cube / teapot on a cloud based image

December 26, 2012 - 2:08am #9

Thank you for responding Nalin,

could you give an advice for this case??

I read a Thread of this case on https://developer.vuforia.com/forum/cloud-recognition/multiple-trackable-handling-question,  but I still confuse on the add script "myAugmentationObj.transform.parent = ImageTargetTemplate.gameObject.transform;" what class must be add?

how to synchronize the target and virtual object on metadata that upload to cloudreco database?

advice please....

We do not currently have a

December 26, 2012 - 1:41am #8

We do not currently have a simple sample showing a 3D cube / teapot on a cloud based image, but it is something we may look to do early in the new year if there is demand - please post this on the wishlist.

In the meantime are you using native or Unity?

N

video virtual on cloudreco

December 24, 2012 - 3:24pm #7

Thank you Nalin,
it works although not like in the cloudreco sample, because the virtual object automatic zoom in when I face my phone camera not to the marker or drag to other side.

so, if we want to show other virtual object like 3D object cube, capsule or others must be define in *.json?? is there sample of cloudreco show 3D object virtual??
can we show video as virtual object on the cloudreco?? how to do it?? I cofuse to define it in Json.

please help...

Metadata file contents

December 24, 2012 - 10:03am #6

Hi rahman,

cave.txt must contain only "samplebook1.json" - not the actual metadata itself, if you are following the sample application code and logic.

The reason is because the way the samples work is that the text contained in this file is added to the following URL (depending on whether it is the 2-0-29 or 30 release):

 

#define BOOKSJSONURL @"https://ar.qualcomm.at/samples/cloudreco/json/"

 

or

 

#define BOOKSJSONURL @"https://developer.vuforia.com/samples/cloudreco/json/"

 

...which you can see in the BooksManager.m file

The sample application then appends "samplebook1.json" to this which gets to this URL:

https://developer.vuforia.com/samples/cloudreco/json/samplebook1.json

and if you type this into a browser then you get the following:

 

{"title":"Cloud Recognition in Vuforia","author":"Karina Borland","average rating":"4","# of ratings":"41","list price":"43.99","your price":"43.15","targetid":"a47d2ea6b762459bb0aed1ae9dbbe405","thumburl":"https://developer.vuforia.com/samples/cloudreco/thumbs/01_thumbnail.png","bookurl":"https://developer.vuforia.com/samples/cloudreco/book1.php"}

Hope this makes sense, and sorry for any confusion.

N

 

 

 

 

 

 

modify cloud sample

December 24, 2012 - 1:48am #5

Hi Nalin,
Thank you for respon my question,
I have uploaded my image target and metadata to cloudreco database, but when I try to redownload my metadata its size 0 Bytes.
my target name is cave and my metadata name cave.txt, I try to change the cave.txt to cave.json but it can't be upload.
my metadata in 1 line: {"title":"Cloud Recognition in Vuforia","author":"Karina Borland","average rating":"4","# of ratings":"41","list price":"43.99","your price":"43.15","targetid":"a47d2ea6b762459bb0aed1ae9dbbe405","thumburl":"https://developer.vuforia.com/samples/cloudreco/thumbs/01_thumbnail.png","bookurl":"https://developer.vuforia.com/samples/cloudreco/book1.php"}

is there something must be changed of the metadata script?

I develop using unity 4 and vuforia 2-0-30, but I try modify sample cloudrecognition-2-0-6

Please help....
 

Hi rahman, A few questions

December 24, 2012 - 12:42am #4

Hi rahman,

A few questions for you:

  • Have you uploaded the cloud reco images to your own database?
  • Have you uploaded exactly the same metadata to your database as well?
  • Are you using native or Unity?
  • What does the log show?

Essentially the CloudReco sample requires the image in the database, plus the metadata for that image must be a single line text file containing sampleBook1.json, sampleBook2.json or sampleBook3.json.  The code then uses this to build a URL from where it gets the JSON and it then uses that to display to the user.

Hope this makes sense.

N

 

modify cloud sample

December 23, 2012 - 10:48pm #3

Hi david,

I try modify cloud demo on the key with my own client key, I hope can I can show the book virtual object with my marker, but the virtual object can't be loaded. where is the wrong??

I also confuse how to show diffrent virtual object on cloud like marker 1 show cube, marker 2 show plane, marker 3 show capsule,?

please help....

Which SDK are you using, and

December 20, 2012 - 9:21am #2

Which SDK are you using, and have you tried using your keys and JSON with the Cloud Reco sample?

The scanning behavior is configurable, you can define it to continue scanning after finding a target - it sounds like you are set-up to stop scanning after a search result.

Also please post any errors that you're seeing.

Log in or register to post comments