# Converting An Image To A Cartoon Using OpenCV

Computer vision is one of the hottest fields in Artificial Intelligence with a wide variety of applications. OpenCV is the most popular library used in computer vision with a lot of interesting stuff. If you want to start your journey in computer vision you can start from learning OpenCV. It is easy to understand and implement by everyone. In this article using OpenCV, let’s have fun with converting normal images into cartoons.

We will cover the following steps in this article to convert the image to cartoon:-

1. Importing libraries
3. Detecting edges in the image
4. Converting into grayscale & applying the medium blur
5. Cartoonifying the image

### Converting Image to Cartoon Using OpenCV

Now, let us proceed step-by-step.

Here we are importing the required libraries. If you are working in Google Colab then we need to import google.colab.patches.

```#Importing required libraries
import cv2
import numpy as np

In this step, we will read the image. We have download an image if Virat Kohli from Google Image and will try to perform our experiment on this image.

```#Reading image
from skimage import io
io.imshow(img)```

As we can see that the input image read by OpenCV is being shown as a BGR (Blue-Green-Red) image so we need to convert it to the RGB (Red-Green-Blue).

````#Converting to RGB`
`img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)`
`io.imshow(img)````

### Step-3: Detecting edges

Here we are going to detect the edges in the image using adaptive thresholding methods.

```#Detecting edges of the input image
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
gray = cv2.medianBlur(gray, 5)
io.imshow(edges)```

### Step-4: Cartoonifying image

In this step, we will be cartoonifying the image using bilateral filter method.

```#Cartoonifying the image
color = cv2.bilateralFilter(img, 9, 250, 250)

### Step-5: Final Output (Cartoon Image)

Finally, we will visualize the final output

`io.imshow(cartoon)`

### Conclusion

In the above demonstration, we converted a normal image into a cartoon by implementing a few lines of code using computer vision techniques. we shall have great fun using computer vision techniques.

The complete code of this implementation is available on AIM’s GitHub repository. Please go through this link to find the notebook.

## Our Upcoming Events

### Telegram group

Discover special offers, top stories, upcoming events, and more.

### Discord Server

Stay Connected with a larger ecosystem of data science and ML Professionals

### No, the Infamous 6-Month AI Pause Letter Wasn’t a Failure

Though the AI pause wasn’t adopted, the letter’s impact is evident, says signatory

### AI in Programming is to Collaborate, Not Eliminate

While the potential of AI is unquestionable, a deeper look into its current capabilities suggests that a complete or even a partial AI takeover in programming is unlikely

### Apple Should be Scared of Windows Copilot

Copilot will start its early rollout as part of the free Windows 11 update, beginning on September 26

### Top 5 Libraries in C/C++ for ML in 2023

There are tons of libraries in C/C++ for ML, such as TensorFlow, Caffe, and mlpack

### Tesla Optimus Finally Learns Yoga, Performs Vrikshasana

Jim Fan, senior AI scientist at NVIDIA, has come forward with insights on how exactly Optimus functions with such brilliance

### NVIDIA’s Dominance Set to Surge Further

NVIDIA’s Meteoric Rise in 2023: On Track to Surpass \$50 Billion Revenue, Achieves \$1 Trillion Market Cap, and Forges Global Partnerships for AI Dominance.

### 6 Brilliant JavaScript Frameworks for Every Developer

Although Python and R are more famous for machine learning, Java can serve this purpose effectively, especially if you’re already familiar with it