Building OpenCV for ARM Cortex-A8

From Texas Instruments Wiki
Jump to: navigation, search

Important Note:

The software discussed on this site is available for download, but is no longer actively developed. This wiki is in maintenance mode so the information on this wiki may not be current. The software is supported on OMAP Processors E2E forum


Introduction:

This wiki provides instructions that specify how to building OpenCV for ARM Cortex-A8 platform using Cmake in a linux environment. The instructions below have been tested for OpenCV 2.2 by cross compiling it on a Ubuntu 10.04 machine. The toolchain is Codesourcery 2010.12.

Build Instructions

OpenCV 2.2 uses cmake to build. Cmake is a meta-makefile system that generates makefiles. We need to install this first.

  • Update Ubuntu to install and setup cmake
  $ sudo apt-get install cmake cmake-curses-gui
  $ export PATH=$PATH:/opt/arm-2010.12/bin
  $ tar -jxf OpenCV-2.2.0.tar.bz2
  • Cmake supports building outside the source tree. We will use this method to build OpenCV. So, create a directory in $HOME as build
  $ mkdir ~/build && cd ~/build
  • We need to now create a toolchain.cmake file that we will pass to cmake so that it knows how to cross-compile.
  $ vi toolchain.cmake
  • Add the following to toolchain.cmake and save it. This assumes that your NFS targetfs is at ~/targetfs
  set( CMAKE_SYSTEM_NAME Linux )
  set( CMAKE_SYSTEM_PROCESSOR arm )
  set( CMAKE_C_COMPILER arm-none-linux-gnueabi-gcc )
  set( CMAKE_CXX_COMPILER arm-none-linux-gnueabi-g++ )
  set( CMAKE_FIND_ROOT_PATH ~/targetfs )

Important: The CMake build setup in OpenCV 2.2 and earlier does not have NEON ENABLE flag to to take advantage of neon accelearation. Hence please make the following modifications to the file CMakeLists.txt in OpenCV 2.2 to enable neon acceleration.

         # Other optimizations 
         if(USE_O2)    
                set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -O2 -mfpu=neon")
         endif()

This may not be required in later versions of OpenCV since OpenCV 2.3 has the option to enable neon in the CMake build process.

  • Now we run cmake to process and generate makefile
  $ cmake -DCMAKE_TOOLCHAIN_FILE=toolchain.cmake ../OpenCV-2.2.0/
  • When cross compiling for ARM, I found that some items do not build. So, we need to use the cmake curses gui to customize cmake output and re-generate the makefile before we can build. Now launch the cmake curses gui to customize the make file generation
  $ ccmake .
  • This will bring up a screen full of options that can be edited. Make sure that the following items are OFF. If it is ON, you can toggle it by scrolling to the option and hitting Enter
    • BUILD_NEW_PYTHON_SUPPORT
    • BUILD_TESTS
    • WITH_1394
    • WITH_CUDA
    • WITH_EIGEN2
    • WITH_FFMPEG
    • WITH_GSTREAMER
    • WITH_GTK
    • WITH_JASPER
    • WITH_JPEG
    • WITH_OPENEXR
    • WITH_PNG
    • WITH_PVAPI
    • WITH_QT
    • WITH_QT_OPENGL
    • WITH_TBB
    • WITH_TIFF
    • WITH_UNICAP
    • WITH_V4L
    • WITH_XINE

Note: Do not forget to keep the USE_O2 option ON in the configuration to take adavntage of neon acceleration that you added to this option

  • Now, press 'c' to configure and 'g' to generate the makefiles again.
  • Now you are ready to build OpenCV. Run make from the command line and it should generate the OpenCV libraries. You can try to customize the build by turning on the various options that we disabled earlier and see if it builds for you.