12
Embedded Programming and Robotics Lesson 17 The OpenCV (Computer Vision) Library The OpenCV Library 1

Embedded Programming and Robotics Lesson 17 The OpenCV (Computer Vision) Library The OpenCV Library1

Embed Size (px)

Citation preview

Page 1: Embedded Programming and Robotics Lesson 17 The OpenCV (Computer Vision) Library The OpenCV Library1

The OpenCV Library 1

Embedded Programming and

RoboticsLesson 17

The OpenCV (Computer Vision) Library

Page 2: Embedded Programming and Robotics Lesson 17 The OpenCV (Computer Vision) Library The OpenCV Library1

The OpenCV Library 2

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 packagessudo apt-get install libjpeg8-dev libtiff4-dev libjasper-dev libpng12-dev• Install the GTK development librarysudo apt-get install libgtk2.0-dev

Page 3: Embedded Programming and Robotics Lesson 17 The OpenCV (Computer Vision) Library The OpenCV Library1

The OpenCV Library 3

Install Required Software

• Install video I/O packagessudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev• Install openCV optimization libraries:sudo apt-get install libatlas-base-dev gfortran• Install pipwget https://bootstrap.pypa.io/get-pip.pysudo python get-pip.py

Page 4: Embedded Programming and Robotics Lesson 17 The OpenCV (Computer Vision) Library The OpenCV Library1

The OpenCV Library 4

Install Required Software

• Install virtualenv and virtualenvwrappersudo pip install virtualenv virtualenvwrapper• Then, update your ~/.profile file to include the following lines# virtualenv and virtualenvwrapperexport WORKON_HOME=$HOME/.virtualenvssource /usr/local/bin/virtualenvwrapper.sh• Reload your profilesource ~/.profile

Page 5: Embedded Programming and Robotics Lesson 17 The OpenCV (Computer Vision) Library The OpenCV Library1

The OpenCV Library 5

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

Page 6: Embedded Programming and Robotics Lesson 17 The OpenCV (Computer Vision) Library The OpenCV Library1

The OpenCV Library 6

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/downloadunzip opencv-2.4.10.zipcd opencv-2.4.10

Page 7: Embedded Programming and Robotics Lesson 17 The OpenCV (Computer Vision) Library The OpenCV Library1

The OpenCV Library 7

Install Required Software

• Set up the build:• mkdir buildcd buildcmake -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 ..

Page 8: Embedded Programming and Robotics Lesson 17 The OpenCV (Computer Vision) Library The OpenCV Library1

The OpenCV Library 8

Install Required Software

• Compile openCV:make• Finally, install openCV:sudo make installsudo ldconfig• OpenCV should now be installed in /usr/local/lib/python2.7/site-

packages

Page 9: Embedded Programming and Robotics Lesson 17 The OpenCV (Computer Vision) Library The OpenCV Library1

The OpenCV Library 9

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.soln -s /usr/local/lib/python2.7/site-packages/cv.py cv.py

Page 10: Embedded Programming and Robotics Lesson 17 The OpenCV (Computer Vision) Library The OpenCV Library1

The OpenCV Library 10

Install Required Software

• Give your OpenCV and Python installation a test drive:workon cvPython>>> 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.

Page 11: Embedded Programming and Robotics Lesson 17 The OpenCV (Computer Vision) Library The OpenCV Library1

The OpenCV Library 11

Install Required Software