使用CMake交叉編譯Android環(huán)境的OpenCV

編譯環(huán)境

這一點(diǎn)十分重要,有時(shí)候如果環(huán)境不同某饰,可能出現(xiàn)一些奇奇怪怪的錯(cuò)誤儒恋,會(huì)浪費(fèi)大量的時(shí)間去填坑。
比如我用>Android NDK r18b版本編譯露乏,就報(bào)錯(cuò):
針對(duì)這個(gè)報(bào)錯(cuò)碧浊,我提了一個(gè)issues:https://github.com/opencv/opencv/issues/15521
不知道以后會(huì)不會(huì)解決。
解決了:
如果使用>Android NDK r18b編譯瘟仿,需要添加下面的參數(shù):

-DBUILD_ZLIB=ON
[ 57%] Linking CXX shared library ../../lib/armeabi-v7a/libopencv_core.so
bionic/libc/include/bits/fortify/stdio.h:70: error: undefined reference to '__vsnprintf_chk'
bionic/libc/include/bits/fortify/stdio.h:43: error: undefined reference to '__vsnprintf_chk'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
modules/core/CMakeFiles/opencv_core.dir/build.make:1345: recipe for target 'lib/armeabi-v7a/libopencv_core.so' failed
make[2]: *** [lib/armeabi-v7a/libopencv_core.so] Error 1
CMakeFiles/Makefile2:1509: recipe for target 'modules/core/CMakeFiles/opencv_core.dir/all' failed
make[1]: *** [modules/core/CMakeFiles/opencv_core.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 57%] Linking CXX static library ../lib/armeabi-v7a/libIlmImf.a
[ 57%] Built target IlmImf
Makefile:162: recipe for target 'all' failed
make: *** [all] Error 2

針對(duì)Android SDK我感覺(jué)沒(méi)什么特別要求箱锐,從API Level 22 到 29我都安裝了。


image.png

配置環(huán)境變量

上面東西都準(zhǔn)備好之后劳较,我們還需要配置一下環(huán)境變量:
在 ~/.bashrc 中添加:

export ANDROID_HOME=/home/andforce/Android/Sdk
export ANDROID_SDK=$ANDROID_HOME
export ANDROID_NDK_HOME=/home/andforce/Downloads/android-ndk-r17c
export ANDROID_NDK=$ANDROID_NDK_HOME

開(kāi)始編譯

解壓下載的OpenCV 4.1.1源碼驹止,進(jìn)入源碼目錄后:

$ tree -L 1
.
├── 3rdparty
├── apps
├── cmake
├── CMakeLists.txt
├── CONTRIBUTING.md
├── data
├── doc
├── include
├── LICENSE
├── modules
├── platforms
├── README.md
└── samples

9 directories, 4 files

創(chuàng)建存放編譯結(jié)果的目錄

$mkdir build

進(jìn)入build目錄開(kāi)始編譯:

$cd build
# 開(kāi)始執(zhí)行 cmake 編譯命令
# 注意有【..】,表示源碼目錄在上一層观蜗,因?yàn)槲覀儸F(xiàn)在是在build目錄
cmake .. -DINSTALL_ANDROID_EXAMPLES=OFF \
-DANDROID_EXAMPLES_WITH_LIBS=OFF \
-DBUILD_EXAMPLES=OFF \
-DBUILD_DOCS=OFF \
-DWITH_OPENCL=OFF \
-DWITH_IPP=ON \
-DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake \
-DANDROID_TOOLCHAIN=clang \
-DANDROID_STL=c++_shared \
-DBUILD_SHARED_LIBS=ON \
-DBUILD_ANDROID_PROJECTS=OFF \
-DBUILD_ANDROID_EXAMPLES=OFF \
-DBUILD_PREF_TESTS=OFF \
-DBUILD_TESTS=OFF \
-DANDROID_ABI=armeabi-v7a \
-DANDROID_SDK_TARGET=21
幾個(gè)重要的參數(shù)含義
#NDK中toolchain的路徑
-DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake
#toolchain是clang版本
-DANDROID_TOOLCHAIN=clang
#表示編譯出的是.a靜態(tài)庫(kù)臊恋,如果要編譯.so動(dòng)態(tài)庫(kù),配置成c++_shared就可以了
-DANDROID_STL=c++_static
#不編譯Android工程
-DBUILD_ANDROID_PROJECTS=OFF
#不編譯事例工程
-DBUILD_ANDROID_EXAMPLES=OFF
#不編譯PREF test
-DBUILD_PREF_TESTS=OFF
#不編譯test
-DBUILD_TESTS=OFF
#android abi墓捻,x86抖仅,x86_64等
-DANDROID_ABI=armeabi-v7a
#Android target sdk
-DANDROID_SDK_TARGET=21

也許你有別的cmake參數(shù)想修改?

首先得知道支持哪些參數(shù),在執(zhí)行完上面的cmake命令之后撤卢,在build目錄執(zhí)行:

cmake -LA .

可以看到环凿,有很多很多的參數(shù),請(qǐng)根據(jù)自己的情況選擇吧放吩。

ANDROID_EXAMPLES_WITH_LIBS:BOOL=OFF
BUILD_ANDROID_EXAMPLES:BOOL=OFF
BUILD_ANDROID_PROJECTS:BOOL=OFF
BUILD_ANDROID_SERVICE:BOOL=OFF
BUILD_CUDA_STUBS:BOOL=OFF
BUILD_DOCS:BOOL=OFF
BUILD_EXAMPLES:BOOL=OFF
BUILD_FAT_JAVA_LIB:BOOL=ON
BUILD_ITT:BOOL=ON
BUILD_JASPER:BOOL=ON
BUILD_JAVA:BOOL=ON
BUILD_JPEG:BOOL=ON
BUILD_LIST:STRING=
BUILD_OPENEXR:BOOL=ON
BUILD_PACKAGE:BOOL=ON
BUILD_PERF_TESTS:BOOL=ON
BUILD_PNG:BOOL=ON
BUILD_PROTOBUF:BOOL=ON
BUILD_SHARED_LIBS:BOOL=OFF
BUILD_TBB:BOOL=ON
BUILD_TESTS:BOOL=OFF
BUILD_TIFF:BOOL=ON
BUILD_USE_SYMLINKS:BOOL=OFF
BUILD_WEBP:BOOL=ON
BUILD_WITH_DEBUG_INFO:BOOL=OFF
BUILD_WITH_DYNAMIC_IPP:BOOL=OFF
BUILD_ZLIB:BOOL=OFF
BUILD_opencv_apps:BOOL=OFF
BUILD_opencv_calib3d:BOOL=ON
BUILD_opencv_core:BOOL=ON
BUILD_opencv_dnn:BOOL=ON
BUILD_opencv_features2d:BOOL=ON
BUILD_opencv_flann:BOOL=ON
BUILD_opencv_highgui:BOOL=ON
BUILD_opencv_imgcodecs:BOOL=ON
BUILD_opencv_imgproc:BOOL=ON
BUILD_opencv_java_bindings_generator:BOOL=ON
BUILD_opencv_js:BOOL=OFF
BUILD_opencv_ml:BOOL=ON
BUILD_opencv_objdetect:BOOL=ON
BUILD_opencv_photo:BOOL=ON
BUILD_opencv_stitching:BOOL=ON
BUILD_opencv_ts:BOOL=ON
BUILD_opencv_video:BOOL=ON
BUILD_opencv_videoio:BOOL=ON
BUILD_opencv_world:BOOL=OFF
CAROTENE_NS:STRING=carotene_o4t
CCACHE_PROGRAM:FILEPATH=CCACHE_PROGRAM-NOTFOUND
CMAKE_AR:FILEPATH=/home/andforce/Downloads/android-ndk-r17c/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ar
CMAKE_ASM_FLAGS:STRING=
CMAKE_ASM_FLAGS_DEBUG:STRING=
CMAKE_ASM_FLAGS_RELEASE:STRING=
CMAKE_BUILD_TYPE:STRING=
CMAKE_COLOR_MAKEFILE:BOOL=ON
CMAKE_CONFIGURATION_TYPES:STRING=Debug;Release
CMAKE_CXX_COMPILER_AR:FILEPATH=CMAKE_CXX_COMPILER_AR-NOTFOUND
CMAKE_CXX_COMPILER_RANLIB:FILEPATH=CMAKE_CXX_COMPILER_RANLIB-NOTFOUND
CMAKE_CXX_FLAGS:STRING=
CMAKE_CXX_FLAGS_DEBUG:STRING=
CMAKE_CXX_FLAGS_MINSIZEREL:STRING=-Os -DNDEBUG
CMAKE_CXX_FLAGS_RELEASE:STRING=
CMAKE_CXX_FLAGS_RELWITHDEBINFO:STRING=-O2 -g -DNDEBUG
CMAKE_CXX_STANDARD_LIBRARIES:STRING=-latomic -lm "/home/andforce/Downloads/android-ndk-r17c/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libc++_static.a" "/home/andforce/Downloads/android-ndk-r17c/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libc++abi.a" "/home/andforce/Downloads/android-ndk-r17c/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libandroid_support.a" "/home/andforce/Downloads/android-ndk-r17c/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libunwind.a" "-ldl"
CMAKE_C_COMPILER_AR:FILEPATH=CMAKE_C_COMPILER_AR-NOTFOUND
CMAKE_C_COMPILER_RANLIB:FILEPATH=CMAKE_C_COMPILER_RANLIB-NOTFOUND
CMAKE_C_FLAGS:STRING=
CMAKE_C_FLAGS_DEBUG:STRING=
CMAKE_C_FLAGS_MINSIZEREL:STRING=-Os -DNDEBUG
CMAKE_C_FLAGS_RELEASE:STRING=
CMAKE_C_FLAGS_RELWITHDEBINFO:STRING=-O2 -g -DNDEBUG
CMAKE_C_STANDARD_LIBRARIES:STRING=-latomic -lm
CMAKE_EXE_LINKER_FLAGS:STRING=
CMAKE_EXE_LINKER_FLAGS_DEBUG:STRING=
CMAKE_EXE_LINKER_FLAGS_MINSIZEREL:STRING=
CMAKE_EXE_LINKER_FLAGS_RELEASE:STRING=
CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO:STRING=
CMAKE_EXPORT_COMPILE_COMMANDS:BOOL=OFF
CMAKE_INSTALL_PREFIX:PATH=/home/andforce/Downloads/opencv-4.1.1/build/install
CMAKE_LINKER:FILEPATH=/home/andforce/Downloads/android-ndk-r17c/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld
CMAKE_MAKE_PROGRAM:FILEPATH=/usr/bin/make
CMAKE_MODULE_LINKER_FLAGS:STRING=
CMAKE_MODULE_LINKER_FLAGS_DEBUG:STRING=
CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL:STRING=
CMAKE_MODULE_LINKER_FLAGS_RELEASE:STRING=
CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO:STRING=
CMAKE_NM:FILEPATH=/home/andforce/Downloads/android-ndk-r17c/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-nm
CMAKE_OBJCOPY:FILEPATH=/home/andforce/Downloads/android-ndk-r17c/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-objcopy
CMAKE_OBJDUMP:FILEPATH=/home/andforce/Downloads/android-ndk-r17c/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-objdump
CMAKE_RANLIB:FILEPATH=/home/andforce/Downloads/android-ndk-r17c/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ranlib
CMAKE_SHARED_LINKER_FLAGS:STRING=
CMAKE_SHARED_LINKER_FLAGS_DEBUG:STRING=
CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL:STRING=
CMAKE_SHARED_LINKER_FLAGS_RELEASE:STRING=
CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO:STRING=
CMAKE_SKIP_INSTALL_RPATH:BOOL=NO
CMAKE_SKIP_RPATH:BOOL=NO
CMAKE_STATIC_LINKER_FLAGS:STRING=
CMAKE_STATIC_LINKER_FLAGS_DEBUG:STRING=
CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL:STRING=
CMAKE_STATIC_LINKER_FLAGS_RELEASE:STRING=
CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO:STRING=
CMAKE_STRIP:FILEPATH=/home/andforce/Downloads/android-ndk-r17c/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-strip
CMAKE_TOOLCHAIN_FILE:FILEPATH=/home/andforce/Downloads/android-ndk-r17c/build/cmake/android.toolchain.cmake
CMAKE_VERBOSE_MAKEFILE:BOOL=FALSE
CPACK_BINARY_DEB:BOOL=OFF
CPACK_BINARY_FREEBSD:BOOL=OFF
CPACK_BINARY_IFW:BOOL=OFF
CPACK_BINARY_NSIS:BOOL=OFF
CPACK_BINARY_RPM:BOOL=OFF
CPACK_BINARY_STGZ:BOOL=ON
CPACK_BINARY_TBZ2:BOOL=OFF
CPACK_BINARY_TGZ:BOOL=ON
CPACK_BINARY_TXZ:BOOL=OFF
CPACK_BINARY_TZ:BOOL=ON
CPACK_SOURCE_RPM:BOOL=OFF
CPACK_SOURCE_TBZ2:BOOL=ON
CPACK_SOURCE_TGZ:BOOL=ON
CPACK_SOURCE_TXZ:BOOL=ON
CPACK_SOURCE_TZ:BOOL=ON
CPACK_SOURCE_ZIP:BOOL=OFF
CPUFEATURES_ROOT:PATH=/home/andforce/Downloads/opencv-4.1.1/3rdparty/cpufeatures
CPU_BASELINE:STRING=DETECT
CPU_DISPATCH:STRING=
CV_DISABLE_OPTIMIZATION:BOOL=OFF
CV_ENABLE_INTRINSICS:BOOL=ON
CV_TRACE:BOOL=ON
ENABLE_BUILD_HARDENING:BOOL=OFF
ENABLE_CCACHE:BOOL=ON
ENABLE_CONFIG_VERIFICATION:BOOL=OFF
ENABLE_FAST_MATH:BOOL=OFF
ENABLE_IMPL_COLLECTION:BOOL=OFF
ENABLE_INSTRUMENTATION:BOOL=OFF
ENABLE_NOISY_WARNINGS:BOOL=OFF
ENABLE_PIC:BOOL=ON
ENABLE_PRECOMPILED_HEADERS:BOOL=OFF
ENABLE_SOLUTION_FOLDERS:BOOL=OFF
ENABLE_THIN_LTO:BOOL=OFF
EXECUTABLE_OUTPUT_PATH:PATH=/home/andforce/Downloads/opencv-4.1.1/build/bin
GENERATE_ABI_DESCRIPTOR:BOOL=OFF
GIT_EXECUTABLE:FILEPATH=/usr/bin/git
HAVE_IEEEFP:STRING=1
HOST_BIG_ENDIAN:STRING=OFF
HOST_FILLORDER:STRING=FILLORDER_LSB2MSB
INSTALL_ANDROID_EXAMPLES:BOOL=OFF
INSTALL_CREATE_DISTRIB:BOOL=OFF
INSTALL_C_EXAMPLES:BOOL=OFF
INSTALL_PYTHON_EXAMPLES:BOOL=OFF
INSTALL_TESTS:BOOL=OFF
LIBRARY_OUTPUT_PATH_ROOT:PATH=/home/andforce/Downloads/opencv-4.1.1/build
M_LIBRARY:FILEPATH=/home/andforce/Downloads/android-ndk-r17c/platforms/android-14/arch-arm/usr/lib/libm.so
OPENCV_CONFIG_FILE_INCLUDE_DIR:PATH=/home/andforce/Downloads/opencv-4.1.1/build
OPENCV_DNN_CUDA:BOOL=OFF
OPENCV_DNN_OPENCL:BOOL=OFF
OPENCV_DOWNLOAD_PATH:PATH=/home/andforce/Downloads/opencv-4.1.1/.cache
OPENCV_DUMP_HOOKS_FLOW:BOOL=OFF
OPENCV_ENABLE_MEMORY_SANITIZER:BOOL=OFF
OPENCV_ENABLE_NONFREE:BOOL=OFF
OPENCV_EXTRA_MODULES_PATH:PATH=
OPENCV_FORCE_3RDPARTY_BUILD:BOOL=OFF
OPENCV_GENERATE_PKGCONFIG:BOOL=OFF
OPENCV_MATHJAX_RELPATH:STRING=https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0
OPENCV_PYTHON3_VERSION:BOOL=OFF
OPENCV_TIMESTAMP:STRING=2019-09-13T14:41:40Z
OPENCV_WARNINGS_ARE_ERRORS:BOOL=OFF
OpenCV_HAL_DIR:PATH=OpenCV_HAL_DIR-NOTFOUND
PROTOBUF_UPDATE_FILES:BOOL=OFF
PYTHON2_EXECUTABLE:FILEPATH=/usr/bin/python2.7
PYTHON2_INCLUDE_DIR:PATH=
PYTHON2_INCLUDE_DIR2:PATH=
PYTHON2_LIBRARY:FILEPATH=
PYTHON2_LIBRARY_DEBUG:FILEPATH=
PYTHON2_NUMPY_INCLUDE_DIRS:PATH=
PYTHON2_PACKAGES_PATH:PATH=
PYTHON3_EXECUTABLE:FILEPATH=/usr/bin/python3
PYTHON3_INCLUDE_DIR:PATH=
PYTHON3_INCLUDE_DIR2:PATH=
PYTHON3_LIBRARY:FILEPATH=
PYTHON3_LIBRARY_DEBUG:FILEPATH=
PYTHON3_NUMPY_INCLUDE_DIRS:PATH=
PYTHON3_PACKAGES_PATH:PATH=
USE_WIN32_FILEIO:BOOL=FALSE
VIDEOIO_ENABLE_PLUGINS:BOOL=ON
VIDEOIO_ENABLE_STRICT_PLUGIN_CHECK:BOOL=ON
VIDEOIO_PLUGIN_LIST:STRING=
WITH_ADE:BOOL=ON
WITH_ANDROID_MEDIANDK:BOOL=OFF
WITH_ARITH_DEC:BOOL=ON
WITH_ARITH_ENC:BOOL=ON
WITH_CAROTENE:BOOL=ON
WITH_CLP:BOOL=OFF
WITH_CPUFEATURES:BOOL=ON
WITH_CUDA:BOOL=OFF
WITH_EIGEN:BOOL=OFF
WITH_FFMPEG:BOOL=OFF
WITH_GDCM:BOOL=OFF
WITH_HALIDE:BOOL=OFF
WITH_HPX:BOOL=OFF
WITH_IMGCODEC_HDR:BOOL=ON
WITH_IMGCODEC_PFM:BOOL=ON
WITH_IMGCODEC_PXM:BOOL=ON
WITH_IMGCODEC_SUNRASTER:BOOL=ON
WITH_INF_ENGINE:BOOL=OFF
WITH_ITT:BOOL=ON
WITH_JASPER:BOOL=ON
WITH_JPEG:BOOL=ON
WITH_LIBREALSENSE:BOOL=OFF
WITH_OPENCL:BOOL=OFF
WITH_OPENCL_SVM:BOOL=OFF
WITH_OPENEXR:BOOL=ON
WITH_OPENMP:BOOL=OFF
WITH_OPENVX:BOOL=OFF
WITH_PNG:BOOL=ON
WITH_PROTOBUF:BOOL=ON
WITH_PTHREADS_PF:BOOL=ON
WITH_QUIRC:BOOL=ON
WITH_TBB:BOOL=OFF
WITH_TIFF:BOOL=ON
WITH_VULKAN:BOOL=OFF
WITH_WEBP:BOOL=ON
ZLIB_INCLUDE_DIR:PATH=/home/andforce/Downloads/android-ndk-r17c/sysroot/usr/include
ZLIB_LIBRARY_DEBUG:FILEPATH=ZLIB_LIBRARY_DEBUG-NOTFOUND
ZLIB_LIBRARY_RELEASE:FILEPATH=/home/andforce/Downloads/android-ndk-r17c/platforms/android-14/arch-arm/usr/lib/libz.so
ccitt:BOOL=ON
logluv:BOOL=ON
lzw:BOOL=ON
mdi:BOOL=ON
next:BOOL=ON
old-jpeg:BOOL=OFF
opencv_dnn_PERF_CAFFE:BOOL=OFF
opencv_dnn_PERF_CLCAFFE:BOOL=OFF
packbits:BOOL=ON
thunder:BOOL=ON

回到正題智听,繼續(xù)說(shuō)如何編譯

cmake結(jié)束之后,輸出類似下面的信息,表示成功了

-- Install to: /home/andforce/Downloads/opencv-4.1.1/build/install


--
-- Configuring done
-- Generating done
-- Build files have been written to: /home/andforce/Downloads/opencv->4.1.1/build

看一下build目錄下生成的東西:

build$ tree -L 1
.
├── 3rdparty
├── bin
├── carotene
├── CMakeCache.txt
├── CMakeDownloadLog.txt
├── CMakeFiles
├── cmake_install.cmake
├── cmake_uninstall.cmake
├── CMakeVars.txt
├── configured
├── CPackConfig.cmake
├── CPackSourceConfig.cmake
├── CTestTestfile.cmake
├── custom_hal.hpp
├── cvconfig.h
├── cv_cpu_config.h
├── data
├── doc
├── include
├── lib
├── Makefile                # <-- 生成了Makefile
├── modules
├── opencv2
├── OpenCV-armeabi-v7a.mk
├── OpenCVConfig.cmake
├── OpenCVConfig-version.cmake
├── opencv_data_config.hpp
├── OpenCV.mk
├── OpenCVModules.cmake
├── opencv_tests_config.hpp
├── platforms
├── unix-install
└── version_string.tmp

