Created
January 30, 2023 10:27
-
-
Save codepediair/474e8ef2f355d6b09c9aeed7b0aaf96c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import numpy as np | |
from tkinter.filedialog import * | |
photo = askopenfilename() | |
img = cv2.imread(photo) | |
grey = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) | |
grey = cv2.medianBlur(grey, 5) | |
edges = cv2.adaptiveThreshold(grey, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 9, 9) | |
#cartoonize | |
color = cv2.bilateralFilter(img, 9, 250, 250) | |
cartoon = cv2.bitwise_and(color, color, mask = edges) | |
cv2.imshow("Image", img) | |
cv2.imshow("Cartoon", cartoon) | |
#save | |
cv2.imwrite("cartoon.jpg", cartoon) | |
cv2.waitKey(0) | |
cv2.destroyAllWindows() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment