introduction to opencv and python - unict · matlab/octave, c#, perl, ch, ... introduction to...
TRANSCRIPT
Introduction toOpenCV and Python
Antonino Furnari
www.dmi.unict.it/~furnari/
Introduction to OpenCV and Python - Computer Vision 2016/2017 - IPLAB - University of Catania
OpenCV – Overview
● Initially launched in 1999 as an Intel Researchinitiative to advance CPU-intensive applications,later supported by Willow Garage and nowsupported by Itseez;
● Cross platform, free for use and released under theBDS licence (releasing the application with an opensource licence is not mandatory!);
Introduction to OpenCV and Python - Computer Vision 2016/2017 - IPLAB - University of Catania
OpenCV – Goals
➢ Advance vision research by providing open andoptimized cod for basic vision. No morereinventing the wheel!
➢ Provide a common infrastructure for developers;
➢ Advance vision-based commercial applications bymaking portable, performance-optimized codeavailable for free.
Introduction to OpenCV and Python - Computer Vision 2016/2017 - IPLAB - University of Catania
OpenCV – Platforms
➢ Supports Windows, Linux, macOS, FreeBSD,NetBSD, OpenBSD, Android, iOS, Maemo,BlackBerry 10;
➢ Written in C++ with bindings for Python, Java,MATLAB/OCTAVE, C#, Perl, Ch, Haskell and Ruby;
➢ CUDA and OpenCL based GPU interfaces are inprogress.
Introduction to OpenCV and Python - Computer Vision 2016/2017 - IPLAB - University of Catania
OpenCV – Main Modules
Introduction to OpenCV and Python - Computer Vision 2016/2017 - IPLAB - University of Catania
core basic data structures and basic functions used by all other modules
imgproc image filtering, geometrical transformations, color space conversion
imgcodecs Image file reading and writing
videoio Media Input/Output
highgui high level user interface
video video analysis, motion estimation, background subtraction, tracking
calib3d single and stereo camera calibration, 3D reconstruction
features2d feature extraction, descrition and matching
objdetect object detection
ml machine learning and pattern recognition (e.g., k-means, SVM, knn)
superres super resolution
stitching images stitching
superres super resolution
videostab video stabilization
Prototyping vs Developing
In the past, Computer Vision researchers used MATLABfor prototyping and C++/OpenCV for deployment.MATLAB is excellent to rapidly test new ideas:
✓fast to code and debug;✓extensive library for (practically) everything;X slow to execute;X makes it hard to organize your code and is not great for big
projects.
C++/OpenCV is great to build optimize software:✓offers optimized implementation for many CV algorithms;✓allows to easily scale to big projects;X slow to codeX makes debugging very hard
Introduction to OpenCV and Python - Computer Vision 2016/2017 - IPLAB - University of Catania
Python + OpenCV(one ring to rule them all)
We will use Python + OpenCV to get the best of bothworlds.
Python is good for both prototyping anddevelopment:
• easy to learn, easy to write and read code;
• with IPython and scipy, it is powerful for scientificcalculus (like MATLAB!);
• can be used for scripting, prototyping, scientificcomputation and development in a very natural way;
• Libraries (practically) for everything;
Introduction to OpenCV and Python - Computer Vision 2016/2017 - IPLAB - University of Catania
Note about versions
You can install different versions of Python and OpenCV. You are free to experiment, but we willconsider the following setup:
• Python 2.7: is the most «mature» branch of Python;
• OpenCV 2.4.11: is the OpenCV version with the best documentation: http://docs.opencv.org/2.4/.
• You will also need the scipy stack including:• numpy for scientific calculus (matrix operations etc.);
• matplotlib to plot data and show images;
• IPython provides an interactive shell for prototyping.
Introduction to OpenCV and Python - Computer Vision 2016/2017 - IPLAB - University of Catania
Scipy + OpenCV installation
The easiest way to install the scipy stack is to choose aPython distribution. We will consider Anaconda,provided by continuum analytics:
• Download Anaconda 4.3 (Python 2.7 version) fromhttps://www.continuum.io/;
• Install OpenCV 2.4.11 from anaconda prompt:
conda install -c menpo opencv=2.4.11
This will install a number of tools, including:• Anaconda prompt;• IPython console;• Jupyter notebooks;• Spyder;
Introduction to OpenCV and Python - Computer Vision 2016/2017 - IPLAB - University of Catania
IPython
The core of a scipy distribution is IPython. It providesa powerful interactive shell in which you can do everything Python can do.
Introduction to OpenCV and Python - Computer Vision 2016/2017 - IPLAB - University of Catania
However, it is usuallyconvenient to use more sophisticated user interfaces such asan IDE.
Python: two paths you can go by(but in the long run there’s still time to change the road you’re on)
Introduction to OpenCV and Python - Computer Vision 2016/2017 - IPLAB - University of Catania
full featured IDE Jupyter notebooks
Full featured IDE
An IDE, similar to MATLAB,such as Spyder (installedwith Anaconda by default).Other choices are alsoavailable.
The workflow is similar tothose of all interpretedlanguages: write your .pyfile, execute, debug etc.
Good for development.
Introduction to OpenCV and Python - Computer Vision 2016/2017 - IPLAB - University of Catania
Jupyter Notebooks
A web interface whichallows you to write«notebooks», i.e., filescontaining both the code,the obtained results andformatted text.
Powerful and flexible.
Very good for learning andexperimenting.
Introduction to OpenCV and Python - Computer Vision 2016/2017 - IPLAB - University of Catania
IDE vs Notebook
• IDEs are good for:• big projects with many different modules and classes;
• interactive software (e.g., processing a video stream inrealtime);
• Notebooks are good for:• experimenting new ideas;
• documenting them;
• practical sessions;
• assigments;
Introduction to OpenCV and Python - Computer Vision 2016/2017 - IPLAB - University of Catania
Getting Started with Python + OpenCV
Introduction to OpenCV and Python - Computer Vision 2016/2017 - IPLAB - University of Catania
Resources
• IPython documentation: http://ipython.org/ipython-doc/stable/index.html
• Numpy quickstart tutorial: https://docs.scipy.org/doc/numpy/user/quickstart.html
• Matplotlib documentation: http://matplotlib.org/contents.html
• OpenCV documentation: http://docs.opencv.org/2.4/index.html
Introduction to OpenCV and Python - Computer Vision 2016/2017 - IPLAB - University of Catania