• Stars
    star
    180
  • Rank 211,828 (Top 5 %)
  • Language
    Python
  • License
    GNU Lesser Genera...
  • Created almost 8 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

OpenCV Python Computer Vision Examples used for Teaching

Python Computer Vision OpenCV Teaching Examples

OpenCV Python computer vision 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

Background:

Directly adapted (and in some cases extended/added to) 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 in some cases.

A related supporting set of Python Image Processing OpenCV Teaching Examples are also available covering basic image processing operations.


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-cv.git
cd python-examples-cv
python3 ./<insert file name of one of the examples>.py [optional video file]

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). For examples each individual .py example file can be used as follows:

$ python3 ./generic_interface.py -h
usage: generic_interface.py [-h] [-c CAMERA_TO_USE] [-r RESCALE] [-fs]
                            [video_file]

Perform ./generic_interface.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

For several of the demos that largely rely on effective demonstration using just a single output window - press the "f" key to run fullscreen. In all examples press "x" to exit.

Use script sh download-models.sh to download CNN model files associated with some examples.


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

  • h_concatenate() - a re-usable function for horiozontal image concatenation for display in single window handling variations in size/channels (see chromaticity_lightness.py).


References:

If referencing these examples in your own work (e.g "... based on the implementation of REF..."), please reference the related research work from which these sample OpenCV reference implementations were derived (in terms of parameters choice etc., presented in bibtex format).

For the SGBM stereo vision and camera calibration examples, reference:

@Article{mroz12stereo,
  author = 	 {Mroz, F. and Breckon, T.P.},
  title = 	 {An Empirical Comparison of Real-time Dense Stereo Approaches for use in the Automotive Environment},
  journal =  {EURASIP Journal on Image and Video Processing},
  year =     {2012},
  volume = 	 {2012},
  number = 	 {13},
  pages = 	 {1-19},
  publisher = {Springer},
  url = 	 {https://breckon.org/toby/publications/papers/mroz12stereo.pdf},
  doi = 	 {10.1186/1687-5281-2012-13}
}

For the Mixture of Gaussian (MOG) background subtraction and Kalman filtering example, reference:

@InProceedings{kundegorski14photogrammetric,
  author = 	 {Kundegorski, M.E. and Breckon, T.P.},
  title = 	 {A Photogrammetric Approach for Real-time 3D Localization and Tracking of Pedestrians in Monocular Infrared Imagery},
  booktitle = {Proc. SPIE Optics and Photonics for Counterterrorism, Crime Fighting and Defence},
  year = 	    {2014},
  month =     {September},
  volume =    {9253},
  number =    {01},
  publisher = {SPIE},
  pages =     {1-16},
  url = 	 {https://breckon.org/toby/publications/papers/kundegorski14photogrammetric.pdf},
  doi = 	 {10.1117/12.2065673}
}

For the DoG, Canny, contour, Harris and Sobel examples, please reference:

@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},
  note = {ISBN-13: 978-0470844731},
}

For all other examples reference the original paper as outlined in the OpenCV manual or the header comment of the .py example file.


If you find any bugs raise an issue (or much better still submit a git pull request with a fix) - [email protected]

"may the source be with you" - anon.

More Repositories

1

fire-detection-cnn

real-time fire detection in video imagery using a convolutional neural network (deep learning) - from our ICIP 2018 paper (Dunnings / Breckon) + ICMLA 2019 paper (Samarth / Bhowmik / Breckon)
Python
533
star
2

solomon-breckon-book

Fundamentals of Digital Image Processing: A Practical Approach with Examples in Matlab - Solomon / Breckon, 2010
MATLAB
43
star
3

cpp-examples-ipcv

C++ Image Processing and Computer Vision OpenCV Examples used for Teaching
C++
27
star
4

stereo-disparity

a small selection of tools for calculating disparity and working with output from the CR MultiSense S21 stereo camera
Python
26
star
5

python-examples-ip

OpenCV Python Image Processing Examples used for Teaching
Python
25
star
6

zed-opencv-native-python

Native stereo capture from the StereoLabs ZED USB 3 series of stereo cameras with OpenCV in Python
Python
19
star
7

chroma-keying

a set of simple excercises in colour filtering from a live video image (inc. invisibility cloaking)
Python
16
star
8

c-examples-ipcv

Legacy C language Image Processing and Computer Vision OpenCV Examples used for Teaching
C++
11
star
9

cpp-examples-ml

Legacy OpenCV Machine Learning Examples (2.4.x, C++)
C++
10
star
10

DoG-saliency

reference implementation of Real-time Salient Object Detection based on Division of Gaussians [Katramados/Breckon, 2011]
Python
8
star
11

irview

Infrared (Thermal) Video Viewer - False Colour Mapping
C++
7
star
12

python-examples-ml

Python Machine Learning Examples used for Teaching
Python
6
star
13

mosaic-lab

a set of supporting files for a Python based teaching lab in generating mosaic images from a live webcam
Python
5
star
14

java-examples-cv

Java Image Processing and Computer Vision OpenCV Examples used for Teaching
Java
4
star
15

python-cnn-tools-test

a set of simple tools to check if we have TensorFlow, Keras and PyTorch setup correctly to use GPU
Python
3
star
16

shell-tools

a small set of useful Unix / Linux command line tools
Shell
3
star
17

correlation-ga

A C++ Teaching Example for a Genetic Algorithm (GA) based on Image Correlation
C++
1
star
18

gts-tools

simple, useful tools for working with GTS (GNU Triangulated Surface library) surfaces
C++
1
star
19

opencv-record-windows

a header class file hack to automagically (intercept and) record OpenCV windows to a movie file with minimal code additions
C++
1
star
20

roviolib

Rovio Robot C++ API Control Library
C++
1
star