问题
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,
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)
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()?
- 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