How to create a cartoon effect – Opencv with Python
by Sergio Canu
We’re going to see in this video how to create a cartoon effect.
A cartoon has 2 important charateristics:
- Really clear edges
- Homogeneus colours
Starting from an original image taken with a camera we’re going to give to it a cartoon effect keeping in mind these 2 charateristics.
import cv2 import numpy as np img = cv2.imread("adventure.jpeg") # 1) Edges gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) gray = cv2.medianBlur(gray, 5) edges = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 9, 9) # 2) Color color = cv2.bilateralFilter(img, 9, 300, 300) # 3) Cartoon cartoon = cv2.bitwise_and(color, color, mask=edges) cv2.imshow("Image", img) cv2.imshow("Cartoon", cartoon) cv2.imshow("color", color) cv2.imshow("edges", edges) cv2.waitKey(0) cv2.destroyAllWindows()
Hi there, I’m the founder of Pysource.
I’m a Computer Vision Consultant, developer and Course instructor.
I help Companies and Freelancers to easily and efficiently build Computer Vision Software.
Learn to build Computer Vision Software easily and efficiently.
This is a FREE Workshop where I'm going to break down the 4 steps that are necessary to build software to detect and track any object.Sign UP for FREE
Detect and Track any Object (Full Videocourse)
You can Build Software to detect and track any Object even if you have a basic programming knowledge.