如何将 OpenCV 4.0 集成到纯 C++ Android NDK 项目中? [英] How can I integrate OpenCV 4.0 into a pure C++ Android NDK project?
问题描述
我集成需要哪些步骤,
变成一个纯C++(无Java代码)Android NDK项目,比如Android NDK谷歌教程:
into a pure C++(No Java Code) Android NDK project, such as Android NDK Google tutorial:
无尽隧道?
官方文档 android 集成参考很多旧版本:OpenCV-2.4 和文件夹结构不再相同.
official documentation for android integration refers to much older version :OpenCV-2.4 and folder structures are no longer the same.
我在 Linux 上使用 Android Studio.
I am using Android Studio on Linux.
非常感谢所有帮助.
推荐答案
下载opencv Android 包(例如opencv-4.0.1-android-sdk) 并解压到例如
~/android
.
到 CMakeLists.txt,添加
set( OpenCV_DIR "~/android/OpenCV-android-sdk/sdk/native/jni" )
find_package( OpenCV REQUIRED )
target_link_libraries(game opencv_java)
该包将定义以下变量:
OpenCV_LIBS : OpenCV 模块的所有导入目标的列表.
OpenCV_LIBS : The list of all imported targets for OpenCV modules.
OpenCV_INCLUDE_DIRS : OpenCV 包含目录的列表.使用 CMake >= 2.8.11 你甚至不需要写
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})
此版本的预构建 OpenCV SDK 还定义了
This version of prebuilt OpenCV SDK defines also
OpenCV_VERSION : 此 OpenCV 构建的版本:4.0.1"
OpenCV_VERSION : The version of this OpenCV build: "4.0.1"
OpenCV_ANDROID_NATIVE_API_LEVEL:Android API 的最低要求级别:16".
OpenCV_ANDROID_NATIVE_API_LEVEL : Minimum required level of Android API: "16".
这意味着您的应用清单需要 minSdkVersion 16 或更高(原始示例需要修复 此处).
This means that your app manifest needs minSdkVersion 16 or higher (the original sample needs a fix here).
您可以使用静态库(opencv_imgcodecs、opencv_stitching、等)代替包含所有 OpenCV 功能的共享库.这些静态库采用默认的ANDROID_STL=c++_static.
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.
为获得最佳效果,请使用 NDK r.18 或 r.19.
For best results, use NDK r.18 or r.19.
更新: NDK r.21 适用于 opencv 4.3.0.
UPDATE: NDK r.21 works well for opencv 4.3.0.
这篇关于如何将 OpenCV 4.0 集成到纯 C++ Android NDK 项目中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!