Here are the steps I took to get the OpenCV 3.2.0 working in ARM processor (running linaro 3.14.0). The host machine is running Ubuntu 14.04.

Step 1: Setting up the cross compiler

The compiler used is arm-linux-gnueabihf-g++. It can be installed from Ubuntu software center by looking for “gcc-arm-linux-gnueabihf”.

Step 2: Install dependencies for OpenCV

OpenCV has lot of dependencies, the best way is to do the following first and fix the missing ones later.

sudo apt-get build-dep opencv

Step 3: Download OpenCV and contrib modules (optional)

The source code for opencv and opencv_contrib can be downloaded below.

In my case, these two are cloned in the same directory.

Step 4: Build the source code

cd opencv-3.2.0mkdir build_armcd build_armcmake  -DCMAKE_TOOLCHAIN_FILE=../platforms/linux/arm-gnueabi.toolchain.cmake -DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules ..
make install -j 32

If everything works fine, it will build and install the files into build_arm/install

Step 5: Build some OpenCV application

Similarly, compile the application using arm-linux-gnueabihf-g++. Some environment variables need to be set.



Here are some issues I encountered during the process.

Issue 1: ZLIB

The issue arises when the cmake found the zlib installation in my machine but couldn’t find the zlib.h in the make step.

For example, in the cmake stage it reported:

-- Found ZLIB: /usr/lib32/ (found suitable version "1.2.8", minimum required is "1.2.3")
-- Could NOT find JPEG (missing: JPEG_LIBRARY)
-- Could NOT find Jasper (missing: JASPER_LIBRARIES) (found version "1.900.1")
-- Found ZLIB: /usr/lib32/ (found version "1.2.8")

But in make stage it reported:

opencv-3.2.0/3rdparty/libtiff/tif_pixarlog.c:93:18: fatal error: zlib.h: No such file or directory
 #include "zlib.h"

You might tried to find the zlib.h in your machine and point to it (zlib.h in /usr/include and zconf.h in /usr/include/x86_64-linux-gnu). But the problem is that the lib file is not compiled for ARM, so it won’t pass the subsequent make stage.

The solution is to not let the cmake find the zlib installed and use the 3rdparty/zlib instead. I downloaded the zlib-1.2.11 source code from the internet and add the path to the beginning of the C_INCLUDE_PATH and CPLUS_INCLUDE_PATH.

The result is that cmake reported:

-- Could NOT find ZLIB (missing: ZLIB_LIBRARY ZLIB_INCLUDE_DIR) (Required is at least version "1.2.3")

And the 3rdparty/zlib is compiled using the cross compiler.


How to Cross Compile OpenCV 3.2.0 to ARM processor
Tagged on:     

Please tell us what's in your mind ...

%d bloggers like this: