Log in or register to post comments

storing dataset on sd card

July 17, 2012 - 8:27am #9

Hello!

I would like to store the datasets on the sd card. This way i will be able to change them without having to reinstall the application. The question is, how can i reach the sd card from the native code? As i understand this is how the dataset loads from the assets folder: dataSetStonesAndChips->load(s, QCAR::DataSet::STORAGE_APPRESOURCE). The problem is that the assets folder is read-only during runtime, so i cannot change the datasets there, that's why i have to use the sd card.

Thanks

storing dataset on sd card

July 17, 2012 - 8:44am #8

To access the SDCard you can use STORAGE_ABSOLUTE and specify an absolute path to the datasets. This will typically be /sdcard/.. but you should confirm this as not all devices use the same path.

see:

https://ar.qualcomm.at/sites/default/files/docs/qcarsdk/class_q_c_a_r_1_1_data_set.html

   

storing dataset on sd card

July 17, 2012 - 11:22am #7

How should i declare the parameter? I modified the native loadTrackerData method and added a const char* extra parameter as the absolute path to the dataset file. I have to right path, because i get it with Environment.getExternalStorageDirectory(). In the ImageTargets Activity i tried both String and CharSequence types for the extra parameter, but none of them seems to work. I get the "Dataset file ???@ not found. DetectorNFT4_DataSet::beginModify(): Dataset is already in modify state. Failed to load dataset '???@'." error. 

storing dataset on sd card

July 17, 2012 - 3:21pm #6

I have found the solution. It wasn't working because the java and the c objects are not compatible with each other. I had to convert the Java object (jstring) into a c object (const char*). The ndk has methods for conversion. Now it's working.

storing dataset on sd card

September 12, 2012 - 1:50am #5

I'm trying to manage same thing, but i have a problem with saving path.

I'm saving tracker to this path on java:

Environment.getExternalStorageDirectory() + "/" + Augmented+ "/" + fileName

But the problem is in ImageTarget.cpp i cannot use Environment.getExternalStorageDirectory()... How can i declare the right path on ImageTarget.cpp?

Thanks in advance,

yaya

storing dataset on sd card

September 12, 2012 - 3:59am #4

Ok. I've managed that by transfering string to native code in ImageTargets.java by changing loadTrackerData method:


/** Native functions to load and destroy tracking data. */

public native int loadTrackerData(String fileName);

 

// Load the tracker data set:

String path = Environment.getExternalStorageDirectory() + "/Augmented/Train.xml";

return (loadTrackerData(path) > 0);

  

And then i changed ImageTargets.cpp like this:

 

JNIEXPORT int JNICALL

Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargets_loadTrackerData(JNIEnv *env, jobject, jstring fileName) {

...

const char *nativeString = env->GetStringUTFChars(fileName, 0);

if(!dataSetTrain->load(nativeString, QCAR::DataSet::STORAGE_ABSOLUTE)) {

    LOG("Failed to load data set.");

    return 0;

    }

    env->ReleaseStringUTFChars(fileName, nativeString);

...

}

 

And that's it :)

storing dataset on sd card

September 24, 2012 - 1:33pm #3

this is useful, thanks..

but can you help me in making reading datasets dynamically from a list of XMLs which changing from time to time, i can send the xml file name as you explained by doin this with an action on a menu item, but i need help how can i apply that in the .cpp code?

storing dataset on sd card

September 24, 2012 - 5:07pm #2

 

You should parse the XML document in Java, to obtain the paths of your datasets, and then pass these using the approach the yaya has demonstrated below.

storing dataset on sd card

March 26, 2013 - 4:45am #1
In your code for the xml file what if the file loaded from the databaser server is another name

example Train2.xml

how can you know dynamically the name for the new xml to be loaded?

 

 


String path = Environment.getExternalStorageDirectory() + "/Augmented/Train.xml";

return (loadTrackerData(path) > 0);

 

 

 

 

Log in or register to post comments