Welcome back to the blog! In this blog we are going to see how you can convert any picture into a cartoon using python programming language.
Here is the program!
--------------------------------------------------------------------------------------------------------------------------
#we will first import the required libraries
import cv2
import numpy as np
#reading the image
img=cv2.imread("code.jpg") #add the path of the image you want to convert or if the image is in the same folder write the name of the image with the correct extension
#working on 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)
#Here it is cartoonization
color=cv2.bilateralFilter(img,9,250,250)
cartoon=cv2.bitwise_and(color,color,mask=edges)
cv2.imshow("Image",img)
cv2.imshow("Edges",edges)
cv2.imshow("Cartoon",cartoon)
cv2.waitkey(0)
cv2.destroyAllWindows()
--------------------------------------------------------------------------------------------------------------------------
Try to run the code, in case of queries or suggestions please tell in the comments section below or kindly email.
Thank you.
Comments
Post a Comment