Using Cmake-gui to build OpenCV and Opencv_contrib for Android on Ubuntu !

Note: If not install cmake-gui, just run script below:

#!/bin/shBASE_PATH=~/tool/AndroidNDK_PATH=${BASE_PATH}/android-ndk-r16bSDK_PATH=${BASE_PATH}/sdkANDROID_API_LEVEL=21#declare -a ANDROID_ABI_LIST=("x86" "x86_64" "armeabi" "arm64-v8a" "armeabi-v7a" "mips" "mips64")ANDROID_CONTRIB_PATH=../../opencv_contrib430/modulesINSTALL_PREFIX=./cmake -DCMAKE_TOOLCHAIN_FILE=${NDK_PATH}/build/cmake/android.toolchain.cmake \      -DANDROID_NDK=${NDK_PATH} \      -DANDROID_NATIVE_API_LEVEL=${ANDROID_API_LEVEL} \  -DANDROID_SDK=${SDK_PATH} \      -DANDROID_ABI="arm64-v8a" \  -DANDROID_STL=c++_static \      -DWITH_CUDA=OFF \      -DWITH_MATLAB=OFF \      -DBUILD_ANDROID_EXAMPLES=OFF \      -DBUILD_DOCS=OFF \      -DBUILD_PERF_TESTS=OFF \      -DBUILD_TESTS=OFF \  -DCMAKE_BUILD_TYPE=Release \      -DOPENCV_EXTRA_MODULES_PATH=${ANDROID_CONTRIB_PATH}  \      -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} ..

一、Compiler Environment & Tools Versions

1.Cmake-gui 3.18.0
2.OpenCV 4.3.0
3.Opencv_contrib 4.3.0
4.Ubuntu 18.04

二、Cmake-gui configuration

1.select source directory & output directory
2.Add Entry for Android

  • ANDROID_NDK type is PATH,enter NDK path
  • ANDROID_SDK type is PATH,enter SDK path
  • ANDROID_ABI type is STRING,default is armeabi-v7a
  • ANDROID_NATIVE_API_LEVEL type is STRING,default is 21
  • ANDROID_STL type is STRING,enter c++_static or c++_shared(default gnustl_static
  • CMAKE_TOOLCHAIN_FILE type is FILEPATH,

Option1:

Option2: enter NDK cmake path. likeandroid-ndk-r16b/build/cmake/android.toolchain.cmake

  • more info can be found in xxx/opencv/platforms/android/android.toolchain.cmake

then click the button Configure in bottom. if no errors, it will be show logs as below:

Parallel framework:            pthreads  Trace:                         YES (with Intel ITT)  Other third-party libraries:    Custom HAL:                  NO    Protobuf:                    build (3.5.1)  Python (for build):            /usr/bin/python3  Java:                          export all functions    ant:                         NO    Java wrappers:               YES    Java tests:                  NO  Install to:                    /home/xxx/Document/player/build-opencv-for-android/opencv430/build/install-----------------------------------------------------------------Configuring done

3.Set Configuration for OpenCV(Options)

  • OPENCV_EXTRA_MODULES_PATH set value:xxx/Document/player/build-opencv-for-android/opencv_contrib430/modules
  • BUILD_ANDROID_PROJECTS=ON Build Android projects providing APK files.
  • BUILD_ANDROID_EXAMPLES=OFF
  • BUILD_PERF_TESTS=OFF
  • BUILD_TESTS=OFF
  • BUILD_opencv_world=OFF
  • BUILD_SHARED_LIBS=OFF
  • WITH_CUDA=OFF
  • CMAKE_BUILD_TYPE=Release

then click the button Configure in bottom again. Also if no errors, it will be show logs as below:

GUI:   Media I/O:     ZLib:                        z (ver 1.2.3)    JPEG:                        build-libjpeg-turbo (ver 2.0.4-62)    WEBP:                        build (ver encoder: 0x020f)    PNG:                         build (ver 1.6.37)    TIFF:                        build (ver 42 - 4.0.10)    JPEG 2000:                   build Jasper (ver 1.900.1)    OpenEXR:                     build (ver 2.3.0)    HDR:                         YES    SUNRASTER:                   YES    PXM:                         YES    PFM:                         YES  Video I/O:  Parallel framework:            pthreads  Trace:                         YES (with Intel ITT)  Other third-party libraries:    Custom HAL:                  NO    Protobuf:                    build (3.5.1)  Python (for build):            /usr/bin/python3  Java:                          export all functions    ant:                         NO    Java wrappers:               YES    Java tests:                  NO  Install to:                    xxx/Document/player/build-opencv-for-android/opencv430/build/install-----------------------------------------------------------------Configuring done

Finally, click the button Generate, and it will be show logs as below:

-----------------------------------------------------------------Configuring doneGenerating done

三、Build

Note!
Do the stuff below before building:
Copy file xfeatures2d.hpp and directory xfeatures2d
from xxx/opencv_contrib430/modules/xfeatures2d/include/opencv2
to xxx/opencv430/modules/features2d/include/opencv2
result like:

otherwise, will occurse error like:

In file included from /home/xxx/Document/player/build-opencv-for-android/opencv-4.3.0/modules/java/generator/src/cpp/opencv_java.cpp:8:In file included from /home/xxx/Document/player/build-opencv-for-android/opencv-4.3.0/output/modules/java_bindings_generator/gen/cpp/opencv_jni.hpp:18:/home/xxx/Document/player/build-opencv-for-android/opencv-4.3.0/output/modules/java_bindings_generator/gen/cpp/xfeatures2d.inl.hpp:12:10: fatal error: 'opencv2/xfeatures2d.hpp' file not found#include "opencv2/xfeatures2d.hpp"

1.Command line build

cd /home/xxx/Document/player/build-opencv-for-android/opencv430/buildmake -j8

No errors, exeute

make install

references:

  1. Windows环境下为Android编译OpenCV4.3
  2. Ubuntu 16.04下为Android编译OpenCV 3.2.0 Manager
  3. build-opencv-for-android
  4. Windows 下 OpenCV 3.4.0 + Contrib 部署文档 (VS2015 & Android)
  5. Ubuntu16.04编译OpenCV for Android

更多相关文章

  1. android 编译错误解决方法(一)
  2. 1.17android小记
  3. 开源项目Universal Image Loader for Android(安卓)说明文档 (1)
  4. android greenDao 编译问题总结
  5. Gradle-Android打包文档
  6. java 编译中常用函数
  7. UMeng统计分析Android集成文档
  8. Android(安卓)快速集成文档校正能力 超简单
  9. 用Android(安卓)studio运行RN项目,Node突然闪退解决方案

随机推荐

  1. 留言板,字符串和数组方法 ----0407
  2. 前端插件:Web Uploader(上传图片)和富文本编
  3. CF卡里面的文件名目录名或卷标语法不正确
  4. 基于 Yii2 开发的多店铺商城系统,免费开源
  5. 统信UOS系统中使用QQ浏览器导入pfx/p12认
  6. I/O模型和Java NIO源码分析
  7. 统信UOS系统中设置WPS双面打印的方法
  8. 快速排序c、c++
  9. springboot研究二:spring-boot单元测试
  10. MySQL 语句分析的神器-Optimizer Trace