Tuesday, 5 February 2013

Compiling OpenCV 2.4.3 for Ubuntu 12.04 and Android Platform

Compiling/Building OpenCV 2.4.3 for Ubuntu 12.04 and Android Platform


Build for Ubuntu 12.04

* Install Required Packages

* GCC 4.4.x or later. :

   sudo apt-get install build-essential

* CMake 2.6 or higher and cmake-gui

Assuming that you have downloaded the OpenCV 2.4.3 source code and unzipped
it to specified directory

* GTK+2.x or higher, including headers (libgtk2.0-dev);

pkgconfig


Python 2.6 or later and Numpy 1.5 or later with developer packages (python-dev, python-numpy);


ffmpeg or libav development packages: libavcodec-dev, libavformat-dev, libswscale-dev;


* libdc1394 2.x;


 libjpeg-dev, libpng-dev, libtiff-dev, libjasper-dev.





* CMAKE-GUI

* Run cmake-gui command
   select the OpenCV source and configure build directory where the make files will be generated.

* Press Configure button 

You may receive error configuration completed/terminated with errors

you can see the error log in the Tab below the option panel

The errors are occuring because the default options enabled are not compatible 
with software packages installed in the system

To resolve the errors  deselect the packages that are not required 

For example :
- i disable WITH_CUDA  as my PC does not have GPU 
hence CUDA toolkit is not installed ( CUDA is for  hetrogenous parallel programming) 

- i disable WITH_GSTREAMER since i had not installed the GSTREAMER package

- i disable WITH_OPENEXR ( OPENEXR is format for HDR images )

- i disable WITH_V4l               ( v4l is video for linux package)

I enable Additional options that are disabled by default
I enable WITH_TBB          

i enable WITH_OPENCL  (OpenCL is open source package for hetrogenous parallel programming)

After that i press the generate option ,and errors are resolved and make files are generated
successfully.

Alternatively you can install the required packages to resolve the dependencies and then proceed to generate the make files successfully.


* To initiate the build  : 
  Go to the build directory configured in the cmake-gui and enter

  make 


 *Install

   to install OpenCV library and header files type
   make install



Build for Android


Download Require Android Pre-Requisites like Android SDK and Android NDK
and note down the paths for the same


*  Export the following shell variables

export ANDROID_NDK=/opt/android-sdk-r8d

* If you are using 64-bit linux 
make sure to install  ia32 shared libraries - transitional package as the NDK requires 32-bit runtime and libraries

* Run cmake-gui
choose a different/new build directory for android build

When you enter configure , a window popup occurs 


* Locate the toolchain 

  file is found in  ${opencv_source_dir}/android/android.toolchain.cmake

    Select Specify tool chain file for cross compiling 

    and enter the tool chain filter located in the above step

*  Android and ARM options

    Select the android-sdk ,android-api level and ARM architecture type if required
    Else it will be compiled with default options
  
application binary interface (ABI) describes the low-level interface between a computer program and the  OS or another program
An embedded-application binary interface (EABI) specifies standard conventions for file formats, data types, register usage, stack frame organization, and function parameter passing of an embedded software program.

   armeabi

   arm-v7a (hardware floating point)
   arm-v7a-with neon (harware floating point and vectorization and SIMD operation)

i selected arm-v7a-with-neon as my Mobile device processor belongs to family that supports armv7 architecture.

This information can be observed when mobile is connected to USB and launching 

the DDMS utility or viewing the device details in eclipse plugin etc.

* Resolving Errors 

 As in the ubuntu case if errors are encountered un-check the packages not applicable or not   required   or install the required packages to resolve the error and click on generate.

* Run make

   After the cmake-gui generates the files successfully go to the build directory and type
   make  to build the files