13 directories, 20 files

還是在build目錄渡紫,執(zhí)行make -j8開(kāi)始編譯

#根據(jù)電腦性能可以調(diào)整-j后面的參數(shù)到推,一般為CPU核心數(shù)的2倍
$make -j8

Scanning dependencies of target libcpufeatures
[ 0%] Building C object 3rdparty/cpufeatures/CMakeFiles/libcpufeatures.dir/cpu-features.c.o
[ 0%] Building C object 3rdparty/libjasper/CMakeFiles/libjasper.dir/jas_cm.c.o
.
.此處省略...
.
[ 74%] Building CXX object >modules/ts/CMakeFiles/opencv_ts.dir/src/cuda_test.cpp.o
.
.此處省略...
.
[ 99%] Building CXX object modules/imgproc/CMakeFiles/opencv_perf_imgproc.dir/perf/perf_warp.cpp.o
[100%] Linking CXX executable ../../bin/opencv_perf_imgproc
[100%] Built target opencv_perf_imgproc

跑到100%表示編譯結(jié)束了

在build/lib/armeabi-v7a生成了對(duì)應(yīng)的靜態(tài)庫(kù)

build/lib/armeabi-v7a$ ls
libopencv_calib3d.so     libopencv_highgui.so    libopencv_photo.so
libopencv_core.so        libopencv_imgcodecs.so  libopencv_stitching.so
libopencv_dnn.so         libopencv_imgproc.so    libopencv_ts.a
libopencv_features2d.so  libopencv_ml.so         libopencv_videoio.so
libopencv_flann.so       libopencv_objdetect.so  libopencv_video.so

