Sunday, July 13, 2014

OpenCV On Carma Board.


Let's try somethings more interesting with our new toy Carma. Image processing is good example how your GPU monster can help to accelerate your application compared to pure CPU solution.

To start quickly, OpenCV maybe a good solution( Actually implementing function by yourselves should be more optimized - but let's play with this in the next topic). In this topic I assume that you are familiar with OpenCV, at least in your PC environment. If you aren't, please spend sometimes reading these tutorial firstly to get some ideas what OpenCV is and how to use it:
https://help.ubuntu.com/community/OpenCV
http://docs.opencv.org/doc/tutorials/introduction/linux_install/linux_install.html
Ok, let's start our journey.
 

  • Prepare our Carma Board for OpenCV
    •  Install required third party libraries into your Carma board. You can simply use sudo apt-get to install with the network connected. 
    • Install essential tools for buidling OpenCV.
    sudo apt-get install build-essential cmake pkg-config
    • Install required Image I/O libraries.
    sudo apt-get install libjpeg62-dev libtiff4-dev libjasper-dev
    •   Install UI libraries for highgui
    sudo apt-get install libgtk2.0-dev libqt4-dev

    • Install required video input/output libraries.
    sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
    • After installing all required libraries for OpenCV into the Carma board, you need to copy all these library files into your development PC, the location should be in: /usr/arm-linux-gnueabi/lib/ and /usr/lib/arm-linux-gnueabi/. Dont miss this step, otherwise you may face troubles when you build OpenCV later.
  • OpenCV Cross Compilation.
    • Download OpenCV latest source code from the following location
    • Extract the source code package: tar -xvf opencv-2.4.9.tar.gz
    •  Go to opencv-2.4.9, make a directory call carma_build, go to this folder.
    • Edit a config file named cmake_script.sh with the following content:
    •  cmake -DGCC_COMPILER_VERSION="4.5" -DPKG_CONFIG_EXECUTABLE=/usr/bin/arm-linux-gnueabi-pkg-config -DWITH_GTK=ON -DWITH_OPENCL=OFF -DWITH_V4L=ON -DWITH_V4L_2=OFF -DSOFTFP=ON -DUSE_NEON=ON -DCMAKE_SKIP_RPATH=ON -DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda -DCUDA_ARCH_BIN="2.1(2.0)" -DCUDA_ARCH_PTX="" -DWITH_CUDA=ON -DWITH_CUBLAS=ON -DWITH_FFMPEG=OFF -DWITH_TBB=ON -DBUILD_opencv_python=OFF -DBUILD_TBB=ON -DBUILD_ZLIB=ON -DBUILD_TIFF=ON -DBUILD_JASPER=ON -DBUILD_JPEG=ON -DBUILD_PNG=ON -DBUILD_OPENEXR=ON -DCMAKE_TOOLCHAIN_FILE=../platforms/linux/arm-gnueabi.toolchain.cmake ..
    •  Depend on your third party libraries, you can modify accordingly. However, please note few important points: cross compiler version, arm-linux configuration file, cuda toolkit path and cmake toolchain file.
    • After this,  just simply execute: make
    • Copy all libopencv-*.so downto your Carma board, normally into /usr/local/lib
    • Ok, now you can start using OpenCV in your Carma board with GPU enabled.
    • You can test your environment by testing all default test-cases, copy "bin" folder downto your board, execute opencv_perf_gpu
 

No comments:

Post a Comment