下载opencv for android的包4.6.0解压
https://opencv.org/releases.html
android {
ANDROID_OPENCV = E:/opencv-4.6.0-android-sdk/OpenCV-android-sdk/sdk/native
INCLUDEPATH += $$ANDROID_OPENCV/jni/include/opencv2 \
$$ANDROID_OPENCV/jni/include
LIBS += $$ANDROID_OPENCV/libs/armeabi-v7a/libopencv_java4.so \
$$ANDROID_OPENCV/staticlibs/armeabi-v7a/libopencv_calib3d.a \
$$ANDROID_OPENCV/staticlibs/armeabi-v7a/libopencv_core.a \
$$ANDROID_OPENCV/staticlibs/armeabi-v7a/libopencv_dnn.a \
$$ANDROID_OPENCV/staticlibs/armeabi-v7a/libopencv_features2d.a \
$$ANDROID_OPENCV/staticlibs/armeabi-v7a/libopencv_flann.a \
$$ANDROID_OPENCV/staticlibs/armeabi-v7a/libopencv_highgui.a \
$$ANDROID_OPENCV/staticlibs/armeabi-v7a/libopencv_imgcodecs.a \
$$ANDROID_OPENCV/staticlibs/armeabi-v7a/libopencv_imgproc.a \
$$ANDROID_OPENCV/staticlibs/armeabi-v7a/libopencv_ml.a \
$$ANDROID_OPENCV/staticlibs/armeabi-v7a/libopencv_objdetect.a \
$$ANDROID_OPENCV/staticlibs/armeabi-v7a/libopencv_photo.a \
$$ANDROID_OPENCV/staticlibs/armeabi-v7a/libopencv_stitching.a \
$$ANDROID_OPENCV/staticlibs/armeabi-v7a/libopencv_video.a \
$$ANDROID_OPENCV/staticlibs/armeabi-v7a/libopencv_videoio.a \
$$ANDROID_OPENCV/3rdparty/libs/armeabi-v7a/libcpufeatures.a \
$$ANDROID_OPENCV/3rdparty/libs/armeabi-v7a/libIlmImf.a \
$$ANDROID_OPENCV/3rdparty/libs/armeabi-v7a/liblibjasper.a \
$$ANDROID_OPENCV/3rdparty/libs/armeabi-v7a/liblibjpeg-turbo.a \
$$ANDROID_OPENCV/3rdparty/libs/armeabi-v7a/liblibpng.a \
$$ANDROID_OPENCV/3rdparty/libs/armeabi-v7a/liblibprotobuf.a \
$$ANDROID_OPENCV/3rdparty/libs/armeabi-v7a/liblibtiff.a \
$$ANDROID_OPENCV/3rdparty/libs/armeabi-v7a/liblibwebp.a \
$$ANDROID_OPENCV/3rdparty/libs/armeabi-v7a/libquirc.a \
$$ANDROID_OPENCV/3rdparty/libs/armeabi-v7a/libtbb.a \
$$ANDROID_OPENCV/3rdparty/libs/armeabi-v7a/libtegra_hal.a
}
编译Android opencv
使用文件
1、QT VS2017安装选项
设置环境变量
2、安装ANT
官网下载:http://ant.apache.org/bindownload.cgi
文件解压到目标文件夹后设置环境变量
添加:ANT_HOME 到安装根路径
配置path:PATH = %ANT_HOME%/bin
在CMD下运行命令检查安装是否完成
ant -version
3、组织编译
3.1在目标文件夹内新建Android-opencv文件夹用来存放编译完成的文件
3.2点击 add entry 添加string类型数据
ANDROID_ABI armeabi-v7a
ANDROID_PLATFORM 26
3.3点击 configure设置编译环境,点击next
3.4在toolchain file中选择ndk中的android.toolchain.cmake,点击finish
3.5 configure结束后报错问题解决
3.6去掉BUILD_ANDROID_PROJECTS BUILD_ANDROID_EXAMPLES两项重新configure
未来版本将删除与CMake < 2.8.12的兼容性CMake。更新VERSION参数值或使用…后缀告诉CMake项目不需要与旧版本兼容,修改对应cmakelists.txt内的cmake版本
安装python git
3.7修改配置选项
去掉例程
静态库生成目录
是否生成动态库
添加贡献库,具体到moudles目录
将所有的库编译到一个文件中
调用本地摄像头
添加移动端的并行架构支持
以下参数根据需求调整
BUILD_ANDROID_PROJECTS 不需要示例项目可直接取消勾选
BUILD_ANDROID_EXAMPLES = OFF
BUILD_PERF_TESTS = OFF
BUILD_TESTS = OFF
BUILD_opencv_world = OFF (生成 .so 库 libopencv_java4.so,这是一个集合,不清楚和默认编译的 libopencv_java4.so 有什么区别,默认不开启,如果开启的话不会复制 java 层函数,也就是 cmake 的 gui 界面会显示 Java wrappers: NO)
BUILD_SHARED_LIBS = OFF (如果 On 则只编译 so 库)
WITH_CUDA = OFF (CUDA 是 NVidia 推出的并行计算架构,编译非安卓 SDK 时建议添加)
WITH_OPENCL = ON (因为我们编译的是 android sdk,所以建议添加移动端的并行架构支持)
WITH_OPENCL_SVM = ON (建议开启共享虚拟内存)
调整完后再次点击Configure,完成后点击Generate。
部分选项可能需要多点几次才能出现
继续点击configure(可以多点几次,有时多点几次就可以下载成功),
安卓raw.githubusercontent.com无法访问问题
安卓程序运行时报出:
unknown host ‘raw.githubusercontent.com’. you may need to adjust the proxy settings in gradle
这种错误一般是无法访问raw.githubusercontent.com造成的
解决办法
访问网址:https://www.ipaddress.com 然后搜索raw.githubusercontent.com,得到一个新的网址,复制到hosts文件夹内
修改hosts文件权限修改访问地址
右击 hosts属性–安全 --高级
点击更改权限
添加新权限
选择主体
进入选择用户或组,点击高级
点击 立即查找 ,找到当前用户,选中 确定
hosts所有权限全部选上,确定
添加权限后一路确定
修改hosts文件保存
185.199.109.133 raw.githubusercontent.com
在目标文件中打开git 开始编译
mingw32-make
mingw32-make install