OpenCV Python image processing examples used for teaching within the undergraduate Computer Science programme at Durham University (UK) by Prof. Toby Breckon.
All tested with OpenCV 3.x and Python 3.x.
# Example : <................................> processing from a video file
# specified on the command line (e.g. python FILE.py video_file) or from an
# attached web camera
Directly adapted from the C++ and earlier C language teaching examples used to generate the video examples within the ebook version of:
Dictionary of Computer Vision and Image Processing (R.B. Fisher, T.P. Breckon, K. Dawson-Howe, A. Fitzgibbon, C. Robertson, E. Trucco, C.K.I. Williams), Wiley, 2014. [Google Books] [doi]
Notably, the C++ examples may contain further speed optimizations.
Download each file as needed or to download the entire repository and run each try:
git clone https://github.com/tobybreckon/python-examples-ip.git
cd python-examples-ip
python3 ./<insert file name of one of the examples>.py [optional video file]
An extremely simple example to check if OpenCV and the other python libraries commonly needed by these examples are present/working on your system and which version of them is in use, is the version.py example:
python3 ./version.py
which should then output something like this (but with the "x" elements completed specific to your system install):
We are using OpenCV: 3.x.x
.. do we have the Open CV Contrib Modules: xxxx
We are using numpy: 1.x.x
We are using matplotlib: 1.x.x
.. and this is in Python: 3.x.x (default, xxxxx) [xxx]
Demo source code is provided "as is" to aid learning and understanding of topics on the course and beyond.
Most run with a webcam connected or from a command line supplied video file of a format OpenCV supports on your system (otherwise edit the script to provide your own image source).
N.B. you may need to change the line near the top that specifies the camera device to use on some examples below - change "0" if you have one webcam, I have it set to "1" to skip my built-in laptop webcam and use the connected USB camera.
All techniques are fully explained in corresponding section of:
Fundamentals of Digital Image Processing: A Practical Approach with Examples in Matlab, Chris J. Solomon and Toby P. Breckon, Wiley-Blackwell, 2010 ISBN: 0470844736, DOI:10.1002/9780470689776, http://www.fundipbook.com
(which also has Matlab code examples of many of the same techniques here - https://github.com/tobybreckon/solomon-breckon-book.git)
bibtex:
@Book{solomonbreckon10fundamentals,
author = {Solomon, C.J. and Breckon, T.P.},
title = {Fundamentals of Digital Image Processing:
A Practical Approach with Examples in Matlab},
publisher = {Wiley-Blackwell},
year = {2010},
isbn = {0470844736},
doi = {10.1002/9780470689776},
url = {http://www.fundipbook.com}
}
If you find any bugs raise an issue (or much better still submit a git pull request with a fix) - toby.breckon@durham.ac.uk
"may the source be with you" - anon.