zlib-1.2.7
export CC=arm-xilinx-linux-gnueabi-gcc
./configure --prefix=$ZYNQ_CV_INSTALL --shared
make
make install
注意:这里需要事先声明CC变量,zlib中没有配置--host之类的选项,第一步的时候可能会报出一个错误,如下图,这个没有关系,我们可以继续进行。
jpeg-8d
./configure --prefix=$ZYNQ_CV_INSTALL --host=arm-xilinx-linux-gnueabi --enable-shared
make
make install
libpng 1.5.14
./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
注意:libpng编译过程中可能会用到zlib之类的库,因此我们需要添加额外的LDFLAGS和CFLAGS变量,更多的信息可以通过./configure --help进行参考
x264-snapshot-20120528-2245-stable
./configure --host=arm-linux --cross-prefix=arm-xilinx-linux-gnueabi- --enable-shared
--disable-asm
--prefix=$ZYNQ_CV_INSTALL
make
make install
xvidcore-1.3.2
cd build/generic
./configure --prefix=$ZYNQ_CV_INSTALL --host=arm-xilinx-linux-gnueabi --disable-assembly
make
make install
注意:xvidcore的编译中可能会调用arm指令集,但是在ZEDBoard上的ARM v7指令集的CortexA9核心只能支持Thumb/Thumb2,因此这里需要禁用汇编选项--disable-assembly
tiff-4.0.3
./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
注意:tiff编译过程中可能会用到zlib之类的库,因此我们需要添加额外的LDFLAGS和CFLAGS变量,更多的信息可以通过./configure --help进行参考
ffmpeg-0.10.3 //注意,这里一定要选ffmpeg-0.X的版本,1,2版本虽然新,但是会生成一个time.h文件,与Linux系统内的time.h会冲突,导致在交叉编译的时候出错
./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
至此,第三方库已经都安装在了opencv-lib文件夹下。下面进行Opencv的交叉移植过程。将OpenCV2.4.3解压到opencv-zed/下,
进入源码目录再新建一个build文件夹并进入build文件夹目录:
在当前目录下新建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 "/opt/zedboard/opencv_zed/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 )
######################################
跟在PC上一样进行配置,这里需要修改PREFIX对应的安装路径,我选择的是/opt/zedboard/opencv_zed/install,然后再选择需要添加的库,如下图:
Detected version of GNU GCC: 46 (406)
Could NOT find Jasper (missing: JASPER_LIBRARY JASPER_INCLUDE_DIR)
checking for module 'libv4l1'
package 'libv4l1' not found
Looking for linux/videodev.h
Looking for linux/videodev.h - found
Looking for linux/videodev2.h
Looking for linux/videodev2.h - found
checking for module 'libavcodec'
package 'libavcodec' not found
checking for module 'libavformat'
package 'libavformat' not found
checking for module 'libavutil'
package 'libavutil' not found
checking for module 'libswscale'
package 'libswscale' not found
Looking for libavformat/avformat.h
Looking for libavformat/avformat.h - found
Looking for ffmpeg/avformat.h
Looking for ffmpeg/avformat.h - not found
Could NOT find PythonLibs (missing: PYTHON_LIBRARIES PYTHON_INCLUDE_PATH)
General configuration for OpenCV 2.4.3 =====================================
Platform:
Host: Linux 2.6.32-431.el6.i686 i686
Target: Linux arm
CMake: 2.6.4
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): -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): -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 -ggdb3
C Compiler: /root/CodeSourcery/Sourcery_CodeBench_Lite_for_Xilinx_GNU_Linux/bin/arm-xilinx-linux-gnueabi-gcc
C flags (Release): -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): -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 -ggdb3
Linker flags (Release):
Linker flags (Debug):
Precompiled headers: YES
OpenCV modules:
To be built: core imgproc flann highgui features2d calib3d ml video objdetect contrib nonfree photo legacy gpu stitching ts videostab
Disabled: world
Disabled by dependency: -
Unavailable: androidcamera java ocl python
GUI:
QT 4.x: NO
GTK+ 2.x: NO
GThread : NO
GtkGlExt: NO
OpenGL support: NO
Media I/O:
ZLib: /opt/zedboard/opencv_zed/opencv-lib/lib/libz.so (ver 1.2.7)
JPEG: /opt/zedboard/opencv_zed/opencv-lib/lib/libjpeg.so (ver 80)
PNG: /opt/zedboard/opencv_zed/opencv-lib/lib/libpng.so (ver 1.5.14)
TIFF: /opt/zedboard/opencv_zed/opencv-lib/lib/libtiff.so (ver 42 - 4.0.3)
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: NO
codec: NO
format: NO
util: NO
swscale: NO
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 TBB: NO
Use OpenCL: NO
Use Eigen: NO
Python:
Interpreter: /usr/bin/python2.6 (ver 2.6.6)
Documentation:
Build Documentation: NO
Sphinx: NO
PdfLaTeX compiler: NO
Tests and samples:
Tests: YES
Performance tests: YES
Examples: NO
Install path: /opt/zedboard/opencv_zed/install
cvconfig.h is in: /opt/zedboard/opencv_zed/OpenCV-2.4.3/build
-----------------------------------------------------------------
Configuring done
我红的标注的地方是特别需要校对的,如果V4l1/V4l2对应的是NO/YES,那说明Viedodev.h这个文件没找到。点击Generate。然后关闭对话框。
make
make install
安装之后,不要着急,还没有大功告成。我们可以利用历程给出的edge_detection.cpp来对交叉编译进行验证。将路径移到edge_detection.cpp所在文件夹下,然后执行:
arm-xilinx-linux-gnueabi-g++ -I /opt/zedboard/opencv_zed/install/include -I /opt/zedboard/opencv_zed/install/include/opencv -L /opt/zedboard/opencv_zed/install/lib -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann ./edge_detection.cpp -o ./edge_detectioni.o
发现,报了很多错,不要着急。仔细一看是在交叉工具链中没有找到第三方库,所以需要将opencv-lib中的各个库文件,拷贝我们的安装文件夹install下(拷贝到交叉工具链下也可以,不过移植过去还是找不到库,所以为了方便之后镜像制作和移植,就拷贝到install下最好):
cp -r /opt/zedboard/opencv_zed/opencv-lib/* /opt/zedboard/opencv_zed/install/
这样就将刚刚编译的第三方库加到了交叉编译工具链中。再一次执行上面的代码,成功编译出edge_detectioni.o。可以查看一下编译出来的文件,可以看到是我们想要的ARM平台执行文件。
这里有个问题,为什么编译出来的是2.6内核执行的文件?Zed不是支持3.3内核的吗?我用交叉编译工具应该是编译出来3.3内核的执行文件啊。我还是初学者,各位可以帮我解决一下疑问。
我们目前已经算是成功了。但是我不想用两个PC机啊!所以我把opencv_zed这个文件夹压缩打包转移到了Ubuntu13.10的虚拟机上!在同样了路径下解压,跟之前的路径保持一样。然后同样利用交叉编译指令进行.cpp文件的交叉编译。成功!说明,尽管CentOS6.5与Ubuntu13.10的内核不同,但是文件神马的都是通用的,不愧都是Linux的孪生兄弟。
制作镜像之后挂在到文件系统中,我选择的是/usr/local/这个路径,具体步骤:
制作镜像的方法:OpenCV库:
dd if=/dev/zero of=cv_lib.img bs=1M count=120//这里的count与bs组合起来表示制作120M的镜像,具体可以根据实际链接库总的大小来设置count
mkfs.ext4 -F cv_lib.img
chmod 777 cv_lib.img
mount cv_lib.img -o loop /mnt
cp -rf $ZYNQ_CV_INSTALL/* /mnt
umount /mnt
在开发板上跑程序,发现不行,原来是缺少了stdc++的库,因此需要将交叉编译工具下的stdc++库拷贝到镜像中来:
cp /root/CodeSourcery/Sourcery_CodeBench_Lite_for_Xilinx_GNU_Linux/arm-xilinx-linux-gnueabi/libc/usr/lib/libstdc++.so* /opt/zedboard/opencv_zed/install/lib
重新制作镜像,然后在zed上运行程序,结果如下图:

说明这三种图片格式都是支持的,移植成功。对于是否支持V4l,我也做了验证,在zed上用Qt+Opencv实现了USB摄像头图像的采集,没有用到超全天晴的方法,完全是依赖Opencv的视频接口实现的。
希望上面的方法能够对你有帮助。