Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanket758 authored Jan 12, 2021
1 parent fe4f7b9 commit 3910d68
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 0 deletions.
Binary file added Cartoonifier/__pycache__/cartoonify.cpython-38.pyc
Binary file not shown.
17 changes: 17 additions & 0 deletions Cartoonifier/cartoonify.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import cv2


def cartoonify(file):
img = cv2.imread(file)

# Get the edges
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
gray = cv2.medianBlur(gray, 3)
edges = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_MEAN_C,
cv2.THRESH_BINARY, 7, 7)

color = cv2.bilateralFilter(img, 3, 300, 300)

cartoon = cv2.bitwise_and(color, color, mask=edges)

return cartoon
61 changes: 61 additions & 0 deletions Cartoonifier/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import tkinter as tk
from tkinter import filedialog
from tkinter import *
from cartoonify import cartoonify
from PIL import ImageTk, Image
import cv2

top = tk.Tk()
top.geometry('1000x600')
top.title('Cartoonifier')
# top.iconbitmap('/home/sanket/PycharmProjects/Cartoonifier/test.jpeg')
top.configure(background='white')


def save_cartoon(file_path, cartoon):
fp = filedialog.asksaveasfilename(filetypes=(('JPEG files', '*.jpg'),
('PNG Files', '*.png'),
('All Files', '*.*')),
defaultextension=file_path)
cartoon.save(fp)


def show_save_button(file_path, cartoon):
save_b = Button(top, text='Save', command=lambda: save_cartoon(file_path, cartoon), padx=10, pady=5)
save_b.place(relx=0.40, rely=0.86)


def convert(file_path):
cartoon = cartoonify(file_path)
cartoon = cv2.cvtColor(cartoon, cv2.COLOR_BGR2RGB)
cartoon = Image.fromarray(cartoon)
cartoon.thumbnail(((top.winfo_width()/1.8),(top.winfo_height()/1.8)))
im = ImageTk.PhotoImage(cartoon)
label = Label(top, image=im)
label.image = im
label.pack(side='right', expand='yes')
show_save_button(file_path, cartoon)


def show_convert_button(file_path):
convert_b = Button(top, text='Cartoonify', command=lambda: convert(file_path), padx=10, pady=5)
convert_b.place(relx=0.60, rely=0.86)


def upload_image():
file_path = filedialog.askopenfilename()
inp = Image.open(file_path)
inp.thumbnail(((top.winfo_width() / 2.22),
(top.winfo_height() / 2.22)))
im = ImageTk.PhotoImage(inp)
label = Label(top, image=im)
label.image = im
label.pack(side='right', expand='yes')
show_convert_button(file_path)


upload = Button(top, text='Upload an image', command=upload_image, padx=10, pady=5)
upload.configure(background='#adadee', foreground='white', font=('arial', 10, 'bold'))
upload.place(relx=0.20, rely=0.86)

top.mainloop()
Binary file added Cartoonifier/test.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screenshot from 2021-01-12 17-25-37.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added output.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3910d68

Please sign in to comment.