A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/blogs/cartooning-an-image-using-opencv-python/ below:

Cartooning an Image using OpenCV - Python

Cartooning an Image using OpenCV - Python

Last Updated : 11 Aug, 2025

Cartooning an image turns a normal photo into a fun, animated-style picture. With OpenCV, we do this by smoothing the image to simplify colors and detecting edges to create outlines. Combining these steps makes the photo look like a cartoon.

Prerequisites: Opencv module

Approach Python Implementation Python
import cv2
img = cv2.imread("Screenshot.png")
if img is None:
    print("Image not found")
    exit()

# Prep grayscale & blur
g = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
g = cv2.medianBlur(g, 5)

# Edges
e = cv2.adaptiveThreshold(g, 255, cv2.ADAPTIVE_THRESH_MEAN_C,
                          cv2.THRESH_BINARY, 9, 9)

# Smooth color
c = cv2.bilateralFilter(img, 9, 250, 250)

# Combine
cartoon = cv2.bitwise_and(c, c, mask=e)

cv2.imshow("Cartoon", cartoon)
cv2.imwrite("cartoon_output.jpg", cartoon)
cv2.waitKey(0)
cv2.destroyAllWindows()

Output:

Original Image Cartoon Output Image

Explanation:


Cartooning an Image using OpenCV – Python


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4