官方下载链接:
https://opencv.org/releases/
我用迅雷下载的包(opencv-4.3.0-android-sdk),下载的结构是这样的:
目录结构
---samples
---sdk
暂时我也不知道这些有什么用,后面再看看
README.android 这个文件有介绍如何使用SDK
打开里面有个链接https://docs.opencv.org/2.4/doc/tutorials/introduction/android_binary_package/O4A_SDK.html
这链接介绍是比较老的版本,不合适我们现在的版本
在多看几次目录,发现SDK有一个java目录的src,然后我们新建一个c++工程,再创建一个lib目录,包名按org.opencv创建,把相关资源目录拷贝过去,如下所示
经过搜索多个博客目前我可能需要用到simple目录工程下face-detection这个module,所以,把这个工程也拷贝到我工程进去
拷贝进去后,这里提示依赖这个project,需要改为我自己的module的名字
同时把sdk里面的native目录也拷贝到我的lib工程里面
我猜应该是这样操作吧
这报错了
E:\git_learn\AndroidOpenCVDemo\face-detection\jni\CMakeLists.txt : C/C++ debug|x86 : CMake Error at E:/git_learn/AndroidOpenCVDemo/opencvlibrary/native/jni/abi-x86/OpenCVModules.cmake:255 (message):
The imported target "libcpufeatures" references the file
"E:/git_learn/AndroidOpenCVDemo/sdk/native/3rdparty/libs/x86/libcpufeatures.a"
but this file does not exist. Possible reasons include:
* The file was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and contained
"E:/git_learn/AndroidOpenCVDemo/opencvlibrary/native/jni/abi-x86/OpenCVModules.cmake"
but not all the files it references.
Call Stack (most recent call first):
E:/git_learn/AndroidOpenCVDemo/opencvlibrary/native/jni/abi-x86/OpenCVConfig.cmake:146 (include)
E:/git_learn/AndroidOpenCVDemo/opencvlibrary/native/jni/OpenCVConfig.cmake:44 (include)
CMakeLists.txt:8 (find_package)
E:\git_learn\AndroidOpenCVDemo\face-detection\jni\CMakeLists.txt : C/C++ debug|x86 : Configuration failed.
executing external native build for cmake E:\git_learn\AndroidOpenCVDemo\face-detection\jni\CMakeLists.txt
直接把sdk拷贝到工程里面吧,,,简单粗暴,先把工程跑的来再说
现在报找不到类:
import org.opencv.engine.OpenCVEngineInterface;
在org.opencv.engine这个包名存在一个aidl的类,所以需要新建aidl目录来存放
最后选择就能运行起来,由于权限问题,需要手动打开权限来测试吧
最后GitHub的地址:https://github.com/moz1q1/AndroidOpenCVDemo