如何为Android平台编译 opencv3 和 opencv_contrib (Linux)
编译出来的opencv库有问题,正在调试中 ......
本文以编译opencv 3.3.0 和 opencv_contrib 3.3.0为例,系统为 Linux x64 (Fedora 21),具体步骤如下:
1. 下载 Source code zip 压缩包
从下面网址,选择 opencv 3.3.0 Source code 下载
https://github.com/opencv/opencv/releases
从下面网址,选择下载与
opencv
3.3.0 对应的
opencv_contrib
3.3.0
https://github.com/opencv/opencv_contrib/releases
注意:opencv和opencv_contrib
版本必须保持一致,否则可能会出现编译错误。
2.
下载
build-opencv-for-android
开源代码
$ cd /mnt/work
$ git clone https://github.com/tzutalin/build-opencv-for-android.git
$ cd build-opencv-for-android
3. 解压源码包并重命名
将opencv-3.3.0.zip 和 opencv_contrib-3.3.0.zip 都解压到下载的build-opencv-for-android 开源代码 所在目录 /mnt/work/build-opencv-for-android 。
$ unzip opencv-3.3..zip -d /mnt/work/build-opencv-for-android
$ unzip opencv_contrib-3.3..zip -d /mnt/work/build-opencv-for-android
$ cd /mnt/work/build-opencv-for-android
$ mv opencv-3.3. opencv
$ mv opencv_contrib-3.3. opencv_contrib
4. 修改 build-opencv-for-android 开源代码中 build-android-opencv.sh
修改内容如下:
修改 第 6 行代码:
declare -a ANDROID_ABI_LIST=("x86" "x86_64" "armeabi" "arm64-v8a" "armeabi-v7a" "mips" "mips64")
为
declare -a ANDROID_ABI_LIST=("armeabi-v7a")
最终代码,如下:
#!/bin/bash
NDK_ROOT="${1:-${NDK_ROOT}}" ### ABIs setup
#declare -a ANDROID_ABI_LIST=("x86" "x86_64" "armeabi-v7a with NEON" "arm64-v8a")
declare -a ANDROID_ABI_LIST=("armeabi-v7a") ### path setup
SCRIPT=$(readlink -f $0)
WD=`dirname $SCRIPT`
OPENCV_ROOT="${WD}/opencv"
N_JOBS=${N_JOBS:-4} ### Download android-cmake
if [ ! -d "${WD}/android-cmake" ]; then
echo 'Cloning android-cmake'
git clone https://github.com/taka-no-me/android-cmake.git
fi INSTALL_DIR="${WD}/android_opencv"
rm -rf "${INSTALL_DIR}/opencv" ### Make each ABI target iteratly and sequentially
for i in "${ANDROID_ABI_LIST[@]}"
do
ANDROID_ABI="${i}"
echo "Start building ${ANDROID_ABI} version" if [ "${ANDROID_ABI}" = "armeabi" ]; then
API_LEVEL=19
else
API_LEVEL=21
fi temp_build_dir="${OPENCV_ROOT}/platforms/build_android_${ANDROID_ABI}"
### Remove the build folder first, and create it
rm -rf "${temp_build_dir}"
mkdir -p "${temp_build_dir}"
cd "${temp_build_dir}" cmake -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON \
-DCMAKE_TOOLCHAIN_FILE="${WD}/android-cmake/android.toolchain.cmake" \
-DANDROID_NDK="${NDK_ROOT}" \
-DANDROID_NATIVE_API_LEVEL=${API_LEVEL} \
-DANDROID_ABI="${ANDROID_ABI}" \
-D WITH_CUDA=OFF \
-D WITH_MATLAB=OFF \
-D BUILD_ANDROID_EXAMPLES=OFF \
-D BUILD_DOCS=OFF \
-D BUILD_PERF_TESTS=OFF \
-D BUILD_TESTS=OFF \
-DOPENCV_EXTRA_MODULES_PATH="${WD}/opencv_contrib/modules/" \
-DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}/opencv" \
../..
# Build it
make -j${N_JOBS}
# Install it
make install/strip
### Remove temp build folder
cd "${WD}"
rm -rf "${temp_build_dir}"
echo "end building ${ANDROID_ABI} version"
done
说明:
1). 由于目前 大多数 android 平台使用arm cpu, 采用armeabi-v7 指令集,为了减少编译时间,所有我只保留 "armeabi-v7a" , 其他删除,如果需要也可保留。
2). armeabi-v7 代表 arm EABI version 7 指令集, EABI 为 嵌入应用二进制接口 (Embedded Application Binary Interface) 。
5. 执行脚本 build-android-opencv.sh
$ ./build-android-opencv.sh /mnt/work/android/android-sdk-linux/ndk-bundle
注:build-android-opencv.sh脚本的通用的执行命令格式为“./build-android-opencv.sh [NDK_ROOT]”,其中,参数NDK_ROOT是可选的,表示Android Native Development Kit (NDK) 顶层目录,如果没有提供,则会试图寻找环境变量 ANDROID_NDK。
6. 查看编译结果
编译成功后,会在 build-opencv-for-android 目录,即build-android-opencv.sh脚本所在目录,生成 android_opencv目录,其目录结构如下:
$ tree -d android_opencv
android_opencv
└── opencv
├── apk
└── sdk
├── etc
│ ├── haarcascades
│ └── lbpcascades
└── native
├── 3rdparty
│ └── libs
│ └── armeabi-v7a
├── jni
│ ├── abi-armeabi-v7a
│ └── include
│ ├── opencv
│ └── opencv2
│ ├── aruco
│ ├── bioinspired
│ ├── calib3d
│ ├── ccalib
│ ├── core
│ │ ├── cuda
│ │ │ └── detail
│ │ ├── hal
│ │ └── utils
│ ├── datasets
│ ├── dnn
│ ├── face
│ ├── features2d
│ ├── flann
│ ├── fuzzy
│ ├── highgui
│ ├── imgcodecs
│ ├── img_hash
│ ├── imgproc
│ │ ├── detail
│ │ └── hal
│ ├── line_descriptor
│ ├── ml
│ ├── objdetect
│ ├── optflow
│ ├── phase_unwrapping
│ ├── photo
│ ├── reg
│ ├── rgbd
│ ├── saliency
│ ├── shape
│ ├── stereo
│ ├── stitching
│ │ └── detail
│ ├── structured_light
│ ├── superres
│ ├── surface_matching
│ ├── text
│ ├── tracking
│ ├── video
│ ├── videoio
│ ├── videostab
│ ├── xfeatures2d
│ ├── ximgproc
│ └── xphoto
└── libs
└── armeabi-v7a directories
问题与解决方法
问题一
$ ./build-android-opencv.sh
Start building armeabi-v7a version
CMake Error at /mnt/work/video/res/opencv/build-opencv-for-android-master/android-cmake/android.toolchain.cmake: (message):
Could not find neither Android NDK nor Android standalone toolchain. You should either set an environment variable:
export ANDROID_NDK=~/my-android-ndk
or
export ANDROID_STANDALONE_TOOLCHAIN=~/my-android-toolchain
or put the toolchain or NDK in the default path:
sudo ln -s ~/my-android-ndk /opt/android-ndk
sudo ln -s ~/my-android-toolchain /opt/android-toolchain
Call Stack (most recent call first):
/usr/share/cmake/Modules/CMakeDetermineSystem.cmake: (include)
CMakeLists.txt: (project) CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_CXX_COMPILER_ENV_VAR
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_CXX_COMPILER
CMake Error: Could not find cmake module file: /mnt/work/video/res/opencv/build-opencv-for-android-master/opencv/platforms/build_android_armeabi-v7a/CMakeFiles/3.0./CMakeCXXCompiler.cmake
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_C_COMPILER_ENV_VAR
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_C_COMPILER
CMake Error: Could not find cmake module file: /mnt/work/video/res/opencv/build-opencv-for-android-master/opencv/platforms/build_android_armeabi-v7a/CMakeFiles/3.0./CMakeCCompiler.cmake
CMake Error at CMakeLists.txt: (project):
No CMAKE_CXX_COMPILER could be found. Tell CMake where to find the compiler by setting the CMake cache entry
CMAKE_CXX_COMPILER to the full path to the compiler, or to the compiler
name if it is in the PATH. CMake Error at CMakeLists.txt: (project):
No CMAKE_C_COMPILER could be found. Tell CMake where to find the compiler by setting the CMake cache entry
CMAKE_C_COMPILER to the full path to the compiler, or to the compiler name
if it is in the PATH. CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
make: *** No targets specified and no makefile found. Stop.
make: *** No rule to make target 'install/strip'. Stop.
end building armeabi-v7a version
解决方法
方法一(推荐方法)
从命令行传入 NDK_ROOT 目录,如下:
$ ./build-android-opencv.sh /mnt/work/android/android-sdk-linux/ndk-bundle/
方法二,
根据提示,设置环境变量 ANDROID_NDK,如下
$ export ANDROID_NDK=/mnt/work/android/android-sdk-linux/ndk-bundle/
$ env | grep ANDROID_NDK
ANDROID_NDK=/mnt/work/android/android-sdk-linux/ndk-bundle/
$ ./build-android-opencv.sh
参考资料
[1] Build and install OpenCV and contrib lib on Ubuntu / Android 链接一 链接二(转载)
[2] 如何编译 opencv3 和 opencv_contrib(Linux)
如何为Android平台编译 opencv3 和 opencv_contrib (Linux)的更多相关文章
- 使用android ndk编译x86 so在linux下使用的问题
一直以为android ndk编译x86 so库可以在linxu下运行,结果我试了几次都行不通.后来想了一下,android ndk编译的库应该只能在android设备或模拟器上运行才有效,后来改用 ...
- 如何编译 opencv3 和 opencv_contrib(Linux)
本文以编译并安装OpenCV 3.3.0 为例,安装系统为 Linux x64 (Fedora 21),具体步骤如下: 1. 下载 Source code zip 压缩包 从下面网址,选择 openc ...
- android平台编译IW
不知道怎么编译IW,所以就搜索网络上的博客http://blog.csdn.net/jksl007/article/details/16862435 首先,iw依赖于libnl库,而目前android ...
- 在cocos2d-x-3.0 android 平台编译时提示CocosGUI.h: No such file or directory
分类是个让人蛋疼的事情,所幸自己的博客自己做主.这是个高兴的开始. 每天抽空玩2048,终于忍受不住,于是决定自己从网上download下源码,自己编译一个出来.所有的事情都很容易,除了操蛋的中文注释 ...
- Android 平台电容式触摸屏的驱动基本原理
Android 平台电容式触摸屏的驱动基本原理 Android 平台电容式触摸屏硬件基本原理 Linux 与 Android 的多点触摸协议 Linux输入子系统:事件的编码
- [原]详解如何将cocos2dx项目编译到Android平台上的(方式一:Cywin+NDK)
链接地址:http://m.blog.csdn.net/blog/yhc13429826359/29357815 2014-6-8阅读578 评论0 前言:cocos2dx作为一个开源的移动2D游戏框 ...
- FFmpeg的Android平台移植—编译篇
摘要:本文主要介绍将FFmpeg音视频编解码库移植到Android平台上的编译和基本测试过程. 环境准备: ubuntu-12.04.5 android-ndk64-r10-linux-x86_64. ...
- 【流媒体开发】VLC Media Player - Android 平台源码编译 与 二次开发详解 (提供详细800M下载好的编译源码及eclipse可调试播放器源码下载)
作者 : 韩曙亮 博客地址 : http://blog.csdn.net/shulianghan/article/details/42707293 转载请注明出处 : http://blog.csd ...
- android平台的三个编译命令——make,mm,mmm
在Android源码根目录下,执行以下三步即可编译android: 1. build/envsetup.sh #这个脚本用来设置android的编译环境; 2. lunch #选择编译目标 3 ...
随机推荐
- js的跨域问题和解决办法
我们在开发中,经常会遇到跨域请求数据问题,那么什么是跨域呢?跨域就是js在不用域之间的数据传输或者通信,比如你在使用ajax从另外一个域请求数据,或者你的页面引入了iframe,要从iframe中获取 ...
- git泄露利用脚本
留一下万一之后用得着呢 工作原理 1.解析.git/index文件,找到工程中所有的: ( 文件名,文件sha1 ) 2.去.git/objects/ 文件夹下下载对应的文件 3.zlib解压文件,按 ...
- 如何让一个div居于页面正中间
如何让一个div居于页面正中间 如何让一个div居于页面中间,我今天说的是让一个div水平居中同时垂直居中,而不是简单的top:50%,left:50%.当然,我们就按一开始的思路写一下:top,le ...
- Java解析excel文档并以List<T>输出
/********************************************************工具类start*********************************** ...
- 接口自动化测试框架 :APIAutoTest框架
前言 随着测试技术的发展,接口自动化测试逐渐成为各大公司投入产出比最高的测试技术.介入时间早,执行效率高,稳定性高的优点,让越来越多的公司引入接口自动化测试. 框架简介 APIAutoTest是处理A ...
- Oracle 客户端安装
Oracle 客户端的安装方式一种有两种: 1.Oracle标准客户端 点击下载 这是Oracle提供的标准版11r2的客户端 2.Oracle Database Instant Client(即 ...
- 关于chart不能自行切换出现的报错现象
1.echart 页面菜单不能切换,line和bar不能自行切换 页面上报错误 bar has not been reqired 解决办法,加载bar <script type=" ...
- 【百度之星2014~复赛 解题报告~正解】The Query on the Tree
声明 笔者最近意外的发现 笔者的个人网站http://tiankonguse.com/ 的很多文章被其它网站转载,但是转载时未声明文章来源或参考自 http://tiankonguse.com/ 网站 ...
- 跨域拦截Access-Control-Allow-Origin设置多个origin
在Extjs和java项目碰到了需要同时处理跨域,外部要访问后台接口的问题 原来的代码是这样,只能设置一个extjs前台需要过滤的跨域请求 package com.xgt.config; import ...
- GridView 基本使用
项目中实例一 <asp:GridView ID="gvBatchReceive" runat="server" AutoGenerateColumns=& ...