Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 12 additions & 68 deletions Tkinter/GUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,90 +7,39 @@
from PIL import Image, ImageTk
import time
import cv2
from Tkinter.GUI_Live import camera
# from snapshot import App, videoCapture
root = tk.Tk()
images = []
from Tkinter.GUI_Image import importWindowyahia


######### import Window ##########

def importWindow():
newWindow = Toplevel(root)
newWindow.geometry("1000x1000")
def browse():

filename = filedialog.askopenfilename(initialdir="/home/yousef/Pictures", title="select File",
filetypes = (("jpeg files","*.jpg"),("all files","*.*"),('png files', '*.png')))

images.append(filename)
canvas = Canvas(newWindow)
canvas.config(width=1000, height=500)
canvas.grid(row=1 , column=0,columnspan=3)
print(filename)
img = ImageTk.PhotoImage(Image.open(images[0]))
canvas.create_image(0, 0, anchor="nw", image=img)
mainloop()

root.withdraw()
newWindow.title("New Window")
newWindow.geometry("700x700")
backButton = tk.Button(newWindow, text="Browse", padx=90, pady=10, fg="white", bg="#2596be", font=('arial', 15),command=browse)
backButton.grid(row=0 , column=0)

######## 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)

newWindow.protocol("WM_DELETE_WINDOW", on_closing)


importWindowyahia(root)

########### second-window #############

def videoWindow():
def openCamera():
# cap=cv2.VideoCapture(0)
# frame=cap.read()
# cv2.imshow('frame', frame)
# cv2.waitKey(0)
cap = cv2.VideoCapture(0)
while True:
_, frame = cap.read()
cv2.imshow('frame', frame)
cv2.waitKey(1)


canv = Canvas(newWindow, width=150, height=150, bg='white')
canv.grid(row=2, column=3)


img = ImageTk.PhotoImage(Image.open('123.png'))
canv.create_image(20, 20, anchor=NW, image=img)


newWindow = Toplevel(root)
cameraWindow = Toplevel(root)
root.withdraw()
newWindow.title("New Window")
newWindow.geometry("700x700")
Label(newWindow,
cameraWindow.title("New Window")
cameraWindow.geometry("700x700")
Label(cameraWindow,
text="This is a new window").grid()
backButton = tk.Button(newWindow, text="Browse", padx=90, pady=10, fg="white", bg="#2596be", font=('arial', 15), command=openCamera)
backButton.grid()


camera(cameraWindow)


######## Back to previous window ########
def on_closing():
newWindow.destroy()
cameraWindow.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 = tk.Button(cameraWindow, text="Previous Page", padx=90, pady=10, fg="white", bg="#2596be", font=('arial', 15), command=on_closing)
backButton.grid()

newWindow.protocol("WM_DELETE_WINDOW", on_closing)
cameraWindow.protocol("WM_DELETE_WINDOW", on_closing)



Expand All @@ -107,9 +56,4 @@ def on_closing():


###########################################
root.mainloop()





root.mainloop()
109 changes: 109 additions & 0 deletions Tkinter/GUI_Image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import tkinter as tk
from tkinter import filedialog, Text
import os, sys, subprocess
from filters_image.change_filter import change_filter
from tkinter.ttk import *
from tkinter import *
from PIL import Image, ImageTk
from filters_image.image_filtering_face import image_filtering_face
import cv2
# 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)
def importWindowyahia(root):
newWindow = Toplevel(root)
newWindow.geometry("1000x1000")
def browse():
global count


filename = filedialog.askopenfilename(title="select File",
filetypes = (("jpeg files","*.jpg"),("all files","*.*"),('png files', '*.png')))
images.append(filename)
canvas = Canvas(newWindow)
canvas.config(width=1000, height=500)
canvas.grid(row=1 , column=0,columnspan=3)
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)

test=canvas.create_image(0, 0, anchor="nw", image=img)
test.grid(row=1 , column=0,columnspan=3)


# 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)


######## 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)

newWindow.protocol("WM_DELETE_WINDOW", on_closing)



125 changes: 125 additions & 0 deletions Tkinter/GUI_Live.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import tkinter as tk
from PIL import ImageTk, Image
import cv2
from filters_live.video_filtering_face import video_filtering_face,change_filter
from tkinter import Tk
from tkinter.ttk import Frame, Label
from background_live.request_image import add_path,check_image

save = False
count_filter = 0
count_back = 1
show_filter_live = False
show_background_live = False

def camera(newWindow):
app = Frame(newWindow)
app.grid()
lmain = Label(app)
lmain.grid()



def printInput():
add_path(inputtxt2.get(1.0, "end-1c"))

inputtxt2 = tk.Text(newWindow,
height=5,
width=20)
inputtxt2.grid(row=0, column=1)
printButton = tk.Button(newWindow,
text = "Print",
command = printInput)
printButton.grid(row=0, column=1)

def nextback():
global count_back,show_background_live
len_image = check_image()
if count_back == len_image:
show_background_live = False
count_back=1
else:
show_background_live = True
count_back+=1
def nextWindow():
global count_filter,show_filter_live
if count_filter == len(change_filter)-1:
show_filter_live = False
count_filter= -1
else:
show_filter_live = True
count_filter+=1

def saveWindow():
global save
save =True


importButton = tk.Button(newWindow,text="Next background", padx=90, pady=10, fg="white", bg="#2596be", font=('arial', 15),
command=nextback)
importButton.grid(row=1, column=0)
importButton = tk.Button(newWindow,text="Next filter", padx=90, pady=10, fg="white", bg="#2596be", font=('arial', 15),
command=nextWindow)
importButton.grid(row=1, column=1)
importButton = tk.Button(newWindow,text='capture and save', padx=90, pady=10, fg="white", bg="#2596be", font=('arial', 15),
command=saveWindow)
importButton.grid(row=2, column=0)

def video_stream3():

frame = video_filtering_face(
change_filter[count_filter]['filter'],
change_filter[count_filter]['center'],
change_filter[count_filter]['width'],
change_filter[count_filter]['height'],
change_filter[count_filter]['up'],
change_filter[count_filter]['left'],
f'../assest/background/back{count_back}.png',
1,show_filter_live,show_background_live

)

cv2image2 = cv2.cvtColor(frame, cv2.COLOR_BGR2RGBA)
img2 = Image.fromarray(cv2image2)
imgtk2 = ImageTk.PhotoImage(image=img2)
lmain.imgtk = imgtk2
lmain.configure(image=imgtk2)
if save:
save_image(frame)
lmain.after(1, video_stream3)
def save_image(frame):
global save
save = False
cv2image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGBA)
img = Image.fromarray(cv2image)
imgtk = ImageTk.PhotoImage(image=img)
lmain.imgtk = imgtk
lmain.configure(image=imgtk)
path_name(frame)

def print_path2(inputtxt, frame):
name = inputtxt.get(1.0, "end-1c")
print(name)
img_name = f"../saved/{name}.png"
cv2.imwrite(img_name, frame)
def path_name(frame):

inputtxt = tk.Text(newWindow,
height=5,
width=20)

inputtxt.grid(row=1, column=2)

printButton = tk.Button(newWindow,
text="save image",
command=lambda: print_path2(inputtxt, frame))
printButton.grid(row=1, column=2)




video_stream3()

# newWindow.mainloop()


Binary file removed Tkinter/__pycache__/GUI.cpython-38.pyc
Binary file not shown.
Binary file removed Tkinter/__pycache__/snapshot.cpython-38.pyc
Binary file not shown.
Binary file removed Tkinter/__pycache__/snapshot.cpython-39.pyc
Binary file not shown.
Loading