Log in or register to post comments

Swapping DataSets

August 7, 2012 - 6:35am #1

This should be a really basic question but due to the lack of resources on the forum and the dev guides I am kind of stuck at this problem.

I am having troubles with understanding the code snippets available at the forums. Can anybody explain me the steps for a simple workflow like loading and activating dataset from definite path (be it QCAR\*.xml). What Scripts would i need to remove in order to write my own dataset load scripts. 

My ARCamera has DataSetLoadBehaviour script and ImageTarget has ImageTargetBehaviour script attached. How do these two scripts work and am I gonna replace these two scripts?

 All in all I am in grave need of a tutorial which obviously is missing. 

 

Please help!

Swapping DataSets

November 7, 2012 - 11:35pm #17

Oh Thanks for clarifying me on that....

And i guess the app is running good now because of your valuable reply.....

I was wrongly using Gameobject.Find("parent"), whereas i need to use Gameobject.Find("ImageTarget")......Now it is able to track the image prettty well...

And also i will go through the Vuforia Documentation as soon as possible....

Thanks a lot udaan...You made the day Cool

Swapping DataSets

November 7, 2012 - 11:23pm #16

studying your code carefully now...here are some pointer:-

The "imageTracker.CreateDataSet" will create an empty dataset hence there will be no trackables in your dataset at that time...

the "dataset.Load" will load the dataset from the absolute path to your empty dataset....then only you should get the GetNumTrackables....

The SDK Documentation is really informative and all of my code is derived from there.....

Swapping DataSets

November 7, 2012 - 10:51pm #15

Thanks a lot Udaan.

I found that. But here the dataset i loaded says it doesnt have any trackables at all....If possible can you please have a look on this thread...

https://ar.qualcomm.at/content/dynamically-load-unity-trackable-file-web#comment-2017388

Your help and reply is much appreciated...Thank you.

Swapping DataSets

November 7, 2012 - 9:52pm #14

The DefaultTrackableEventHandler prints out the name of the trackable found...see under onTrackingfound function in DefaultTrackableEventHandler....you can use your custom event handler also but use only one event handler.

In the code where its written GameObject.find("Parent")---this is for finding a gameObject "Parent" in the Hierarchy and then binding it to the image trackers... make sure you have a code that goes along with your hierarchy....

I used this code in the Start() function of the script since i needed it only when application starts... 

Swapping DataSets

November 7, 2012 - 2:34am #13

And please find the code slice i followed from yours,

void LoadAndActivateDataSet(string dataSetPath)

{

if (TrackerManager.Instance.GetTracker(Tracker.Type.IMAGE_TRACKER)==null)

{

TrackerManager.Instance.InitTracker(Tracker.Type.IMAGE_TRACKER);

Debug.Log ("InitTracker");

}

if(!DataSet.Exists(dataSetPath,DataSet.StorageType.STORAGE_ABSOLUTE))

{

if(File.Exists(dataSetPath))

{

Debug.Log("File Exist");

}

Debug.Log("Data Set "+dataSetPath+" does not exist.");

return; }

Debug.Log("Data set Exist");

 

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

DataSet dataSet = imageTracker.CreateDataSet();

if (dataSet != null)

        {

            for (int i = 0; i < dataSet.GetNumTrackables(); i++)

            {

                TrackableBehaviour tb = dataSet.GetTrackable(i);

                if (tb.CurrentStatus == TrackableBehaviour.Status.DETECTED ||

                    tb.CurrentStatus == TrackableBehaviour.Status.TRACKED)

                {

                    Debug.Log("Target " + tb.TrackableName + " is tracked at " + tb.transform.position + 

                              " with rotation " + tb.transform.rotation);

                }

            }

        }

if(!dataSet.Load(dataSetPath,DataSet.StorageType.STORAGE_ABSOLUTE))

{ Debug.Log("Failed to load data set"+dataSetPath+".");

return;

}

Debug.Log("Successfully Activated the Dataset");

imageTracker.ActivateDataSet(dataSet);

for(int i =0; i<dataSet.GetNumTrackables();i++)

{

DataSetTrackableBehaviour dstb = dataSet.GetTrackable(i);

GameObject go = dstb.gameObject;

go.AddComponent<DefaultTrackableEventHandler>();

GameObject parent = GameObject.Find ("Parent");

parent.transform.parent= dstb.transform;

parent.transform.localScale = new Vector3 (70f,70f,70f);

parent.transform.localPosition = new Vector3 (0.0f,0.35f,0.0f);

parent.transform.localRotation=Quaternion.identity;

parent.active=true;

dstb.gameObject.active=true;

} }