生成sdk

還是在build目錄下,執(zhí)行make install

build$ make install

之后會(huì)在build/install/下生成sdk

build/install$ tree -L 3
.
├── LICENSE
├── README.android
└── sdk
    ├── etc
    │   ├── haarcascades
    │   ├── lbpcascades
    │   ├── licenses
    │   ├── valgrind_3rdparty.supp
    │   └── valgrind.supp
    └── native
        ├── 3rdparty
        ├── jni
        └── staticlibs

9 directories, 4 files

頭文件在:build/install/sdk/native/jni/include/

build/install/sdk/native/jni/include/opencv2$ ls
calib3d      dnn.hpp         highgui.hpp    ml.hpp              photo.hpp      videoio.hpp
calib3d.hpp  features2d      imgcodecs      objdetect           stitching
core         features2d.hpp  imgcodecs.hpp  objdetect.hpp       stitching.hpp
core.hpp     flann           imgproc        opencv.hpp          video
cvconfig.h   flann.hpp       imgproc.hpp    opencv_modules.hpp  video.hpp
dnn          highgui         ml             photo               videoio

靜態(tài)庫(kù)在:build/install/sdk/native/staticlibs/

build/install/sdk/native/staticlibs/armeabi-v7a$ ls 
libopencv_calib3d.so     libopencv_highgui.so    libopencv_photo.so
libopencv_core.so        libopencv_imgcodecs.so  libopencv_stitching.so
libopencv_dnn.so         libopencv_imgproc.so    libopencv_videoio.so
libopencv_features2d.so  libopencv_ml.so         libopencv_video.so
libopencv_flann.so       libopencv_objdetect.so

