Cross-compiling OpenCV

2018-12-28

# Install compiling dependencies

sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev

# Add repo for libjasper-dev

sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
sudo apt update
sudo apt install libjasper1 libjasper-dev

# Create folder

mkdir opencv-build

# Download OpenCV source code
git clone https://github.com/Itseez/opencv.git

mkdir build
cd build

# Running cmake
cmake -DENABLE_VFPV3=ON -DENABLE_VFPV4=ON -DENABLE_NEON=ON -DCMAKE_TOOLCHAIN_FILE=../opencv/platforms/linux/arm-gnueabi.toolchain.cmake ../opencv

# Compile
make -j4
make install

Everything is under ./install

Note that header files for opencv2 are under opencv4 folder. Parameters for compling apps:

OPENCV_INCLUDE=$(LIBPREFIX)/include/opencv4
-I$(OPENCV_INCLUDE)
-lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_flann