diff --git a/.idea/Filteristic.iml b/.idea/Filteristic.iml index cd50985..4ad56e7 100644 --- a/.idea/Filteristic.iml +++ b/.idea/Filteristic.iml @@ -5,8 +5,7 @@ - - + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index d56657a..b29c341 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/Tkinter/GUI.py b/Tkinter/GUI.py index ede888d..65e978d 100644 --- a/Tkinter/GUI.py +++ b/Tkinter/GUI.py @@ -8,6 +8,8 @@ import time import cv2 from Tkinter.GUI_Live import camera +from tkinter_custom_button import TkinterCustomButton + # from snapshot import App, videoCapture root = tk.Tk() images = [] @@ -44,15 +46,18 @@ def on_closing(): ########## Home-Page ########## -image= PhotoImage(file ='../assest/image.png',width=700,height=700) -Label(root, image= image, bg="black",).grid(column=0,row=0,columnspan=2) - -importButton = tk.Button(text="Import", padx=90, pady=10, fg="white", bg="#2596be", font=('arial',15), command=importWindow) -importButton.grid(row=1,column=0) - - -cameraButton= tk.Button(text="Camera", padx=90, pady=10, fg="white", bg="#2596be",font=('arial',15), command=videoWindow) -cameraButton.grid(row=1,column=1) +root.geometry("960x630") +image= PhotoImage(file ='../assest/2.png',width=960,height=540) +Label(root, image= image).grid(column=0,row=0,columnspan=2) +Label().grid(column=0,row=1) +importButton =TkinterCustomButton(text="Image", corner_radius=5, command=importWindow,fg_color="#3319CB",hover_color="#005DFE",width=300, + cursor="shuttle",text_font=("sans-serif", 20)) +importButton.grid(row=2,column=0) +Label().grid(column=1,row=1) +cameraButton= TkinterCustomButton(text="Camera", corner_radius=5, command=videoWindow,fg_color="#3319CB",hover_color="#005DFE",width=300, + cursor="shuttle",text_font=("sans-serif", 20)) +# cameraButton.place(relx=0.5, rely=0.5, anchor=CENTER) +cameraButton.grid(row=2,column=1) ########################################### diff --git a/Tkinter/GUI_Image.py b/Tkinter/GUI_Image.py index ba1a9b7..370dd98 100644 --- a/Tkinter/GUI_Image.py +++ b/Tkinter/GUI_Image.py @@ -7,63 +7,22 @@ from PIL import Image, ImageTk from filters_image.image_filtering_face import image_filtering_face import cv2 +from tkinter_custom_button import TkinterCustomButton # root = tk.Tk() images = [] count = 0 next = False entry = "" ######### import Window ########## -def render(image_withfilter,canvas): - image_withfilter = cv2.cvtColor(image_withfilter, cv2.COLOR_BGR2RGB) - photo = ImageTk.PhotoImage(image=Image.fromarray(image_withfilter)) - canvas.create_image(0, 0, anchor="nw", image=photo)\ - .grid(column=2, row=1, columnspan=2) -def next_fun(path,canvas): - global count - - images.append(image_filtering_face( - change_filter[count]['filter'], - path, - change_filter[count]['center'], - change_filter[count]['width'], - change_filter[count]['height'], - change_filter[count]['up'], - change_filter[count]['left'], - change_filter[count]['counte'] - )) - count += 1 - if count == len(change_filter)-1: - count = -1 - render(images[-1],canvas) - -def submit(content): - global entry - entry1 = entry.get() - imgdir = f"../saved/{entry1}.png" - cv2.imwrite(imgdir, content) - entry.delete(0, END) -def saving(content,newWindow): - global entry - sub_btn = tk.Button(newWindow, text='Submit', command=lambda: submit(content)) - entry = tk.Entry(newWindow, width=20, bg="white") - entry.grid(row=1, column=2) - sub_btn.grid(row=2, column=2) - -def image_filter(path, canvas, newWindow): - print('yahia') - images.append( - image_filtering_face(["../assest/tongue.png"], path, [57], [0.6], [1.2], [-25], [0], - [0])) - save = tk.Button(newWindow, text="save", padx=90, pady=10, fg="white", bg="#2596be", - font=('arial', 15), command=lambda: saving(images[-1],newWindow)) - save.grid(row=0, column=4) - next = tk.Button(newWindow, text="next", padx=90, pady=10, fg="white", bg="#2596be", - font=('arial', 15), command=lambda: next_fun(path, canvas)) - next.grid(row=0, column=3) - render(images[-1], canvas) + + + +# mainloop() + + + def importWindowyahia(root): newWindow = Toplevel(root) - newWindow.geometry("1000x1000") def browse(): global count @@ -73,37 +32,99 @@ def browse(): images.append(filename) canvas = Canvas(newWindow) canvas.config(width=1000, height=500) - canvas.grid(row=1 , column=0,columnspan=3) + canvas.pack() img = ImageTk.PhotoImage(Image.open(images[0])) # images[0] = cv2.resize(images[0], (200, 200)) - filtering = tk.Button(newWindow, text="Add Filter", padx=90, pady=10, fg="white", bg="#2596be", - font=('arial', 15), command=lambda: image_filter(filename, canvas, newWindow)) - filtering.grid(row=0, column=1) + filtering = TkinterCustomButton(master=newWindow,text="Add Filter", corner_radius=5,command=lambda: image_filter(filename, canvas, newWindow), + fg_color="#3319CB", hover_color="#005DFE", width=200,cursor="shuttle", text_font=("sans-serif", 20)) + filtering.pack() test=canvas.create_image(0, 0, anchor="nw", image=img) - test.grid(row=1 , column=0,columnspan=3) + test.pack() - # mainloop() root.withdraw() - root.geometry("500x500") newWindow.title("New Window") - newWindow.geometry("500x500") - browse_button = tk.Button(newWindow, text="Browse", padx=90, pady=10, fg="white", bg="#2596be", font=('arial', 15),command=browse) - browse_button.grid(row=0 , column=0) + newWindow.geometry("960x630") + browse_button = TkinterCustomButton(master=newWindow,text="Browse", corner_radius=5, command=browse, + fg_color="#3319CB", hover_color="#005DFE", width=200, cursor="shuttle", + text_font=("sans-serif", 20)) + + + browse_button.pack() ######## Back to previous window ######## def on_closing(): newWindow.destroy() root.deiconify() - backButton = tk.Button(newWindow, text="Previous Page", padx=90, pady=10, fg="white", bg="#2596be", font=('arial', 15), command=on_closing) - backButton.grid(row=0 , column=2) + image= PhotoImage(file ='../assest/back.png') + backButton = TkinterCustomButton(master=newWindow, corner_radius=15, + command=on_closing,fg_color="#f1f1f1",hover_color="#c1c1c1", cursor="shuttle",image=image,width=50) + + backButton.place(x=0,y=3) newWindow.protocol("WM_DELETE_WINDOW", on_closing) + def render(image_withfilter, canvas): + image_withfilter = cv2.cvtColor(image_withfilter, cv2.COLOR_BGR2RGB) + photo = ImageTk.PhotoImage(image=Image.fromarray(image_withfilter)) + canvas.create_image(0, 0, anchor="nw", image=photo).pack() + + def next_fun(path, canvas): + global count + images.append(image_filtering_face( + change_filter[count]['filter'], + path, + change_filter[count]['center'], + change_filter[count]['width'], + change_filter[count]['height'], + change_filter[count]['up'], + change_filter[count]['left'], + change_filter[count]['counte'] + )) + count += 1 + if count == len(change_filter) - 1: + count = -1 + render(images[-1], canvas) + + def submit(content,top): + global entry + entry1 = entry.get() + imgdir = f"../saved/{entry1}.png" + cv2.imwrite(imgdir, content) + entry.delete(0, END) + top.destroy() + def saving(content, newWindow): + pass + def image_filter(path, canvas, newWindow): + images.append( + image_filtering_face(["../assest/tongue.png"], path, [57], [0.6], [1.2], [-25], [0], + [0])) + save = TkinterCustomButton(master=newWindow, text="Save", corner_radius=5, + command=lambda: open_popup(images[-1],newWindow), fg_color="#3319CB", + hover_color="#005DFE", width=200, cursor="shuttle", text_font=("sans-serif", 20)) + save.place(x=50, y=544) + next = TkinterCustomButton(master=newWindow, text="Next", corner_radius=5, + command=lambda: next_fun(path, canvas), fg_color="#3319CB", + hover_color="#005DFE", width=200, cursor="shuttle", text_font=("sans-serif", 20)) + next.place(x=710, y=544) + render(images[-1], canvas) + + def open_popup(content,newWindow): + top = Toplevel(newWindow) + top.geometry("250x150") + top.title("save") + global entry + sub_btn = TkinterCustomButton(master=top, text="Submit", corner_radius=5, command=lambda: submit(content,top), + fg_color="#3319CB", + hover_color="#005DFE", width=100, + cursor="shuttle", text_font=("sans-serif", 20)) + entry = tk.Entry(top, width=20, bg="white") + entry.place(x=75, y=10) + sub_btn.place(x=75, y=50) diff --git a/Tkinter/__pycache__/GUI_Image.cpython-39.pyc b/Tkinter/__pycache__/GUI_Image.cpython-39.pyc new file mode 100644 index 0000000..24b9417 Binary files /dev/null and b/Tkinter/__pycache__/GUI_Image.cpython-39.pyc differ diff --git a/Tkinter/__pycache__/GUI_Live.cpython-39.pyc b/Tkinter/__pycache__/GUI_Live.cpython-39.pyc new file mode 100644 index 0000000..22a86a7 Binary files /dev/null and b/Tkinter/__pycache__/GUI_Live.cpython-39.pyc differ diff --git a/Tkinter/__pycache__/tkinter_custom_button.cpython-39.pyc b/Tkinter/__pycache__/tkinter_custom_button.cpython-39.pyc new file mode 100644 index 0000000..c2b018f Binary files /dev/null and b/Tkinter/__pycache__/tkinter_custom_button.cpython-39.pyc differ diff --git a/Tkinter/tkinter_custom_button.py b/Tkinter/tkinter_custom_button.py new file mode 100644 index 0000000..259bfe8 --- /dev/null +++ b/Tkinter/tkinter_custom_button.py @@ -0,0 +1,276 @@ +import tkinter +import sys + + +class TkinterCustomButton(tkinter.Frame): + """ tkinter custom button with border, rounded corners and hover effect + + Arguments: master= where to place button + bg_color= background color, None is standard, + fg_color= foreground color, blue is standard, + hover_color= foreground color, lightblue is standard, + border_color= foreground color, None is standard, + border_width= border thickness, 0 is standard, + command= callback function, None is standard, + width= width of button, 110 is standard, + height= width of button, 35 is standard, + corner_radius= corner radius, 10 is standard, + text_font= (, ), + text_color= text color, white is standard, + text= text of button, + hover= hover effect, True is standard, + image= PIL.PhotoImage, standard is None""" + + def __init__(self, + bg_color=None, + fg_color="#2874A6", + hover_color="#5499C7", + border_color=None, + border_width=0, + command=None, + width=120, + height=40, + corner_radius=10, + text_font=None, + text_color="white", + text="CustomButton", + hover=True, + image=None, + *args, **kwargs): + super().__init__(*args, **kwargs) + + if bg_color is None: + self.bg_color = self.master.cget("bg") + else: + self.bg_color = bg_color + + self.fg_color = fg_color + self.hover_color = hover_color + self.border_color = border_color + + self.width = width + self.height = height + + if corner_radius*2 > self.height: + self.corner_radius = self.height/2 + elif corner_radius*2 > self.width: + self.corner_radius = self.width/2 + else: + self.corner_radius = corner_radius + + self.border_width = border_width + + if self.corner_radius >= self.border_width: + self.inner_corner_radius = self.corner_radius - self.border_width + else: + self.inner_corner_radius = 0 + + self.text = text + self.text_color = text_color + if text_font is None: + if sys.platform == "darwin": # macOS + self.text_font = ("Avenir", 13) + elif "win" in sys.platform: # Windows + self.text_font = ("Century Gothic", 11) + else: + self.text_font = ("TkDefaultFont") + else: + self.text_font = text_font + + self.image = image + + self.function = command + self.hover = hover + + self.configure(width=self.width, height=self.height) + + if sys.platform == "darwin" and self.function is not None: + self.configure(cursor="pointinghand") + + self.canvas = tkinter.Canvas(master=self, + highlightthicknes=0, + background=self.bg_color, + width=self.width, + height=self.height) + self.canvas.place(x=0, y=0) + + if self.hover is True: + self.canvas.bind("", self.on_enter) + self.canvas.bind("", self.on_leave) + + self.canvas.bind("", self.clicked) + self.canvas.bind("", self.clicked) + + self.canvas_fg_parts = [] + self.canvas_border_parts = [] + self.text_part = None + self.text_label = None + self.image_label = None + + self.draw() + + def draw(self): + self.canvas.delete("all") + self.canvas_fg_parts = [] + self.canvas_border_parts = [] + self.canvas.configure(bg=self.bg_color) + + # border button parts + if self.border_width > 0: + + if self.corner_radius > 0: + self.canvas_border_parts.append(self.canvas.create_oval(0, + 0, + self.corner_radius * 2, + self.corner_radius * 2)) + self.canvas_border_parts.append(self.canvas.create_oval(self.width - self.corner_radius * 2, + 0, + self.width, + self.corner_radius * 2)) + self.canvas_border_parts.append(self.canvas.create_oval(0, + self.height - self.corner_radius * 2, + self.corner_radius * 2, + self.height)) + self.canvas_border_parts.append(self.canvas.create_oval(self.width - self.corner_radius * 2, + self.height - self.corner_radius * 2, + self.width, + self.height)) + + self.canvas_border_parts.append(self.canvas.create_rectangle(0, + self.corner_radius, + self.width, + self.height - self.corner_radius)) + self.canvas_border_parts.append(self.canvas.create_rectangle(self.corner_radius, + 0, + self.width - self.corner_radius, + self.height)) + + # inner button parts + + if self.corner_radius > 0: + self.canvas_fg_parts.append(self.canvas.create_oval(self.border_width, + self.border_width, + self.border_width + self.inner_corner_radius * 2, + self.border_width + self.inner_corner_radius * 2)) + self.canvas_fg_parts.append(self.canvas.create_oval(self.width - self.border_width - self.inner_corner_radius * 2, + self.border_width, + self.width - self.border_width, + self.border_width + self.inner_corner_radius * 2)) + self.canvas_fg_parts.append(self.canvas.create_oval(self.border_width, + self.height - self.border_width - self.inner_corner_radius * 2, + self.border_width + self.inner_corner_radius * 2, + self.height-self.border_width)) + self.canvas_fg_parts.append(self.canvas.create_oval(self.width - self.border_width - self.inner_corner_radius * 2, + self.height - self.border_width - self.inner_corner_radius * 2, + self.width - self.border_width, + self.height - self.border_width)) + + self.canvas_fg_parts.append(self.canvas.create_rectangle(self.border_width + self.inner_corner_radius, + self.border_width, + self.width - self.border_width - self.inner_corner_radius, + self.height - self.border_width)) + self.canvas_fg_parts.append(self.canvas.create_rectangle(self.border_width, + self.border_width + self.inner_corner_radius, + self.width - self.border_width, + self.height - self.inner_corner_radius - self.border_width)) + + for part in self.canvas_fg_parts: + self.canvas.itemconfig(part, fill=self.fg_color, width=0) + + for part in self.canvas_border_parts: + self.canvas.itemconfig(part, fill=self.border_color, width=0) + + # no image given + if self.image is None: + # create tkinter.Label with text + self.text_label = tkinter.Label(master=self, + text=self.text, + font=self.text_font, + bg=self.fg_color, + fg=self.text_color) + self.text_label.place(relx=0.5, rely=0.5, anchor=tkinter.CENTER) + + # bind events the the button click and hover events also to the text_label + if self.hover is True: + self.text_label.bind("", self.on_enter) + self.text_label.bind("", self.on_leave) + + self.text_label.bind("", self.clicked) + self.text_label.bind("", self.clicked) + + self.set_text(self.text) + + # use the given image + else: + # create tkinter.Label with image on it + self.image_label = tkinter.Label(master=self, + image=self.image, + bg=self.fg_color) + + self.image_label.place(relx=0.5, + rely=0.5, + anchor=tkinter.CENTER) + + # bind events the the button click and hover events also to the image_label + if self.hover is True: + self.image_label.bind("", self.on_enter) + self.image_label.bind("", self.on_leave) + + self.image_label.bind("", self.clicked) + self.image_label.bind("", self.clicked) + + def configure_color(self, bg_color=None, fg_color=None, hover_color=None, text_color=None): + if bg_color is not None: + self.bg_color = bg_color + else: + self.bg_color = self.master.cget("bg") + + if fg_color is not None: + self.fg_color = fg_color + + # change background color of image_label + if self.image is not None: + self.image_label.configure(bg=self.fg_color) + + if hover_color is not None: + self.hover_color = hover_color + + if text_color is not None: + self.text_color = text_color + if self.text_part is not None: + self.canvas.itemconfig(self.text_part, fill=self.text_color) + + self.draw() + + def set_text(self, text): + if self.text_label is not None: + self.text_label.configure(text=text) + + def on_enter(self, event=0): + for part in self.canvas_fg_parts: + self.canvas.itemconfig(part, fill=self.hover_color, width=0) + + if self.text_label is not None: + # change background color of image_label + self.text_label.configure(bg=self.hover_color) + + if self.image_label is not None: + # change background color of image_label + self.image_label.configure(bg=self.hover_color) + + def on_leave(self, event=0): + for part in self.canvas_fg_parts: + self.canvas.itemconfig(part, fill=self.fg_color, width=0) + + if self.text_label is not None: + # change background color of image_label + self.text_label.configure(bg=self.fg_color) + + if self.image_label is not None: + # change background color of image_label + self.image_label.configure(bg=self.fg_color) + + def clicked(self, event=0): + if self.function is not None: + self.function() + self.on_leave() \ No newline at end of file diff --git a/assest/2.png b/assest/2.png new file mode 100644 index 0000000..a2b0b1a Binary files /dev/null and b/assest/2.png differ diff --git a/assest/back.png b/assest/back.png new file mode 100644 index 0000000..e2e70b5 Binary files /dev/null and b/assest/back.png differ diff --git a/background_image/__pycache__/backgorund_image.cpython-39.pyc b/background_image/__pycache__/backgorund_image.cpython-39.pyc new file mode 100644 index 0000000..732c6e7 Binary files /dev/null and b/background_image/__pycache__/backgorund_image.cpython-39.pyc differ diff --git a/background_live/__pycache__/request_image.cpython-39.pyc b/background_live/__pycache__/request_image.cpython-39.pyc new file mode 100644 index 0000000..b64dcab Binary files /dev/null and b/background_live/__pycache__/request_image.cpython-39.pyc differ diff --git a/filters_image/__pycache__/change_filter.cpython-39.pyc b/filters_image/__pycache__/change_filter.cpython-39.pyc new file mode 100644 index 0000000..0b9083f Binary files /dev/null and b/filters_image/__pycache__/change_filter.cpython-39.pyc differ diff --git a/filters_image/__pycache__/image_filtering_face.cpython-39.pyc b/filters_image/__pycache__/image_filtering_face.cpython-39.pyc new file mode 100644 index 0000000..1fd39d5 Binary files /dev/null and b/filters_image/__pycache__/image_filtering_face.cpython-39.pyc differ diff --git a/filters_live/__pycache__/change_filter.cpython-39.pyc b/filters_live/__pycache__/change_filter.cpython-39.pyc new file mode 100644 index 0000000..9000416 Binary files /dev/null and b/filters_live/__pycache__/change_filter.cpython-39.pyc differ diff --git a/filters_live/__pycache__/video_filtering_face.cpython-39.pyc b/filters_live/__pycache__/video_filtering_face.cpython-39.pyc new file mode 100644 index 0000000..c0db7a8 Binary files /dev/null and b/filters_live/__pycache__/video_filtering_face.cpython-39.pyc differ