到此惕澎,整個(gè)交叉編譯過(guò)程就結(jié)束了莉测。

cmake .. \
-DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake \
-DCMAKE_BUILD_TYPE=Release \
-DANDROID_ABI="x86" \
-DANDROID_NATIVE_API_LEVEL=21 \
-DWITH_CAROTENE=OFF \
-DWITH_CLP=OFF \
-DWITH_CUBLAS=OFF \
-DWITH_CUDA=OFF \
-DWITH_CUFFT=OFF \
-DWITH_EIGEN=OFF \
-DWITH_GDCM=OFF \
-DWITH_GSTREAMER_0_10=OFF \
-DWITH_JASPER=OFF \
-DWITH_JPEG=OFF \
-DWITH_NVCUVID=OFF \
-DWITH_OPENCL=OFF \
-DWITH_OPENCL_SVM=OFF \
-DWITH_OPENEXR=OFF \
-DWITH_OPENMP=OFF \
-DWITH_OPENVX=OFF \
-DWITH_PNG=ON \
-DWITH_PTHREADS_PF=OFF \
-DWITH_TBB=OFF \
-DWITH_TIFF=OFF \
-DWITH_WEBP=OFF \
-DBUILD_ANDROID_EXAMPLES=OFF \
-DBUILD_ANDROID_SERVICE=OFF \
-DBUILD_CUDA_STUBS=OFF \
-DBUILD_DOCS=OFF \
-DBUILD_EXAMPLES=OFF \
-DBUILD_FAT_JAVA_LIB=OFF \
-DBUILD_JASPER=OFF \
-DBUILD_JPEG=OFF \
-DBUILD_OPENEXR=OFF \
-DBUILD_PACKAGE=OFF \
-DBUILD_PERF_TESTS=OFF \
-DBUILD_PNG=ON \
-DBUILD_SHARED_LIBS=OFF \
-DBUILD_TBB=OFF \
-DBUILD_TESTS=OFF \
-DBUILD_TIFF=OFF \
-DBUILD_WITH_DEBUG_INFO=OFF \
-DBUILD_WITH_DYNAMIC_IPP=OFF \
-DBUILD_opencv_apps=OFF \
-DBUILD_opencv_calib3d=ON \
-DBUILD_ZLIB=ON \
-DBUILD_opencv_core=ON \
-DBUILD_opencv_features2d=ON \
-DBUILD_opencv_flann=ON \
-DBUILD_opencv_highgui=ON \
-DBUILD_opencv_imgcodecs=ON \
-DBUILD_opencv_imgproc=ON \
-DBUILD_opencv_java=OFF \
-DBUILD_opencv_ml=ON \
-DBUILD_opencv_objdetect=OFF \
-DBUILD_opencv_photo=OFF \
-DBUILD_opencv_shape=OFF \
-DBUILD_opencv_stitching=OFF \
-DBUILD_opencv_stereo=OFF \
-DBUILD_opencv_superres=OFF \
-DBUILD_opencv_ts=OFF \
-DBUILD_opencv_video=OFF \
-DBUILD_opencv_videoio=OFF \
-DBUILD_opencv_line_descriptor=OFF \
-DBUILD_opencv_reg=OFF \
-DBUILD_opencv_saliency=OFF \
-DBUILD_opencv_videostab=OFF \
-DBUILD_opencv_world=OFF \
-DCMAKE_CXX_FLAGS="-ffunction-sections -fdata-sections -fvisibility=hidden -O3 -std=c++11 -mfloat-abi=softfp -mfpu=neon -march=armv7-a -mtune=cortex-a8" \
-DCMAKE_C_FLAGS="-ffunction-sections -fdata-sections -fvisibility=hidden -O3 -mfloat-abi=softfp -mfpu=neon -march=armv7-a -mtune=cortex-a8" \
-DCMAKE_SHARED_LINKER_FLAGS="-Wl,--gc-sections" \
-DBUILD_opencv_xfeatures2d=OFF \
-DBUILD_opencv_face=OFF \
-DBUILD_opencv_bgsegm=OFF \
-DBUILD_opencv_datasets=OFF \
-DBUILD_opencv_dpm=OFF \
-DBUILD_opencv_tracking=OFF \
-DBUILD_opencv_xobjdetect=OFF \
-DBUILD_opencv_optflow=OFF \
-DBUILD_opencv_tracking=OFF \
-DENABLE_NEON=ON \
-DBUILD_opencv_ximgproc=ON \
-DBUILD_opencv_dnn=OFF \
-DBUILD_opencv_structured_light=OFF \
-DBUILD_opencv_surface_matching=OFF \
-DBUILD_opencv_text=OFF \
-DBUILD_opencv_xphoto=OFF \
-DBUILD_opencv_fuzzy=OFF \
-DBUILD_opencv_bioinspired=OFF \
-DBUILD_opencv_phase_unwrapping=OFF \
-DBUILD_opencv_plot=OFF \
-DBUILD_opencv_rgbd=OFF \
-DBUILD_opencv_aruco=OFF


