-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
imgtosketch.py
65 lines (56 loc) · 2.18 KB
/
imgtosketch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import tkinter as tk
from tkinter import *
from tkinter import filedialog
from tkinter import messagebox as mgbx
import cv2
def convert():
src = src_location.get()
dest = dest_location.get()
image = cv2.imread(src)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
inverted = 255 - gray
blur = cv2.GaussianBlur(inverted, (21, 21), 0)
inverted_blur = 255 - blur
sketch = cv2.divide(gray, inverted_blur, scale = 256.0)
try:
cv2.imwrite(dest+r"/sketch.png", sketch)
mgbx.showinfo("Done", "Successful!")
except:
mgbx.showerror("Error", "The image was not converted!")
def browse_img():
app.files_list = list(filedialog.askopenfilenames(initialdir =r"C:\Users\harsh\OneDrive\Pictures"))
sourceText.insert('1', app.files_list)
def browse_dest():
destinationdirectory = filedialog.askdirectory(initialdir =r"C:\Users\harsh\OneDrive\Pictures")
destinationText.insert('1', destinationdirectory)
app = tk.Tk()
app.geometry("500x500")
app.title("Img to Sketch")
src_location = StringVar()
dest_location = StringVar()
heading = Label(app, text="Python Image to Sketch App",
bg="purple", fg = "white", font=("Algerian",24),
width="500", height="3")
heading.pack()
l1 = Label(text="Select the image to convert : ",
font=("Algerian",18))
l1.place(x=20, y=150)
sourceText = Entry(width=40, textvariable=src_location,
font=18)
sourceText.place(x=20, y=190)
src_browse = Button(text="Browse", font=("ALgerian",18),
command=browse_img)
src_browse.place(x=300, y=230)
l2 = Label(text="Select the destination : ",
font=("Algerian",18))
l2.place(x=20, y=280)
destinationText = Entry(width=40, textvariable=dest_location,
font=18)
destinationText.place(x=20, y=320)
dest_browse = Button(text="Browse", font=("ALgerian",18),
command=browse_dest)
dest_browse.place(x=300, y=360)
con = Button(text="Convert", font=("Algerian",18),
command=convert)
con.place(x=100, y=430)
mainloop()