Please see the following blog post for more details about this code Non-Photorealistic Rendering using OpenCV ( Python, C++ )