赞
踩
参考文章:https://blog.csdn.net/ajianyingxiaoqinghan/article/details/70194392
由于在移植过程中遇到了一点问题 对以上文章做了简单修改,移植成功。记录如下:
Opencv2.4.13 移植到 ARM平台
PC操作系统:Ubuntu 14.04 LTS
OpenCV 2.4.13
编译器:arm-linux-gcc
PC 安装依赖工具
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev
下载编译opencv依赖库源码
zlib-1.2.11
jpegsrc.v9b
libpng-1.6.29
yasm-1.3.0
x264-snapshot-20170415-2245
xvidcore_1.3.3.orig
ffmpeg-2.8.11
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
libxvid下载地址:http://ftp.br.debian.org/debian-multimedia/pool/main/x/xvidcore/
ffmpeg下载地址:http://ffmpeg.org/download.html
创建源码目录 /home/rank/HaiSi/opencv
依赖库安装目录 /home/rank/HaiSi/opencv-depend/
opencv生成库安装目录 /home/rank/HaiSi/opencv-install/
将opencv源码,以及以上依赖解压到源码目录/home/rank/HaiSi/opencv中
目录结构
/home/rank/HaiSi/opencv
–opencv-2.4.13
–zlib-1.2.11
–jpegsrc.v9b
–libpng-1.6.29
–yasm-1.3.0
–x264-snapshot-20170415-2245
–xvidcore_1.3.3.orig
–ffmpeg-2.8.11
开始编译-需要确保交叉工具链已经安装且配置成功
编译zlib
export OPENCV_DEPEND=/home/rank/HaiSi/opencv-depend/
cd /home/rank/HaiSi/opencv/zlib-1.2.11
./configure –prefix=$OPENCV_DEPEND
修改Makefile
CC=arm-linux-gcc
AR=arm-linux-ar
RANLIB=arm-linux-ranlib
LDSHARED=arm-linux-gcc -shared -Wl,-soname,libz.so.1,–version-script,zlib.map
make
make install
完成以后/home/rank/HaiSi/opencv-depend/lib 下会生成zlib的库文件
cp -aR /home/rank/HaiSi/opencv-depend/lib/* 到交叉编译工具链的lib目录 编译libpng会链接到相关的库
cp -r /home/rank/HaiSi/opencv-depend/lib/* 到交叉编译工具链的include目录
编译jpeg
export OPENCV_DEPEND=/home/rank/HaiSi/opencv-depend/
cd /home/rank/HaiSi/opencv/jpegsrc.v9b
./configure –host=arm-linux –prefix=$OPENCV_DEPEND –enable-shared –enable-static CC=arm-linux-gcc
make
make install
完成以后/home/rank/HaiSi/opencv-depend/lib 下会生成jpeg的库文件
cp -aR /home/rank/HaiSi/opencv-depend/lib/* 到交叉编译工具链的lib目录
cp -r /home/rank/HaiSi/opencv-depend/lib/* 到交叉编译工具链的include目录
编译libpng
export OPENCV_DEPEND=/home/rank/HaiSi/opencv-depend/
cd /home/rank/HaiSi/opencv/libpng-1.6.29
./configure –host=arm-linux –prefix=$OPENCV_DEPEND –enable-shared –enable-static CC=arm-linux-gcc
make
make install
完成以后/home/rank/HaiSi/opencv-depend/lib 下会生成libpng的库文件
cp -aR /home/rank/HaiSi/opencv-depend/lib/* 到交叉编译工具链的lib目录
cp -r /home/rank/HaiSi/opencv-depend/lib/* 到交叉编译工具链的include目录
编译yasm
export OPENCV_DEPEND=/home/rank/HaiSi/opencv-depend/
cd /home/rank/HaiSi/opencv/yasm-1.3.0
CC=arm-linux-gcc ./configure –enable-shared –host=arm-linux –disable-asm –prefix=$OPENCV_DEPEND
make
make install
完成以后/home/rank/HaiSi/opencv-depend/lib 下会生成yasm的库文件
cp -aR /home/rank/HaiSi/opencv-depend/lib/* 到交叉编译工具链的lib目录
cp -r /home/rank/HaiSi/opencv-depend/lib/* 到交叉编译工具链的include目录
编译libx264
export OPENCV_DEPEND=/home/rank/HaiSi/opencv-depend/
cd /home/rank/HaiSi/opencv/x264-snapshot-20170415-2245
CC=arm-linux-gcc ./configure –enable-shared –host=arm-linux –disable-asm –prefix=$OPENCV_DEPEND
make
make install
完成以后/home/rank/HaiSi/opencv-depend/lib 下会生成x264的库文件
cp -aR /home/rank/HaiSi/opencv-depend/lib/* 到交叉编译工具链的lib目录
cp -r /home/rank/HaiSi/opencv-depend/lib/* 到交叉编译工具链的include目录
编译libxvidcore
export OPENCV_DEPEND=/home/rank/HaiSi/opencv-depend/
cd /home/rank/HaiSi/opencv/xvidcore_1.3.3.orig
cd ./build/generic
./configure –prefix=$OPENCV_DEPEND –host=arm-linux –disable-assembly CC=arm-linux-gcc
make
make install
完成以后/home/rank/HaiSi/opencv-depend/lib 下会生成libxvidecore的库文件
cp -aR /home/rank/HaiSi/opencv-depend/lib/* 到交叉编译工具链的lib目录
cp -r /home/rank/HaiSi/opencv-depend/lib/* 到交叉编译工具链的include目录
编译ffmpeg-2.8.11
export OPENCV_DEPEND=/home/rank/HaiSi/opencv-depend/
cd /home/rank/HaiSi/opencv/ffmpeg-2.8.11
./configure –prefix=
make
make install
完成以后/home/rank/HaiSi/opencv-depend/lib 下会生成ffmpeg的库文件
cp -aR /home/rank/HaiSi/opencv-depend/lib/* 到交叉编译工具链的lib目录
cp -r /home/rank/HaiSi/opencv-depend/lib/* 到交叉编译工具链的include目录
(注意事项拷贝生成的库和头文件到工具链目录时一定要正确,否则编译不通过找不到依赖库。如果出现这种情况需要检查工具链的中的哪一个lib 和 include才是正确的目录多是几次基本会成功)
编译opencv-2.4.13
cd /home/rank/HaiSi/opencv/opencv-2.4.13
mkdir release
打开编辑 vi toolchain.cmk 内容如下
###########user defined#############
set( CMAKE_SYSTEM_NAME Linux )
set( CMAKE_SYSTEM_PROCESSOR arm )
set( CMAKE_C_COMPILER aarm-linux-gcc )
set( CMAKE_CXX_COMPILER arm-linux-g++ )
###########user defined#############
set( CMAKE_FIND_ROOT_PATH “/home/rank/HaiSi/opencv-depend” )
set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER )
set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
######################################
cmake -DCMAKE_TOOLCHAIN_FILE=toolchain.cmake ../ 由于cmake 配置选项比较多用图形界面 cmake-gui 会方便 所以需要安装 cmake-gui sudo apt-get install cmake cmake-qt-gui 启动 cmake-gui 设置源代码地址为/home/rank/HaiSi/opencv/opencv-2.4.13,构建地址为/home/rank/HaiSi/opencv/opencv-2.4.13/release并对如下选项进行修改: CMAKE_INSTALL_PREFIX(安装目录),默认为/opencv-2.4.9/build/install,改为/home/rank/HaiSi/opencv-install 去掉 WITH_CUDA 去掉 WITH_GTK 去掉 WITH_1394 去掉 WITH_GSTREAMER 去掉 WITH_LIBV4L 去掉 WITH_TIFF 去掉 BUILD_OPENEXR 去掉 WITH_OPENEXR 去掉 BUILD_opencv_ocl 去掉 WITH_OPENCL 配置完成以后点击 Configure,Generate 编辑/home/rank/HaiSi/opencv/opencv-2.4.13/release/CMakeCache.txt CMAKE_EXE_LINKER_FLAGS选项本来为空,此时修改为 -lpthread make make install 会在/home/rank/HaiSi/opencv-install/ 下生成相关的include 和 lib 同样拷贝到到交叉编译工具链的include 和 lib目录
编译测试代码
arm-linux-g++ main.cpp -L/home/rank/HaiSi/opencv-install/lib -lopencv_core -lopencv_imgproc -lopencv_ml -lopencv_highgui -I/home/rank/HaiSi/opencv-install/include -o test
拷贝 测试程序及依赖 test home/rank/HaiSi/opencv-install home/rank/HaiSi/opencv-depend 到arm板子
指定动态库的链接路径
export LD_LIBRARY_PATH=/mnt/opencv-install/lib/:
运行测试程序
查看结果
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。