1

I have been using OpenCV for Android for a long time. It works fine, so far. But now I want to improve the performance and I want to go native. However, even native development itself is a little complicated for me in Android. Now I got the point of it and I can build simple applications by myself.

The point that I am stuck is how to add those libraries and include files in "native" folder of OpenCV Android package.

NOTE:I do not intent to create native application, but use only OpenCV as native. Other parts will still be java

Long story short, I just don't want to call native OpenCV methods with Java wrapper, but instead do everything related to OpenCV in native and then get the result to Java part.

Thanks for any efford in advance.

zgrkpnr89
  • 325
  • 1
  • 6
  • 17

1 Answers1

4

If you are not using OpenCV from Java at all, the best option is to include the libraries by linking statically with them, and then removing dead code, symbols, etc, to keep the native library size under control. Having to download an additional package is something many users don't like.

Just include

OPENCV_LIB_TYPE:=STATIC
OPENCV_CAMERA_MODULES:=off
include path/to/opencv/sdk/native/jni/OpenCV.mk

in your Android.mk.

Have a look at the OpenCV Android documentation here.

user1906
  • 2,310
  • 2
  • 20
  • 37
  • Well, you made a great point. After Android Studio 1.3 ndk support, there is no Android.mk . Or I couldn't find it. In the samples came with ndk support Android.mk does not exist. – zgrkpnr89 Jul 13 '15 at 23:09
  • I see. I checked the examples and I couldn't find any reference to using an already build library. Check this answer, this may still work: http://stackoverflow.com/questions/23935193/gradle-ndk-to-specify-an-include-directive-in-generated-android-mk?rq=1 – user1906 Jul 13 '15 at 23:17
  • You can disable AS ndk support and add a task to compile you native code with command line. By doing this you will still use Android.mk and the answer of @user1906 will work – sonic Jul 15 '15 at 08:23
  • Really helpful answer. Thank you. – 9301293 Sep 28 '16 at 21:42