Now that we know how to handle the webcam and keyboard/mouse inputs, let's go ahead and see how to convert a picture into a cartoon-like image. We can convert an image into either a sketch or a colored cartoon image.
The following is an example of what a sketch will look like:
If you apply the cartoonizing effect to the color image, it will look something like this next image:
Let's see how to achieve this:
import cv2 import numpy as np def print_howto(): print(""" Change cartoonizing mode of image: 1. Cartoonize without Color - press 's' 2. Cartoonize with Color - press 'c' """) def cartoonize_image(img, ksize=5, sketch_mode=False): num_repetitions, sigma_color, sigma_space, ds_factor = 10, 5, 7, 4 # Convert image to grayscale img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # Apply median filter to the grayscale image img_gray = cv2.medianBlur(img_gray, 7) # Detect edges in the image and threshold...