What are the steps necessary for me to integrate,
the latest version of OpenCV
into a pure C++(No Java Code) Android NDK project, such as Android NDK Google tutorial:
Endless-Tunnel ?
official documentation for android integration refers to much older version :OpenCV-2.4 and folder structures are no longer the same.
I am using Android Studio on Linux.
All help is highly Appreciated.
OpenCv4Android is available as a SDK with a set of samples and Javadoc documentation for OpenCV Java API. It also contains prebuilt apk-files, which you can run on your device instantly.
Android provides Native Development Kit (NDK) to support native development in C/C++, besides the Android Software Development Kit (Android SDK) which supports Java.
Code written in C/C++ can be compiled to ARM, or x86 native code (or their 64-bit variants) using the Android Native Development Kit (NDK). The NDK uses the Clang compiler to compile C/C++.
Download opencv Android package (e.g. opencv-4.0.1-android-sdk) and unpack to, say, ~/android
.
To the bottom of CMakeLists.txt, add
set( OpenCV_DIR "~/android/OpenCV-android-sdk/sdk/native/jni" )
find_package( OpenCV REQUIRED )
target_link_libraries(game opencv_java)
The package will define the following variables:
OpenCV_LIBS : The list of all imported targets for OpenCV modules.
OpenCV_INCLUDE_DIRS : The list of OpenCV include directories. With CMake >= 2.8.11 you don't even need to write
include_directories(${OpenCV_INCLUDE_DIRS})
This version of prebuilt OpenCV SDK defines also
OpenCV_VERSION : The version of this OpenCV build: "4.0.1"
OpenCV_ANDROID_NATIVE_API_LEVEL : Minimum required level of Android API: "16".
This means that your app manifest needs minSdkVersion 16 or higher (the original sample needs a fix here).
Instead of the shared library that contains all OpenCV functionality, you can use static libraries (opencv_imgcodecs, opencv_stitching, et al). These static libraries assume the default ANDROID_STL=c++_static.
For best results, use NDK r.18 or r.19.
UPDATE: NDK r.21 works well for opencv 4.3.0.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With