?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市集灌,隨后出現(xiàn)的幾起案子悔雹,更是在濱河造成了極大的恐慌,老刑警劉巖欣喧,帶你破解...
    沈念sama閱讀 211,123評(píng)論 6 490
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件腌零,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡唆阿,警方通過(guò)查閱死者的電腦和手機(jī)益涧,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,031評(píng)論 2 384
  • 文/潘曉璐 我一進(jìn)店門(mén),熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)驯鳖,“玉大人闲询,你說(shuō)我怎么就攤上這事∏痴蓿” “怎么了扭弧?”我有些...
    開(kāi)封第一講書(shū)人閱讀 156,723評(píng)論 0 345
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)记舆。 經(jīng)常有香客問(wèn)我鸽捻,道長(zhǎng),這世上最難降的妖魔是什么泽腮? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 56,357評(píng)論 1 283
  • 正文 為了忘掉前任御蒲,我火速辦了婚禮,結(jié)果婚禮上诊赊,老公的妹妹穿的比我還像新娘厚满。我一直安慰自己,他們只是感情好碧磅,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,412評(píng)論 5 384
  • 文/花漫 我一把揭開(kāi)白布碘箍。 她就那樣靜靜地躺著遵馆,像睡著了一般。 火紅的嫁衣襯著肌膚如雪丰榴。 梳的紋絲不亂的頭發(fā)上团搞,一...
    開(kāi)封第一講書(shū)人閱讀 49,760評(píng)論 1 289
  • 那天,我揣著相機(jī)與錄音多艇,去河邊找鬼。 笑死像吻,一個(gè)胖子當(dāng)著我的面吹牛峻黍,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播拨匆,決...
    沈念sama閱讀 38,904評(píng)論 3 405
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼姆涩,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了惭每?” 一聲冷哼從身側(cè)響起骨饿,我...
    開(kāi)封第一講書(shū)人閱讀 37,672評(píng)論 0 266
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎台腥,沒(méi)想到半個(gè)月后宏赘,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 44,118評(píng)論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡黎侈,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,456評(píng)論 2 325
  • 正文 我和宋清朗相戀三年察署,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片峻汉。...
    茶點(diǎn)故事閱讀 38,599評(píng)論 1 340
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡贴汪,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出休吠,到底是詐尸還是另有隱情扳埂,我是刑警寧澤,帶...
    沈念sama閱讀 34,264評(píng)論 4 328
  • 正文 年R本政府宣布瘤礁,位于F島的核電站阳懂,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏蔚携。R本人自食惡果不足惜希太,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,857評(píng)論 3 312
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望酝蜒。 院中可真熱鬧誊辉,春花似錦、人聲如沸亡脑。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 30,731評(píng)論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至蛙紫,卻和暖如春拍屑,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背坑傅。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 31,956評(píng)論 1 264
  • 我被黑心中介騙來(lái)泰國(guó)打工僵驰, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人唁毒。 一個(gè)月前我還...
    沈念sama閱讀 46,286評(píng)論 2 360
  • 正文 我出身青樓蒜茴,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親浆西。 傳聞我的和親對(duì)象是個(gè)殘疾皇子粉私,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,465評(píng)論 2 348

推薦閱讀更多精彩內(nèi)容