Deconstructing the code

When you run the preceding program, you will see a window with a video stream from the webcam. If you press S, the video stream will change to sketch mode, and you will see its pencil-like outline. If you press C, you will see the color-cartoonized version of the input stream. If you press any other key, it will return to the normal mode.

Let's look at the cartoonize_image function and see how we did it. First, we converted the image to a grayscale image, and ran it through a median filter. Median filters are very good at removing salt and pepper noise. This is the kind of noise where you see isolated black or white pixels in the image. It is common in webcams and mobile cameras, so we need to filter it out before ...

Get OpenCV 3.x with Python By Example - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.