Skip to content

tobybreckon/python-examples-ip

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python Image Processing OpenCV Teaching Examples

OpenCV Python image processing examples used for teaching within the undergraduate Computer Science programme at Durham University (UK) by Prof. Toby Breckon.

Python - PEP8

All tested with OpenCV 3.x / 4.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

More generally most of the examples accessing camera or video can be used as follows:

python3 ./skeleton.py -h
usage: skeleton.py [-h] [-c CAMERA_TO_USE] [-r RESCALE] [video_file]

Perform ./skeleton.py example operation on incoming camera/video image

positional arguments:
  video_file            specify optional video file

optional arguments:
  -h, --help            show this help message and exit
  -c CAMERA_TO_USE, --camera_to_use CAMERA_TO_USE
                        specify camera to use
  -r RESCALE, --rescale RESCALE
                        rescale image by this factor

Most run with a webcam connected or from a command line supplied video file of a format OpenCV supports on your system (supplied as a command line argument as per above).

Demo source code is provided "as is" to aid learning and understanding of topics on the course and beyond.


Background:

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.


How to download and run:

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: x.x.x
.. do we have the Open CV Contrib Modules: xxxx
We are using numpy: x.x.x
We are using matplotlib: x.x.x
.. and this is in Python: x.x.x (default, xxxxx) [xxx]

More generally an extended set of OpenCV functionality tests is available (used to check OpenCV itself is working) and also a simple bash shell script (test_all.sh) to run through all the examples for semi-automated testing.


Re-usable Exemplar Components (Python Classes):

This codebase contains the following re-usable exemplar elements:

  • camera_stream.py - a re-usable threaded camera class, that is call compatible with the existing OpenCV VideoCapture class, designed to always deliver the latest frame from a single camera without buffering delays (used by all examples if available).

The master copy of the above is available from the the OpenCV Python Computer Vision Examples used for Teaching repository.


Reference:

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)

@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.