./configure --prefix=$ZYNQ_CV_INSTALL --shared
make
make install
jpeg安装
./configure --prefix=$ZYNQ_CV_INSTALL --host=arm-xilinx-linux-gnueabi --enable-shared
make
make install
libpng安装
./configure --prefix=$ZYNQ_CV_INSTALL --host=arm-xilinx-linux-gnueabi --enable-arm-neon --enable-shared --with-pkgconfigdir=$ZYNQ_CV_INSTALL/lib/pkgconfig LDFLAGS=-L$ZYNQ_CV_INSTALL/lib CPPFLAGS=-I$ZYNQ_CV_INSTALL/include
make
make install
x264安装
./configure --host=arm-linux --cross-prefix=arm-xilinx-linux-gnueabi- --enable-shared --disable-asm --prefix=$ZYNQ_CV_INSTALL
make
make install
xvidcore安装
cd build/generic/
./configure --prefix=$ZYNQ_CV_INSTALL --host=arm-xilinx-linux-gnueabi --disable-assembly
make
make install
tiff安装
./configure --prefix=$ZYNQ_CV_INSTALL --host=arm-xilinx-linux-gnueabi --enable-shared LDFLAGS=-L$ZYNQ_CV_INSTALL/lib CFLAGS=-I$ZYNQ_CV_INSTALL/include
make
make install
ffmpeg安装
./configure --prefix=$ZYNQ_CV_INSTALL --enable-shared --disable-static --enable-gpl --enable-cross-compile --arch=arm --disable-stripping --target-os=linux --enable-libx264 --enable-libxvid --cc=arm-xilinx-linux-gnueabi-gcc --enable-swscale --extra-cflags=-I$ZYNQ_CV_INSTALL/include --extra-ldflags=-L$ZYNQ_CV_INSTALL/lib --disable-asm
make
make install
#进入文件夹
cd opencv-2.4.9
#建立并进入编译文件夹
mkdir build
cd build
#创建文件
gedit toolchain.cmake
#修改文件,在其中加入如下内容:
###########user defined#############
set( CMAKE_SYSTEM_NAME Linux )
set( CMAKE_SYSTEM_PROCESSOR arm )
set( CMAKE_C_COMPILER arm-xilinx-linux-gnueabi-gcc )
set( CMAKE_CXX_COMPILER arm-xilinx-linux-gnueabi-g++ )
###########user defined#############
set( CMAKE_FIND_ROOT_PATH "/usr/local/arm/opencv-lib" )
set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER )
set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )
######################################
#保存并退出
#添加LDFLAGS环境变量
export LDFLAGS=-Wl,-rpath-link,/usr/local/arm/opencv-lib/lib
#在CentOS中,使OpenCV支持V4L
cp /usr/include/linux/videodev.h /root/CodeSourcery/Sourcery_CodeBench_Lite_for_Xilinx_GNU_Linux/arm-xilinx-linux-gnueabi/libc/usr/include/linux/
#cmake
cmake -D CMAKE_TOOLCHAIN_FILE=toolchain.cmake -D CMAKE_INSTALL_PREFIX=/usr/local/arm/opencv-arm ../
#cmake配置
cmake-gui
接着就打开了cmake-gui的配置界面,在里面可以配置opencv的编译选项。
在cmake GUI中,勾选 Grouped 和 Advanced 选项框,核对以下信息:
1. 源码与安装目录。需要跟下面一模一样
Where is the source code: /home/xilinx-arm-opencv/PetaLinux/package/opencv/opencv-2.4.9
Where to build the binaries: /home/xilinx-arm-opencv/PetaLinux/package/opencv/opencv-2.4.9/build
2. CMAKE项。需要跟下面一模一样
CMAKE_INSTALL_PREFIX : /usr/local/arm/opencv-arm
CMAKE_EXE_LINKER_FLAGS : -Wl,-rpath-link,/usr/local/arm/opencv-lib
CMAKE_C_COMPILER : /root/CodeSourcery/Sourcery_CodeBench_Lite_for_Xilinx_GNU_Linux/bin/arm-xilinx-linux-gnueabi-gcc
CMAKE_CXX_COMPILER : /root/CodeSourcery/Sourcery_CodeBench_Lite_for_Xilinx_GNU_Linux/bin/arm-xilinx-linux-gnueabi-g++
3.WITH项。只勾选如下选项,其他都不勾选
WITH_FFMPEG
WITH_JASPER
WITH_JPEG
WITH_OPENEXR
WITH_PNG
WITH_TIFF
WITH_V4L
界面如下图:
配置完成后点击Configure按钮,会打印出如下信息:(特别需要注意标红的LOG信息与我的是否相同!)
General configuration for OpenCV 2.4.9 =====================================
Version control: unknown
Platform:
Host: Linux 2.6.32-431.el6.i686 i686 Target: Linux arm
CMake: 2.8.12.2
CMake generator: Unix Makefiles
CMake build tool: /usr/bin/gmake
Configuration: Release
C/C++:
Built as dynamic libs?: YES C++ Compiler: /root/CodeSourcery/Sourcery_CodeBench_Lite_for_Xilinx_GNU_Linux/bin/arm-xilinx-linux-gnueabi-g++ (ver 4.6.1)
C++ flags (Release): -fsigned-char -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -O3 -DNDEBUG -DNDEBUG
C++ flags (Debug): -fsigned-char -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -g -O0 -DDEBUG -D_DEBUG C Compiler: /root/CodeSourcery/Sourcery_CodeBench_Lite_for_Xilinx_GNU_Linux/bin/arm-xilinx-linux-gnueabi-gcc
C flags (Release): -fsigned-char -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -O3 -DNDEBUG -DNDEBUG
C flags (Debug): -fsigned-char -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -g -O0 -DDEBUG -D_DEBUG
Linker flags (Release): -Wl,-rpath-link,/usr/local/arm/opencv-lib
Linker flags (Debug): -Wl,-rpath-link,/usr/local/arm/opencv-lib
Precompiled headers: YES
OpenCV modules:
To be built: core flann imgproc highgui features2d calib3d ml video legacy objdetect photo gpu nonfree contrib stitching superres ts videostab
Disabled: world
Disabled by dependency: -
Unavailable: androidcamera dynamicuda java ocl python viz
GUI:
QT: NO
GTK+ 2.x: NO
GThread : NO
GtkGlExt: NO
OpenGL support: NO
VTK support: NO
Media I/O: ZLib: /usr/local/arm/opencv-lib/lib/libz.so (ver 1.2.7) JPEG: /usr/local/arm/opencv-lib/lib/libjpeg.so (ver 90) PNG: /usr/local/arm/opencv-lib/lib/libpng.so (ver 1.5.14) TIFF: /usr/local/arm/opencv-lib/lib/libtiff.so (ver 42 - 4.0.7)
JPEG 2000: build (ver 1.900.1)
OpenEXR: build (ver 1.7.1)
Video I/O:
DC1394 1.x: NO
DC1394 2.x: NO FFMPEG: YES codec: YES (ver 53.61.100) format: YES (ver 53.32.100) util: YES (ver 51.35.100) swscale: YES (ver 2.1.100) gentoo-style: YES
GStreamer: NO
OpenNI: NO
OpenNI PrimeSensor Modules: NO
PvAPI: NO
GigEVisionSDK: NO
UniCap: NO
UniCap ucil: NO V4L/V4L2: YES/YES
XIMEA: NO
Xine: NO
Other third-party libraries:
Use IPP: NO
Use Eigen: NO
Use TBB: NO
Use OpenMP: NO
Use GCD NO
Use Concurrency NO
Use C=: NO
Use Cuda: NO
Use OpenCL: NO
Python:
Interpreter: /usr/bin/python2 (ver 2.6.6)
Java:
ant: NO
JNI: NO
Java tests: NO
Documentation:
Build Documentation: NO
Sphinx: NO
PdfLaTeX compiler: NO
Tests and samples:
Tests: YES
Performance tests: YES
C/C++ Examples: NO Install path: /usr/local/arm/opencv-arm
cvconfig.h is in: /home/xilinx-arm-opencv/PetaLinux/package/opencv/opencv-2.4.9/build
-----------------------------------------------------------------
Configuring done
再点击Generate按钮,即完成了makefile文件的配置。关闭cmake gui界面。
最后编译并安装opencv:
#编译前需要将交叉编译好的依赖库连接或复制到交叉编译工具中去
#否则会在opencv编译时出现类似undefined reference to `png_set_strip_alpha@PNG15_0'的错误
cp -r /usr/local/arm/opencv-lib/lib/* /root/CodeSourcery/Sourcery_CodeBench_Lite_for_Xilinx_GNU_Linux/arm-xilinx-linux-gnueabi/libc/usr/lib/
#编译并安装
make
make install