Python Resources

Updated on Feb 5 2022

Python In Other Contexts

Deborah R. Fowler



Python OpenCV

Posted on June 12  2021


OpenCV is a library for computer vision, machine learning and image processing. It can be used in other languages as well. Numpy is a library designed for number crunching and is often used with OpenCV.

PIL is the Python Imaging Library which when support discontinued in 2011, a fork became pillow as its replacement with Python 3.x support.

OpenCV follows a BGR color convention while PIL follows an RGB color convention. There is an excellnt write up on OpenCV for python at
https://docs.opencv.org/master/d0/de3/tutorial_py_intro.html

As an introduction, I found an example of an OpenCV pencil sketch (similar to something you might do in photoshop) at
https://thecleverprogrammer.com/2020/09/30/pencil-sketch-with-python/

The example used takes an image, converts it to gray levels, then inverts it and blurs, inverts again and divides. The images are then displayed.

As an exercise I converted this into PIL as well, changed the variable names to camel case and wrote the images rather than display.


The results are seen below: original test.png, TestCv2.png and TestPIL.png