Embedded Programming and Robotics Lesson 17 The OpenCV (Computer Vision) Library The OpenCV Library1
Install Required Software Some of the things in this next are probably already installed, but run this just to be safe sudo apt-get install build-essential cmake pkg-config Install image I/O packages sudo apt-get install libjpeg8-dev libtiff4-dev libjasper-dev libpng12-dev Install the GTK development library sudo apt-get install libgtk2.0-dev The OpenCV Library2
Install Required Software Install video I/O packages sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev Install openCV optimization libraries: sudo apt-get install libatlas-base-dev gfortran Install pip wget sudo python get-pip.py The OpenCV Library3
Install Required Software Install virtualenv and virtualenvwrapper sudo pip install virtualenv virtualenvwrapper Then, update your ~/.profile file to include the following lines # virtualenv and virtualenvwrapper export WORKON_HOME=$HOME/.virtualenvs source /usr/local/bin/virtualenvwrapper.sh Reload your profile source ~/.profile The OpenCV Library4
Install Required Software Create your computer vision virtual environment: mkvirtualenv cv Install the Python 2.7 development tools (Python 3 does not yet support openCV 2.4): sudo apt-get install python2.7-dev Install NumPy since the OpenCV Python bindings represent images as multi-dimensional NumPy arrays: pip install numpy The OpenCV Library5
Install Required Software Download OpenCV and unpack it: wget -O opencv zip unix/2.4.10/opencv zip/download unzip opencv zip cd opencv The OpenCV Library6
Install Required Software Set up the build: mkdir build cd build cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_NEW_PYTHON_SUPPORT=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON.. The OpenCV Library7
Install Required Software Compile openCV: make Finally, install openCV: sudo make install sudo ldconfig OpenCV should now be installed in /usr/local/lib/python2.7/site- packages The OpenCV Library8
Install Required Software To utilize OpenCV within our cv virtual environment, we first need to sym-link OpenCV into our site-packages directory: cd ~/.virtualenvs/cv/lib/python2.7/site-packages/ ln -s /usr/local/lib/python2.7/site-packages/cv2.so cv2.so ln -s /usr/local/lib/python2.7/site-packages/cv.py cv.py The OpenCV Library9
Install Required Software Give your OpenCV and Python installation a test drive: workon cv Python >>> import cv2 >>> cv2.__version__ '2.4.10‘ This lets you bring up the Python shell, import the library, and call a static method to show the version. If this works, all is well. The OpenCV Library10
Install Required Software The OpenCV Library11
References python-on-your-raspberry-pi-2-and-b/ python-on-your-raspberry-pi-2-and-b/ The OpenCV Library12