Cross compiling OpenCV for a ARM based linux system (Xilinx)

asked 2019-07-29 07:59:02 -0600

Aaron Zettler gravatar image

updated 2019-07-29 08:11:10 -0600

I have successfully built OpenCV for a Arm Based linux system (Xilinx) under Ubuntu 18.04. Because i spent a lot of time on this i want to share my methode in this post.

Building Lapack:

The lapack (Linear Algebra PACKage) library is required. To use OpenCV for arm you have to manual build and install lapack. First you have to create a toolchain.make file.

$ gedit toolchain.make

  • Insert the flowing configuration and set your path-to-xilinx-compiler and other params.

    set( CMAKE_SYSTEM_NAME Linux )
    set( CMAKE_SYSTEM_PROCESSOR arm )
    set( CMAKE_C_COMPILER path-to-xilinx-compiler/arm-linux-gnueabihf-gcc )
    set( CMAKE_CXX_COMPILER path-to-xilinx-compiler/arm-linux-gnueabihf-g++ )
    set( CMAKE_INSTALL_PREFIX /usr/lib/arm )
    set( CMAKE_FIND_ROOT_PATH /usr/lib/arm )

    Then download, build and install lapack.

    cwd=$(pwd)
    git clone https://github.com/Reference-LAPACK/l...
    cd lapack/
    mkdir build
    cd build/
    cmake -D CMAKE_TOOLCHAIN_FILE=$toolchainpath ..
    make -j8 #multithreading make
    sudo make install

Building OpenCV:

It is important that the libraries libatlas3-base, libatlas-base-dev and libhdf5-dev are not installed on the system because OpenCV will include them but you wont be able to link them without building the system specific version yourself.

  • configure cmake: you can use the exported cmake command or configure it yourself using cmake-gui like below

    -set these flags and configure a few times

    BUILD_SHARED_LIBS = OFF
    OPENCV_EXTRA_MODULES_PATH = "<extra_modules_path>"
    CMAKE_INSTALL_PREFIX = "<install_prefix_path>"

    -set all these flags to OFF

    WITH_1394
    WITH_CUDA
    WITH_CUFFT X
    WITH_EIGEN
    WITH_GSTREAMER
    WITH_GTK
    WITH_JASPER
    WITH_JPEG
    WITH_OPENEXR
    WITH_PNG
    WITH_PVAPI
    WITH_QT
    WITH_TBB
    WITH_TIFF
    WITH_UNICAP X
    WITH_V4L
    WITH_XINE

    WITH_EIGEN
    WITH_IPP
    BUILD_ZLIB
    BUILD_opencv_gapi
    BUILD_IPP_IW

    -delete EIGEN_INCLUDE_PATH
    -delete all HDF paths
    -set right compiler

    CMAKE_CXX_COMPILER
    CMAKE_C_COMPILER

  • build:

    make -j8

  • install:

    sudo make install

  • pkg-config setup:

    sed -i 's/-lfreetype //g' unix-install/opencv4.pc #remove -lfreetype from file
    sed -i 's/-lharfbuzz //g' unix-install/opencv4.pc #remove -lharfbuzz from file
    sudo cp unix-install/opencv4.pc /usr/lib/x86_64-linux-gnu/pkgconfig

    Sample Program

#include <stdio.h>
#include <opencv2/opencv.hpp>
int main( int argc, char** argv )
{
  cv::Mat testmat;
  printf("Test\n");
  return 0;
} 
  • Add Lapack lib path

    dont forget to add the lapack lib path "-L/usr/lib/arm/lib" to the build command/makefile.

  • build:

    g++ TestApp.cpp -o TestApp `pkg-config --cflags --libs opencv4` -L/usr/lib/arm/lib

I hope this will help someone.

edit retag flag offensive close merge delete