120 likes | 137 Views
Learn how to install the OpenCV library for computer vision projects. Follow step-by-step instructions to set up required software and create a virtual environment. Test your installation to ensure proper functionality.
E N D
Embedded Programming and Robotics Lesson 17 The OpenCV (Computer Vision) Library The OpenCV Library
Install Required Software • Some of the things in this next are probably already installed, but run this just to be safe sudoapt-get install build-essential cmakepkg-config • Install image I/O packages sudoapt-get install libjpeg8-dev libtiff4-dev libjasper-dev libpng12-dev • Install the GTK development library sudoapt-get install libgtk2.0-dev The OpenCV Library
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 https://bootstrap.pypa.io/get-pip.py sudopython get-pip.py The OpenCV Library
Install Required Software • Install virtualenv and virtualenvwrapper sudo pip install virtualenvvirtualenvwrapper • 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 Library
Install Required Software • Create your computer vision virtual environment: mkvirtualenvcv • 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 Library
Install Required Software • Download OpenCV and unpack it: wget -O opencv-2.4.10.zip http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.10/opencv-2.4.10.zip/download unzip opencv-2.4.10.zip cd opencv-2.4.10 The OpenCV Library
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 Library
Install Required Software • Compile openCV: make • Finally, install openCV: sudo make install sudoldconfig • OpenCV should now be installed in /usr/local/lib/python2.7/site-packages The OpenCV Library
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 Library
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 Library
Install Required Software The OpenCV Library
References • http://www.pyimagesearch.com/2015/02/23/install-opencv-and-python-on-your-raspberry-pi-2-and-b/ • http://docs.opencv.org/modules/core/doc/intro.html The OpenCV Library