两种方式集成SDK
1.使用java API 依赖sdk,libs下依赖opencv_java?.so
build.gradle
implementation project(':openCVLibrary330')
//来自sdk/java 目录
//复制 sdk/native/libs 到项目中
sourceSets {
main {
jniLibs.srcDirs = ['libs']
}
}
//application 或者 activity 里左初始化
private void iniLoadOpenCV() {
boolean success = OpenCVLoader.initDebug();
if(success) {
Log.i(CV_TAG, "OpenCV Libraries loaded...");
} else {
Toast.makeText(this.getApplicationContext(), "WARNING: Could not load OpenCV Libraries!", Toast.LENGTH_LONG).show();
}
}
1.使用c++ API,集成.a 文件到自己的so库
CMakeLists.txt
cmake_minimum_required(VERSION 3.4.1)
# ##################### OpenCV 环境 ############################
#设置OpenCV-android-sdk路径
set( OpenCV_DIR D:\\work\\opencv-4.3.0-android-sdk\\OpenCV-android-sdk\\sdk\\native\\jni )
find_package(OpenCV REQUIRED )
if(OpenCV_FOUND)
include_directories(${OpenCV_INCLUDE_DIRS})
message(STATUS "OpenCV library status:")
message(STATUS " version: ${OpenCV_VERSION}")
message(STATUS " libraries: ${OpenCV_LIBS}")
message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")
else(OpenCV_FOUND)
message(FATAL_ERROR "OpenCV library not found")
endif(OpenCV_FOUND)
# ###################### 项目原生模块 ###########################
add_library( native-lib
SHARED
src/main/cpp/native-lib.cpp src/main/cpp/native-opencv.cpp)
target_link_libraries( native-lib
${OpenCV_LIBS}
log
jnigraphics)
网友评论