问题
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.
回答1:
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) get_target_property(__src opencv_java IMPORTED_LOCATION_RELEASE ) add_custom_command(TARGET game POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${__src} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY} )
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.
I have opened a feature request for Android NDK to provide better support for imported shared libraries.
来源:https://stackoverflow.com/questions/54967251/how-can-i-integrate-opencv-4-0-into-a-pure-c-android-ndk-project