Using opencv FileStorage native in android

╄→гoц情女王★ 提交于 2019-12-20 07:21:45

问题


I am trying to write an android applications witch calculates keypoints and descriptors using opencv and store them. However i am getting troubles with cv:FileStorage. I am actually passing the file path throw native methods. The same path (different file ending) is also used to store another file on the javaside.

JNIEXPORT void JNICALL Java_com_..._CalcFeatures(JNIEnv* env, jobject, jlong addrGray, jstring location){
...
const char *nativeString = env->GetStringUTFChars(location, NULL);
string filepath=string(nativeString);
FileStorage fs(filepath, FileStorage::WRITE);
fs<<"frameCount"<<5;
fs.release();
...
}

LogCat output:

Fatal signal 11 (SIGSEGV) at 0x000009f4 (code=19), thread 23789 

I also tryed to hardcode the path (like „/sdcard/test.xml“ or „/storage/emulated/0/text.xml“). If I am using “test.xml” as filepath, I don’t get any errors, but I am not able to find the file on my phone (HTC One).

Any advices?

Thanks for your time.

UPDATE:

this works just fine, so there is a problem with FileStorage. Is there any other way in opencv to parse it to an xml/json format? perhaps with string as result?

FILE* file = fopen(nativeString,"w+");
fputs("hello, world\n", file);
fclose(file);

回答1:


I've asked similar question here: imread returns empty matrix while ifstream can open and read the same file and I found that even if I can manipulate file from native part, I cant use opencv's FileStorage.

And that's why I'm not able to load matrix,cascade classifier,etc.

I also tried load data from file to memory and create FileStorage from memory, it created for writing, but it does not works (while it works on windows perfectly). I cant access to any node.



来源:https://stackoverflow.com/questions/23679508/using-opencv-filestorage-native-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!