问题描述:

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.

相关阅读:
Top