opencv - How to access a file by its path within a shared library plugin with a Unity Android App -
i have written native shared library (.so) in android studio uses opencv cascade classifiers. classifiers have load method requires path file , must called before can used.
i can call load method correctly in android studio first placing required files in res/raw directory of project. create file resource in android app uses shared library:
inputstream = context.getresources().openrawresource(r.raw.lbpcascade_frontalface); file rsrcdir = context.getdir("rsrc", context.mode_private); file rsrc = new file(rsrcdir, "lbpcascade_frontalface.xml"); fileoutputstream os = new fileoutputstream(rsrc); byte[] buffer = new byte[4096]; int bytesread; while ((bytesread = is.read(buffer)) != -1) { os.write(buffer, 0, bytesread); } is.close(); os.close(); return rsrc;
in shared library (c++) can access file following path:
/data/data/com.company.product/app_rsrc/lbpcascade_frontalface.xml
and works charm.
but need use shared library unity. i've been able access contents of file, resides in "streamingassets" folder, using following script:
ienumerator loadrsrcs() { var filepath = system.io.path.combine(application.streamingassetspath, "lbpcascade_frontalface.xml"); if (filepath.contains("://")) { var www = new www(filepath); yield return www; result = www.text; } }
and result holds contents of "lbpcascade_frontalface.xml" after www object has extracted file data apk file.
but, how pass file path shared library? can't pass filepath variable because prefixed jar:file://. i.e:
"jar:file://" + application.datapath + "!/assets/";
i guess first need write contents file object in unity script somehow , pass path file object i've done in android studio. without context object android api provides, how that?
any help/advice appreciated, or if can suggest better method of achieving same result i'm ears!
Comments
Post a Comment