opencv交叉编译环境搭建-aarch64

#背景

要将交叉编译应用到64位arm端(rockchip)运行,应用使用到opencv

#版本

PC虚拟机: ubuntu16.04

opencv: 3.4.4

交叉编译器: aarch64-linux-gnu 5.4.0

相关依赖:

zlib-1.2.11

jpegsrc.v9b

libpng-1.6.36

yasm-1.3.0

x264-snapshot

xvidcore_1.3.3.orig

ffmpeg-4.1

各个依赖库下载地址:

zlib官网:http://www.zlib.net/

libjpeg下载地址:http://www.ijg.org/files/

libpng下载地址:http://www.libpng.org/pub/png/libpng.html

yasm下载地址:http://yasm.tortall.net/Download.html

x264下载地址:http://www.videolan.org/developers/x264.html

或者:http://download.videolan.org/pub/videolan/x264/snapshots/

libxvid下载地址:http://ftp.br.debian.org/debian-multimedia/pool/main/x/xvidcore/

ffmpeg下载地址:http://ffmpeg.org/download.html

opencv下载地址:https://opencv.org/

当然,网页打开可能需要工具,如果不行,可从文末网盘下载。

#编译

编译zlib 
export OPENCV_DEPEND=安装路径
sudo ./configure –prefix=$OPENCV_DEPEND 
修改Makefile 
CC=aarch64-linux-gnu-gcc 
AR=aarch64-linux-gnu-ar 
RANLIB=aarch64-linux-gnu-ranlib 
LDSHARED=aarch64-linux-gnu-gcc -shared -Wl,-soname,libz.so.1,–version-script,zlib.map 
make 
make install 

编译jpeg 
sudo ./configure –host=aarch64-linux-gnu –prefix=$OPENCV_DEPEND –enable-shared –enable-static CC=aarch64-linux-gnu-gcc
make 
make install 

编译libpng 
sudo ./configure –host=aarch64-linux-gnu –prefix=$OPENCV_DEPEND –enable-shared –enable-static CC=aarch64-linux-gnu-gcc
make 
make install 

编译yasm 
sudo CC=aarch64-linux-gnu-gcc ./configure --enable-shared --host=aarch64-linux-gnu --disable-asm --prefix=$OPENCV_DEPEND
make 
make install 

编译libx264 
export OPENCV_DEPEND=/home/rank/HaiSi/opencv-depend/ 
cd /home/rank/HaiSi/opencv/x264-snapshot-20170415-2245 
sudo ./configure --prefix=$OPENCV_DEPEND --enable-shared  --host=aarch64-linux-gnu --cross-prefix=aarch64-linux-gnu-
make 
make install 

编译libxvidcore 
cd ./build/generic 
sudo ./configure --prefix=$OPENCV_DEPEND --host=aarch64-linux-gnu --disable-assembly
make 
make install 

编译ffmpeg-2.8.11 
sudo ./configure --prefix=$OPENCV_DEPEND --enable-shared --disable-static --enable-gpl --enable-cross-compile \

--arch=arm64 --disable-stripping --target-os=linux --enable-libx264 --enable-libxvid --cc=aarch64-linux-gnu-gcc \

--enable-swscale --extra-ldflags=-L$OPENCV_DEPEND/lib --extra-cflags=-I$OPENCV_DEPEND/include
make 
make install 
完成以后将opencv-depend/lib/* 复制到交叉编译工具链的lib目录 
将opencv-depend/lib/* 复制到到交叉编译工具链的include目录

 

编译opencv-3.4.4

cd opencv-3.4.4

mkdir build

cmake-gui (未安装的话apt-get install cmake cmake-qt-gui)

设置源码地址和生成地址(为上面新建的build文件夹)

添加Cache Entry

Name=CMAKE_AR;

Type=FILEPATH

Value = /usr/bin/aarch64-linux-gnu-ar

 

点击configure,选择specify toolchain for cross-compiling

Next

Specify the Toolchain file选择opencv-3.4.4/platforms/linux/aarch64-gnu.toolchain.cmake

Finish

 

默认安装项,或自行增减。

当前项目需要用到libopencv_imgcodecs,所在必须是opencv3版本以上才有此项。

Configure

Generate

关掉cmake

进入build文件夹,

make

make install

 

随后可将build/insall下的库拷贝出来用了。

 

网盘中有相关源码和编译好的opencv

链接:https://pan.baidu.com/s/1kvYvun9TRCDgiZMiYgyqTg

提取码:lpb4

 

#参考:

https://blog.csdn.net/ajianyingxiaoqinghan/article/details/70194392

http://www.bubuko.com/infodetail-2561158.html

https://blog.csdn.net/rank_ck/article/details/82659343

你可能感兴趣的:(人工智能)