NDK and OpenCV setup in Android Studio

南楼画角 提交于 2019-12-11 05:34:49

问题


I imported the module "OpenCV for Android" into Android Studio and I tried to implement my image processing features in Java code.

Most of the OpenCV methods like Core.multiply and Core.add work fine, however, I found that some OpenCV methods like Mat.put() and Mat.get() are not quite efficient, and the program run really slow in my device.

So, my questions are,

  1. If I set up NDK in Android Studio, would this make my program run faster? (I think the program would be more efficient if I use pointer in C++, I am not sure if this is correct)

  2. I use the OpenCV methods Mat.get() and Mat.put() in this way,


    Bitmap bitmap = BitmapFactory.decodeResource(this.getResources(), R.drawable.testPhoto);
    Mat m1 = new Mat(bitmap.getHeight(), bitmap.getWidth(), CvType.CV_8UC4);
    Mat m2 = m1.clone();
    Utils.bitmapToMat(bitmap, m1);
    byte[] arr = new byte[(int)(m1.total() * m1.channels())];
    m1.get(0,0,arr);
    //some processing here...
    m2.put(0,0,arr);

So, is there any more efficient way to use the Mat.get() and Mat.put()?

  1. If using NDK is a better way, how can I set up both OpenCV and NDK in a Android project? I tried to follow this tutorial to set up NDK in Android Studio, but once I set up NDK, I could not import OpenCV into my project.

回答1:


To setup OpenCV and NDK, first you import OpenCV library as module in your android project and add it as dependencies. Then you can research how to setup the Android NDK.

After getting image as input through BitmapFactory and conveting into Mat, you can process the image in NDK, that makes program to run faster and efficient.



来源:https://stackoverflow.com/questions/39461996/ndk-and-opencv-setup-in-android-studio

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