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/lapack.git
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 compilerCMAKE_CXX_COMPILER
CMAKE_C_COMPILERbuild:
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;
}
- build:
>arm-linux-gnueabihf-g++ TestApp.cpp -o TestApp `pkg-config --cflags --libs opencv4` -L/usr/lib/arm/lib
I hope this will help someone.