[Enhancement] mapping from assets to a path suitable for OpenCV
floe opened this issue · comments
Florian Echtler commented
Thanks for your code, found it very helpful to understand the convoluted NDK camera API. In return, I may have a possible solution for your asset issue: I came across the same problem, i.e. how to properly load the haar cascade files on Android, and you can solve that at runtime (see also https://github.com/mmbuw/mis-2018-exercise-4-opencv/blob/master/app/src/main/java/com/example/mis/opencv/MainActivity.java#L129-L139):
public String initAssetFile(String filename) {
File file = new File(getFilesDir(), filename);
if (!file.exists()) try {
InputStream is = getAssets().open(filename);
OutputStream os = new FileOutputStream(file);
byte[] data = new byte[is.available()];
is.read(data); os.write(data); is.close(); os.close();
} catch (IOException e) { e.printStackTrace(); }
Log.d(TAG,"prepared local file: "+filename);
return file.getAbsolutePath();
}
Still a hack, but oh well... ;-)
Regards, Florian
Spencer Fricke commented
Glad it helped and I like this approach, it's still a hack, but a much more manageable hack, hopefully have time soon to implement it. Thanks for the idea!