ubuntu16.04编译opencv for Android
2017-08-06 11:56
405 查看
安装cmake
参考这篇博客ubuntu安装CMake的几种方式中的软链接Android Sdk中的CMake下载opencv源码
直接在github clone最新源码https://github.com/opencv/opencv/tree/master
或者在官网下载指定版本的源码
http://opencv.org/releases.html
编译opencv源码
进入源码目录新建一个opencvAndroid.sh脚本文件,内容如下#!/bin/sh rm -rf android_build mkdir android_build cd android_build cmake -DANDROID_NDK=/home/gavinandre/Android/Sdk/ndk-bundle -DANDROID_STL=c++_shared -DCMAKE_TOOLCHAIN_FILE=/home/gavinandre/Android/Sdk/ndk-bundle/build/cmake/android.toolchain.cmake -DCMAKE_SYSTEM_VERSION=21 -DCMAKE_ANDROID_ARCH_ABI="armeabi-v7a" -DCMAKE_ANDROID_ARM_NEON=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_ANDROID_STL_TYPE="c++_shared" -DBUILD_opencv_world=ON -DBUILD_ZLIB=ON $@ .. cmake --build . --config Release
-DXXXXXX是指定Android交叉编译工具链中的一些参数
需要注意两点:
1.建议指定DANDROID_STL和DCMAKE_ANDROID_STL_TYPE为c++_shared,因为当使用c++11和gnustl_shared来编译时,NDK缺少一些函数,参考:https://stackoverflow.com/questions/22922961/c11-cmath-functions-not-in-std-namespace-for-android-ndk-w-gcc-4-8-or-clang-3
2.指定CMAKE_BUILD_TYPE和config时为Release,这样会开启O3优化,在使用opencv的一些函数时会大幅度提升效率
然后运行该脚本
./opencvAndroid.sh
之后等待编译完成即可
编译完成后可以在android_build目录下找到编译完的静态库文件
opencv库在:android_build/lib/下
第三方库在:android_build/3rdparty/lib/下
出现如下错误的话
/usr/include/features.h:391:10: fatal error: 'gnu/stubs.h' file not found
说明可能是64位系统缺少32位依赖库,使用如下命令安装
sudo apt install libc6-dev-i386
相关文章推荐
- Ubuntu 16.04下为Android编译OpenCV 3.2.0 Manager
- sdl2 for android ubuntu开发环境搭建记录,编译SDL2 on ubuntu 16.04 x64
- ubuntu16.04编译dlib for Android
- ubuntu16.04编译boost for Android
- [转]ubuntu下编译opencv for android及sample demo
- Ubuntu 16.04编译Opencv 3.4 (For python2.7 and python3.5)
- Ubuntu 16.04下为Android编译OpenCV 3.1.0 Manager
- Ubuntu16.04安装opencv for python/c++
- Ubuntu下Chromium for Android 源码的编译
- ubuntu16.04编译android2.3源码
- 编译得到OpenCv+Contrib SDK for android
- ubuntu16.04 编译android 源码出现的错误
- 编译并使用带有OpenCL模块的OpenCV for android SDK
- Anaconda Python3.6 OpenCV3.3 Ubuntu 16.04源码编译
- Ubuntu 16.04 64bit 编译 Android 4.4 内核
- ubuntu16.04编译android6_r1源码绕坑贴
- 在Ubuntu 16.04上为树莓派(RaspBerry Pi 3)编译Android 7(Nougat)
- ubuntu16.04 编译 opencv3.1.0 (Anaconda)
- [Android 编译(一)] Ubuntu 16.04 LTS 成功编译 Android 6.0 源码教程