Cross Compiling OpenCV for Xilinx Zynq Arm on Ubuntu Linux OS

I am writing this to keep a log for myself and others whenever I want to cross compile OpenCV for Xilinx Zynq – ARM platform for Ubuntu 14.04. I have followed instructions mentioned on Xilinx-Wiki however I had to tweak quite a few instructions for me at a few places in order to successfully compile OpenCV. I have chosen to download and compile OpenCV-2.4.9 in particular. I did this a while ago so the Xilinx Vivado tools are older versions Vivado 2014.4. I have not tried on other versions of Ubuntu and OpenCV but I think it should still work. I have not listed any OS level dependencies that is required before attempting to start cross compiling OpenCV for Xilinx Zynq. The prerequisite is that the Xilinx Vivado tools have been installed correctly in Ubuntu /opt/Xilinx/ directory and can be invoked from Linux shell prompt. The following are my compilation of the instructions:

  1. First install Xilinx Vivado Tools successfully without any problems in /opt/Xilinx/Vivado folder.
  2. Create a text file (env_opencv_xilinx) with the following environment variables to be sourced so that the Vivado tools are available on command line:
  3. export CROSS_COMPILE=arm-xilinx-linux-gnueabi-
    source /opt/Xilinx/Vivado/2014.4/
  4. Source env_opencv_xilinx file
  5. Download OpenCV-2.4.9 from
  6. Unzip and untar OpenCV and place it in /home/user/opencv-2.4.9 folder
  7. Download ffmpeg-2.8.10 from
  8. Unzip and untar FFmpeg folder. I chose to move the ffmpeg-2.8.10 folder inside the opencv-2.4.9 folder.
  9. Change directory inside the ffmpeg-2.8.10 folder
  10. Run: ./configure –enable-shared –disable-static –cross-prefix=arm-xilinx-linux-gnueabi- –arch=armv7l –target-os=linux –prefix=/home/user/opencv-2.4.9_arm/ffmpeg-2.8.10/
  11. Add the following paths in the env_opencv_xilinx and source it again:
  12. export LD_LIBRARY_PATH=/home/user/opencv-2.4.9_arm/ffmpeg-2.8.10/lib:${LD_LIBRARY_PATH}
    export C_INCLUDE_PATH=/home/user/opencv-2.4.9_arm/ffmpeg-2.8.10/include:${C_INCLUDE_PATH}
    export CPLUS_INCLUDE_PATH=/home/user/opencv-2.4.9_arm/ffmpeg-2.8.10/include:${CPLUS_INCLUDE_PATH}
    export PKG_CONFIG_PATH=/home/user/opencv-2.4.9_arm/ffmpeg-2.8.10/lib/pkgconfig:${PKG_CONFIG_PATH}
  13. Create a folder called build within the opencv-2.4.9 directory.
  14. Add the following lines in a text file called toolchain.make and place it in the /home/user/opencv-2.4.9/ folder:
  15. set( CMAKE_SYSTEM_NAME Linux )
    set( CMAKE_C_COMPILER arm-xilinx-linux-gnueabi-gcc )
    set( CMAKE_CXX_COMPILER arm-xilinx-linux-gnueabi-g++ )
    set( CMAKE_INSTALL_PREFIX /home/user/opencv-2.4.9_arm/build )
    set( CMAKE_FIND_ROOT_PATH /opt/Xilinx/SDK/2014.4/gnu/arm/lin/arm-xilinx-linux-gnueabi )
  16. Copy all the generated SO library files from ffmpeg-2.8.10/lib/ folder to opencv-2.4.9/build/lib folder otherwise OpenCV build process may not find the FFmpeg libraries automatically.
  17. Change directory into the build folder.
  18. I have chosen to set the BUILD_opencv_nonfree=ON as I would like to explore the algorithms available in the non-free of OpenCV.
  19. Run: cmake -D CMAKE_TOOLCHAIN_FILE=toolchain.make -D BUILD_opencv_nonfree=ON /home/user/opencv-2.4.9_arm/
  20. Check the configuration information of OpenCV to confirm the FFmpeg library is detected.
  21. Customise Build options by running: ccmake .
  22. I have chosen to keep WITH_JPEG and WITH_PNG set to ON so that the applications can read and write JPEG and PNG format image files, however Xilinx recommends the following options to be set to OFF
  24. First press ‘c’ then ‘g’ to generate new Makefile. Alternatively edit CMakeCache.txt to modify build options. Check that WITH_FFMPEG=ON in CMakeCache.txt to enable FFmpeg support.
  25. Run: make
  26. Copy and Save build/lib/ in a different folder than lib.
  27. Run: make install .If all goes well then there will not be any errors however I did get an error here saying not found, flagged by the module/core/cmake_install.cmake script. I checked that this particular SO was generated however during the make install process, due to may be some incorrectly generated command in some script it gets removed. I did not have time to debug this in detail however I fond a work around to complete the installation.
  28. Edit build/modules/core/cmake_install.cmake and remove the following lines, this will not generate the error during “make install” and the installation should now complete:
  30. Copy the saved libopencv_core.2.4.9 back to the build/lib/ folder. That’s it.

If I have not missed any step then Opencv-2.4.9 should have now compiled in the opencv-2.4.9/build directory, enjoy image processing.


Share Button

Problem with Cross Compiling OpenCV for Xilinx Zynq – ARM with FFmpeg on Ubuntu Linux OS


I followed the instructions mentioned by Xilinx at in order to cross compile the OpenCV-2.4.9 with FFmpeg for Xilinx Zynq Platform on Ubuntu 14.04.

While configuring the FFmpeg, it gave me the following warning:

“WARNING: arm-xilinx-linux-gnueabi-pkg-config not found, library detection may fail.”

The FFmpeg did compile ok and generated all the necessary SO files however as a result of the warning when I tried to build the OpenCV-2.4.9, I got errors that, etc FFmpeg libraries are not found.

Following errors while build takes place :

/usr/lib/gcc-cross/arm-linux-gnueabi/4.7/../../../../arm-linux-gnueabi/bin/ld: warning:, needed by opencv/ffmpeg-2.7.1/lib/, not found (try using -rpath or -rpath-link)
opencv/ffmpeg-2.7.1/lib/ undefined reference to `swr_close@LIBSWRESAMPLE_1′

/opt/Xilinx/SDK/2014.4/gnu/arm/lin/bin/../lib/gcc/arm-xilinx-linux-gnueabi/4.8.3/../../../../arm-xilinx-linux-gnueabi/bin/ld: warning:, needed by ../../lib/, not found (try using -rpath or -rpath-link)
../../lib/ undefined reference to `avcodec_decode_video2@LIBAVCODEC_56′


The way I have manged to resolve this and successfully cross compile OpenCV is by manually copying the SO libs from FFmpeg/lib folder to the OpenCV/build/lib directory and then rerunning the make. After this OpenCV was successfully built.


Share Button