Swapping DataSets

November 7, 2012 - 2:24am #12

Thanks a lot for your very quick reply....

The problem is i dint check it again with the device instead checked in the system which causes the problem...so when i try it with device, it is able to identify the dataset....

And one more final doubt, now if i capture the image it is not able to identify and print like "Image 2" found like it will do if i add it as a image target. 

What i have to do to recognize the image and print like "Image 2 Found" and "Image 2 Lost" ?? Please suggest..

Thanks in advance.

Swapping DataSets

November 6, 2012 - 11:40pm #11

the path i used was "/mnt/sdcard/your_folder_name/yourdataset.xml"

you wil have to point towards the xml file and the .dat and .xml should be in same directory. The code I posted here does not check for any activated datasets...it just  activates a dataset on a specified path....so in that case you'll have to make sure no dataset is activated for this I didn't exactly removed the scripts i just passed (selected in the editor) null values....

 

hope this helps

Swapping DataSets

November 6, 2012 - 11:25pm #10

Hi udaan,

Can you please specify the dataset path used ?? ( ex - "/mnt/android/mydata.xml" or  "D:/data:/mydata.dat")

Because i tried with your code and placed my dataset(.dat and .xml) files in a folder but Vuforia could not recognize it as a valid Dataset...

And do i really need to remove "DataSetLoadBehaviour and ImageTargetBehaviour scripts" ???

I just want to make sure...

Thanks in advance...

Swapping DataSets

August 13, 2012 - 3:50am #9

I finally did it with the following code

Quote:

void LoadAndActivateDataSet(string dataSetPath)

{

if (TrackerManager.Instance.GetTracker(Tracker.Type.IMAGE_TRACKER)==null)

{

TrackerManager.Instance.InitTracker(Tracker.Type.IMAGE_TRACKER);

Debug.Log ("InitTracker");

}

if(!DataSet.Exists(dataSetPath,DataSet.StorageType.STORAGE_ABSOLUTE))

{

Debug.Log("Data Set"+dataSetPath+"does not exist.");

return;

}

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

DataSet dataSet = imageTracker.CreateDataSet();

if(!dataSet.Load(dataSetPath,DataSet.StorageType.STORAGE_ABSOLUTE))

{

Debug.Log("Failed to load data set"+dataSetPath+".");

return;

}

for(int i =0; i<dataSet.GetNumTrackables();i++)

{

DataSetTrackableBehaviour dstb = dataSet.GetTrackable(i);

GameObject go = dstb.gameObject;

go.AddComponent<DefaultTrackableEventHandler>();

GameObject parent = GameObject.Find ("Parent");

parent.transform.parent= dstb.transform;

parent.transform.localScale = new Vector3 (0.7f,0.7f,0.7f);

parent.transform.localPosition = new Vector3 (0.0f,0.35f,0.0f);

parent.transform.localRotation=Quaternion.identity;

parent.active=true;

 

dstb.gameObject.active=true;

}

imageTracker.ActivateDataSet(dataSet);

 

}

The problem was in the path string.I was giving the path as a WWW class would expect.Plus I had to remove the DataSetLoadBehaviour and ImageTargetBehaviour scripts to get this to work...still confused about the workflow of these things . Thanks for the support! Smile

 

Swapping DataSets

August 10, 2012 - 10:47pm #8

This is the code that I am using

Quote:

 

