OpenCV-NDK icon indicating copy to clipboard operation
OpenCV-NDK copied to clipboard

[Enhancement] mapping from assets to a path suitable for OpenCV

Open floe opened this issue 5 years ago • 1 comments

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

floe avatar Aug 31 '18 07:08 floe

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!

sjfricke avatar Aug 31 '18 13:08 sjfricke