OpenCV 开发之——人脸识别库生成 so 文件
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
#OPENCV_INSTALL_MODULES:=off
#OPENCV_LIB_TYPE:=SHARED
ifdef OPENCV_ANDROID_SDK
ifneq ("","(OPENCV_ANDROID_SDK)/OpenCV.mk)")
include ${OPENCV_ANDROID_SDK}/OpenCV.mk
else
include ${OPENCV_ANDROID_SDK}/sdk/native/jni/OpenCV.mk
endif
else
include ../../sdk/native/jni/OpenCV.mk
endif
LOCAL_SRC_FILES := DetectionBasedTracker_jni.cpp
LOCAL_C_INCLUDES += $(LOCAL_PATH)
LOCAL_LDLIBS += -llog -ldl
LOCAL_MODULE := detection_based_tracker
include $(BUILD_SHARED_LIBRARY)
ndk-build 编译 face-detection/jni 文件
在项目/jni 上右键—>Open In—>Terminal
在打开后的终端,执行
ndk-build
指令
Android NDK: android-8 is unsupported. Using minimum supported version android-14.
Android NDK: WARNING: APP_PLATFORM android-14 is higher than android:minSdkVersion 1 in D:/Code/Android/OpenCV-android-sdk-453/samples/face-detection/AndroidManifest.xml. NDK binaries will not be comptible with
devices older than android-14. See https://android.googlesource.com/platform/ndk/+/master/docs/user/common_problems.md for more information.
D:/Code/Android/OpenCV-android-sdk-453/samples/face-detection/jni/Android.mk:14: ../../sdk/native/jni/OpenCV.mk: No such file or directory
make: *** No rule to make target `../../sdk/native/jni/OpenCV.mk'. Stop.
根据提示信息做如下修改
Android.mk
include ../../sdk/native/jni/OpenCV.mk 修改为 include ../../../sdk/native/jni/OpenCV.mk
#LOCAL_SRC_FILES := DetectionBasedTracker_jni.cpp(注释掉)
Application.mk
APP_ABI := armeabi-v7a 修改为 APP_ABI := armeabi-v7a arm64-v8a
重新执行
ndk-build
执行,libs 和 obj 文件夹下生成对应的 so 文件
2.2 cmake 编译
Cmake 运行环境
官网下载地址:https://cmake.org/download/
环境变量配置
path=D:\SoftWare\cmake-3.18.2-win64-x64
path=C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\Hostx64\x64
Cmake 构建文件
CMakeLists.txt:编译配置工具
终端执行 camek 指令
jni 文件夹下新建 build 文件夹(用于 cmake 指令的生成目录)
右键 build,依次选择:Open In——>Terminal,在终端中打开 build
在终端中执行如下 cmake 指令
cmake .. -DOpenCV_DIR=......\sdk\native\jni\abi-arm64-v8a -DANDROID_TOOLCHAIN=clang -DANDROID_STL=c++_shared
指令说明:
..
表示执行上一层目录下的 CMakeLists.txt 文件OpenCV_DIR,ANDROID_TOOLCHAIN,ANDROID_STL 表示 build.gradle 中执行 cmake 时传递进来的参数,用等号链接
执行后的效果图
cmake-gui.exe 执行编译
找到 cmake 安装目录,打开 cmake-gui
分别选择 source code 和 build 生成文件夹
点击 Configure 按钮,在弹出的对话框中设置对应选项
按照配置检查有无错误
| 编译错误 | 错误原因 |
| :-: | --- |
|
|
|
修改 OpenCV_DIR 后重新执行 Configure 按钮,检查是否有错误
点击 Generate,查看 build 目录下生成内容
评论