private void SwapDataSet () {

 

 

 

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

if(imageTracker != null)

{

 

string dataSetPath = "file:///mnt/sdcard/AssetBundles/Fanta.xml";

if(!DataSet.Exists(dataSetPath,DataSet.StorageType.STORAGE_ABSOLUTE))

{

Debug.LogError("DataSet Does Not Exist");

}

DataSet dataSet = imageTracker.CreateDataSet();

dataSet.Load (dataSetPath,DataSet.StorageType.STORAGE_ABSOLUTE);

imageTracker.ActivateDataSet(dataSet);

int markeramount = dataSet.GetNumTrackables();

for (int i = 0;i < markeramount;i++)

{

        DataSetTrackableBehaviour dstb = dataSet.GetTrackable(i);

GameObject go = dstb.gameObject;

go.AddComponent<DefaultTrackableEventHandler>();

GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);

cube.transform.parent = dstb.transform;

cube.transform.localScale=new Vector3(0.7f,0.7f,0.7f);

cube.transform.localPosition = new Vector3(0.0f, 0.35f, 0.0f);

   cube.transform.localRotation = Quaternion.identity;

cube.active=true;

   dstb.gameObject.active=true;

 

 

}

}

   }

Are there any changes to the behaviour scripts that i want to make. Am I missing something?

Swapping DataSets

August 10, 2012 - 3:37am #7

Ok I read and tried the ImageTarget sample package for unity and successfully swapped between my datasets. Now my doubt is that we are finding and loading the DataSet from the editor.Thus I'll be needing Multiple ImageTarget Prefabs in my scene.

But my requirements are to load the .xml and .dat from an SDcard. I know its doable but I haven't got any headstart with it. I am activating dataSets like this

imageTracker.ActivateDataSet(imageTracker.GetDataSet(int));

But what if I want to Load a Single DataSet(from SDcard or doucuments directory) at runtime while my scene should always contain single ImageTarget prefab.

Any suggestions please!

Swapping DataSets

August 9, 2012 - 3:07am #6

I don't have any code right now as I am stuck with another problem in my app.I'll surely post the codes that I was trying to implement once I rectify this other problem that I am having. In the meantime I'll brush up my skills on Event Handlers so that I can understand your suggestions.

 

Thanks for the support! 

Swapping DataSets

August 9, 2012 - 2:55am #5

I don't have any code right now as I am stuck with another problem in my app.I'll surely post the codes that I was trying to implement once I rectify this other problem that I am having. In the meantime I'll brush up my skills on Event Handlers so that I can understand your suggestions.

 

Thanks for the support! 

Swapping DataSets

August 8, 2012 - 4:55pm #4

You can add them in your event handler as you are now. And you should retain the DataSetLoadBehaviour to load your datasets, and can the implement your own logic for activating and deactivating them. Feel free to post the code your using for some tips.

Swapping DataSets

August 7, 2012 - 10:14pm #3

Ok I read the AR Developer Guide thoroughly and what i understand is that I'll have to use TrackerManager,DataSet and ImageTracker classes to runtime change the dataset. That said I couldn't understand the code snippet "Adding content to a trackable".

First we are adding Trackable Event Handler,that's ok.But can I ommit adding a Cube(or any GameObject)? As I already am adding objects dynamically to the ImageTargets through a custom script which uses "DefaultTrackableEventHandler" to show/hide my GameObject when the tracking is found/lost. 

My Project Setup is currently using DataSetLoadBehaviour to load the dataset and If swap datasets dynamically I think I'll need to Disable this script and add the custom scripts.

Sorry if my doubts are really noob but I am newbie so some wisdom words from your side might really be helpful for me and for others out there like me :).

Swapping DataSets

August 7, 2012 - 7:51am #2

You won't need to modify either of those scripts. The section on Swappable Datasets under Mastering Advanced Topics in the SDK guide addressses loading and activating datasets - https://ar.qualcomm.at/sdk

You can also also use the API documentation. The Unity API derives from the core API - https://ar.qualcomm.at/api

In your case, you'll be using STORAGE_ABSOLUTE

When developing Vuforia apps, customization and extension of the SDK is typically accomplished by implementing custom event handlers, rather than revising the behaviors.

Log in or register to post comments