Image Recognition Method OpenCV on the Raspberry Pi

Setup on Raspian Linix

Pre-compiled: If it works, do this... It prolly won't, but it's worth a shot.

sudo apt-get install libopencv-dev

From Source: as per https://ariandy1.wordpress.com/2013/02/13/raspberry-pi-rasbian-opencv/

  1. Make sure everything is up to date
    sudo apt-get update
    sudo apt-get upgrade
    sudo rpi-update

     
  2. Install the tools (probably already installed)
    sudo apt-get install build-essential cmake pkg-config
  3. Paste all the folowing dependancy installations into the terminal window:
    sudo apt-get -y install build-essential
    sudo apt-get -y install cmake
    sudo apt-get -y install pkg-config
    sudo apt-get -y install libpng12-0 libpng12-dev libpng++-dev libpng3
    sudo apt-get -y install libpnglite-dev libpngwriter0-dev libpngwriter0c2
    sudo apt-get -y install zlib1g-dbg zlib1g zlib1g-dev
    sudo apt-get -y install libjasper-dev libjasper-runtime libjasper1
    sudo apt-get -y install pngtools libtiff4-dev libtiff4 libtiffxx0c2 libtiff-tools
    sudo apt-get -y install libjpeg8 libjpeg8-dev libjpeg8-dbg libjpeg-prog
    sudo apt-get -y install libavcodec53 libavcodec-dev libavformat53 libavformat-dev
    sudo apt-get -y install libavutil51 libavutil-dev libswscale2 libswscale-dev
    sudo apt-get -y install libgstreamer0.10-0-dbg libgstreamer0.10-0 libgstreamer0.10-dev
    sudo apt-get -y install libxine1-ffmpeg libxine-dev libxine1-bin
    sudo apt-get -y install libunicap2 libunicap2-dev
    sudo apt-get -y install libdc1394-22-dev libdc1394-22 libdc1394-utils
    sudo apt-get -y install swig
    sudo apt-get -y install python-numpy
    sudo apt-get -y install libpython2.6 python-dev python2.6-dev
    sudo apt-get -y install libjpeg-progs libjpeg-dev
    sudo apt-get -y install libgstreamer-plugins-base0.10-dev
    sudo apt-get -y install libqt4-dev libgtk2.0-dev
     
    
  4. Manually install x264:
    sudo apt-get remove x264 x264-dev
     
    wget ftp://ftp.videolan.org/pub/videolan/x264/snapshots/x264-snapshot-20120528-2245-stable.tar.bz2
    tar -xvf x264-snapshot-20120528-2245-stable.tar.bz2
    cd x264-snapshot-20120528-2245-stable/
    ./configure --enable-shared --enable-pic
    make
    sudo make install
    cd ..
     
    
  5. Manually install ffmpeg: (note the configure line below is entered all on one line.)
    sudo apt-get remove ffmpeg
     
    wget http://ffmpeg.org/releases/ffmpeg-0.11.1.tar.bz2
    echo "Installing ffmpeg"
    tar -xvf ffmpeg-0.11.1.tar.bz2
    cd ffmpeg-0.11.1/
    ./configure --enable-gpl --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb \
    --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid \
    --enable-nonfree --enable-postproc --enable-version3 --enable-x11grab --enable-shared --enable-pic make sudo make install cd ..
  6. Maunally install l4v:
    wget http://www.linuxtv.org/downloads/v4l-utils/v4l-utils-0.8.8.tar.bz2
    tar -xvf v4l-utils-0.8.8.tar.bz2
    cd v4l-utils-0.8.8/
    make
    sudo make install
    cd ..
     
    
  7. Download the current version of OpenCV (replace version with the actual version)
    tar -xjvf  OpenCV-version.tar.bz2
    rm OpenCV-version.tar.bz2
    cd OpenCV-version/
    mkdir build
    cd build/
     
    
  8. Creat a standard configruation. Note, the following is entered all on one line
     
    sudo cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_NEW_PYTHON_SUPPORT=ON -D BUILD_EXAMPLES=ON .. | sudo tee ./CMAKE.log
     
    Check the CMAKE.log file to make sure there are no errors and that if found all the libraries. If there are missing files, find them and point OpenCV installer at them (e.g. with a symlink)
  9. Do the big compile. You probably want to start a new screen -S OpenCVInst then
    sudo su -
    make | tee make.log && make install | tee make_install.log
     
    Now you can detach the screen with Ctrl+a Ctrl+d and let it run. You can check the status with:
    tail -f make.log
     
    Compile times of overnight are the norm.
  10. Tell Linux about the new libraries with
    sudo echo /usr/local/lib>/etc/ld.so.conf.d/opencv.conf
    sudo ldconfig /etc/ld.so.conf.d
    sudo echo PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig>>/etc/bash.bashrc
    sudo echo export PKG_CONFIG_PATH>>/etc/bash.bashrc

See also: