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/settings64.sh
  4. Source env_opencv_xilinx file
  5. Download OpenCV-2.4.9 from http://opencv.org/downloads.html
  6. Unzip and untar OpenCV and place it in /home/user/opencv-2.4.9 folder
  7. Download ffmpeg-2.8.10 from http://www.ffmpeg.org/download.html#releases
  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_SYSTEM_PROCESSOR arm )
    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
  23. WITH_1394, WITH_CUDA, WITH_CUFFT, WITH_EIGEN, WITH_GSTREAMER, WITH_GTK, WITH_JASPER, WITH_OPENEXR, WITH_PVAPI, WITH_QT, WITH_TBB, WITH_TIFF, WITH_UNICAP, WITH_V4L, WITH_XINE
  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/libopencv_core.so.2.4.9 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 libopencv_core.so.2.4.9 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:
  29. “FILE(INSTALL DESTINATION “${CMAKE_INSTALL_PREFIX}/lib” TYPE SHARED_LIBRARY FILES
    “/home/jj901099/opencv-2.4.9_arm/build/lib/libopencv_core.so.2.4.9”
    “/home/jj901099/opencv-2.4.9_arm/build/lib/libopencv_core.so.2.4”
    “/home/jj901099/opencv-2.4.9_arm/build/lib/libopencv_core.so”
    )”
  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

My First, Hand Soldered SMD PCB with FPGA – Papilio Duo

This is my first experience with hand soldering SMD components. Assembled the Paplio Duo board by completely hand soldering and it works! I could not have done it without the help and guidance of my fellow members at RLAB. So proud to be able to successfully solder the Xilinx Spartan 6 FPGA on this board :).

Website for this Open Source board is at Gadget Factory .

rajpapilio1

Share Button

Installing Altera Modelsim on 64-bit Ubuntu 14.04 – Linux

I downloaded and the ModelSim-Altera Starter Edition for Linux from Altera (now part of Intel) website at the following webpage:

http://dl.altera.com/?product=modelsim_ae#tabs-2

I then installed it on the 64-bit Ubuntu-14.04. After which I ran the following command from within the bin directory of the installed Modelsim and despite the executable present I got the following error:

command$> ./vsim: No such file or directory

I investigated further on internet and found that I require 386 – 32-bit libraries for Ubuntu since the Modelsim seems to be 32-bit. So I took the following steps on the Linux command prompt:

$>sudo dpkg –add-architecture i386
$>sudo apt-get update
$>sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386
$>sudo apt-get install lib32z1 lib32ncurses5 lib32bz2-1.0

After installing the above, and invoking vsim, I got the following error:

libXft.so.2: cannot open shared object file

So I took the following steps:

$>sudo apt-get install libxft2 libxft2:i386 lib32ncurses5

Then I got the following error and to fix that I took the following steps

libXext.so.6: cannot open shared object file. libXext.so.6 not found

$>sudo apt install libxext6

$>sudo apt install libxext6:i386

And finally, this solved the problem. I was able to invoke Modelsim using ./vsim command.

Share Button

Unboxing My Very Own Zedboard

I purchased my very own Zedboard in order to work on some of the cool FPGA stuff at my home in my Electronic Lab. This board has the state-of-the-art Xilinx Zynq 7020 FPGA. Here I show unboxing the contents of the Zedboard that I received.

IMG_20150925_155200

 

IMG_20150925_155259

 

IMG_20150925_155307

 

IMG_20150925_155316

 

IMG_20150925_155338

 

IMG_20150925_155651

 

 

Share Button