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
5 changes: 1 addition & 4 deletions .idea/Filteristic.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Tkinter/GUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def videoWindow():
def on_closing():
cameraWindow.destroy()
root.deiconify()

backButton = tk.Button(cameraWindow, text="Previous Page", padx=90, pady=10, fg="white", bg="#2596be", font=('arial', 15), command=on_closing)
backButton.grid()

Expand Down
52 changes: 28 additions & 24 deletions Tkinter/GUI_Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,17 @@ def browse():
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.pack()
img = ImageTk.PhotoImage(Image.open(images[0]))

# images[0] = cv2.resize(images[0], (200, 200))

filtering = TkinterCustomButton(master=newWindow,text="Add Filter", corner_radius=5,command=lambda: image_filter(filename, canvas, newWindow),
img = Image.open(images[-1])
img = img.resize((500, 500))
img = ImageTk.PhotoImage(img)
img_label = Label(newWindow, image=img)
img_label.photo = img
img_label.place(x=228, y=40)

filtering = TkinterCustomButton(master=newWindow,text="Add Filter", corner_radius=5,command=lambda: image_filter(filename, newWindow),
fg_color="#3319CB", hover_color="#005DFE", width=200,cursor="shuttle", text_font=("sans-serif", 20))
filtering.pack()
filtering.place(x=380, y=550)

test=canvas.create_image(0, 0, anchor="nw", image=img)
test.pack()



Expand All @@ -69,12 +67,18 @@ def on_closing():

newWindow.protocol("WM_DELETE_WINDOW", on_closing)

def render(image_withfilter, canvas):
def render(image_withfilter):
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):
img = Image.fromarray(image_withfilter)
img = img.resize((500, 500))
img = ImageTk.PhotoImage(img)
img_label = Label(newWindow, image=img)
img_label.photo = img
img_label.place(x=228, y=40)
# photo = ImageTk.PhotoImage(image=Image.fromarray(image_withfilter))
# canvas.create_image(0, 0, anchor="nw", image=photo)

def next_fun(path):
global count

images.append(image_filtering_face(
Expand All @@ -89,8 +93,8 @@ def next_fun(path, canvas):
))
count += 1
if count == len(change_filter) - 1:
count = -1
render(images[-1], canvas)
count = 0
render(images[-1])

def submit(content,top):
global entry
Expand All @@ -101,19 +105,20 @@ def submit(content,top):
top.destroy()
def saving(content, newWindow):
pass
def image_filter(path, canvas, newWindow):
def image_filter(path, 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)
save.place(x=50, y=550)
next = TkinterCustomButton(master=newWindow, text="Next", corner_radius=5,
command=lambda: next_fun(path, canvas), fg_color="#3319CB",
command=lambda: next_fun(path), 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)
newWindow.bind("<Right>", lambda x: next_fun(path))
next.place(x=710, y=550)
render(images[-1])

def open_popup(content,newWindow):
top = Toplevel(newWindow)
Expand All @@ -127,4 +132,3 @@ def open_popup(content,newWindow):
entry = tk.Entry(top, width=20, bg="white")
entry.place(x=75, y=10)
sub_btn.place(x=75, y=50)

7 changes: 2 additions & 5 deletions Tkinter/GUI_Live.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ def camera(newWindow):
lmain = Label(app)
lmain.grid()



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

Expand Down Expand Up @@ -115,9 +113,8 @@ def path_name(frame):
command=lambda: print_path2(inputtxt, frame))
printButton.grid(row=1, column=2)




newWindow.bind("<Right>", lambda x: nextWindow())
newWindow.bind("<Left>", lambda x: nextback())
video_stream3()

# newWindow.mainloop()
Expand Down
100 changes: 39 additions & 61 deletions filters_image/image_filtering_face.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,74 +20,52 @@ def image_filtering_face(path_filter,path_img,center,width,height,up,left,counte
detector = dlib.get_frontal_face_detector()
faces = detector(image)
if faces:
try:
for i in range(len(path_filter)):
return filter(image,gray_image,faces,filter_image[i],center[i],width[i],height[i],up[i],left[i])
except:
image = cv2.imread(path_img)
print("except")
return image

# key = cv2.waitKey(0)
# if key == ord('n'):
# change_image(counte)
# elif key == ord('q'):
# cv2.destroyAllWindows()
#
# elif key == ord("c"):
# img_name = "../saved/opencv_frame.png"
# cv2.imwrite(img_name, image)
# print("{} written!".format(img_name))

# image = cv2.imread(img_name)
# cv2.imshow("Frame", image)
# key = cv2.waitKey(0)
# os.remove("../saved/opencv_frame.png")
# if key == ord("s"):
# user_name = input("enter name")
# imgdir = f"../saved/{user_name}.png"
# cv2.imwrite(imgdir, image)
# image_filtering_face(["../assest/tongue.png"],"../assest/face.jpg",[57],[0.6],[1.2],[-25],[0])
# if key == ord("e"):
# image_filtering_face(["../assest/tongue.png"],"../assest/face.jpg",[57],[0.6],[1.2],[-25],[0])

# try:
for i in range(len(path_filter)):
return filter(image,gray_image,faces,filter_image[i],center[i],width[i],height[i],up[i],left[i])
# except:
# image = cv2.imread(path_img)

# return image


def filter(image,gray_frame,faces,filter_image1,center,width,height,up=0,left=0):
predictor_path = "../assest/shape_predictor_68_face_landmarks.dat"
predictor = dlib.shape_predictor(predictor_path)
for face in faces:
landmarks = predictor(gray_frame, face)

center_filter = (landmarks.part(center).x-left, landmarks.part(center).y-up)
left_filter = (landmarks.part(4).x, landmarks.part(4).y)
right_filter = (landmarks.part(14).x, landmarks.part(14).y)

filter_width = int(hypot(left_filter[0] - right_filter[0],
left_filter[1] - right_filter[1]) * width)
filter_height = int(filter_width * height)

# New filter position
top_left = (int(center_filter[0] - filter_width / 2),
int(center_filter[1] - filter_height / 2))
bottom_right = (int(center_filter[0] + filter_width / 2),
int(center_filter[1] + filter_height / 2))

# Adding the new filter
filtery = cv2.resize(filter_image1, (filter_width, filter_height))
filtery_gray = cv2.cvtColor(filtery, cv2.COLOR_BGR2GRAY)
_, filter1 = cv2.threshold(filtery_gray, 25, 255, cv2.THRESH_BINARY_INV)

filter_area = image[top_left[1]: top_left[1] + filter_height,
top_left[0]: top_left[0] + filter_width]
filter_area_no_filter = cv2.bitwise_and(filter_area, filter_area, mask=filter1)
final_filter = cv2.add(filter_area_no_filter, filtery)

image[top_left[1]: top_left[1] + filter_height,
top_left[0]: top_left[0] + filter_width,:] = final_filter
print("filter1")
return image
try:
landmarks = predictor(gray_frame, face)

center_filter = (landmarks.part(center).x-left, landmarks.part(center).y-up)
left_filter = (landmarks.part(4).x, landmarks.part(4).y)
right_filter = (landmarks.part(14).x, landmarks.part(14).y)

filter_width = int(hypot(left_filter[0] - right_filter[0],
left_filter[1] - right_filter[1]) * width)
filter_height = int(filter_width * height)

# New filter position
top_left = (int(center_filter[0] - filter_width / 2),
int(center_filter[1] - filter_height / 2))
bottom_right = (int(center_filter[0] + filter_width / 2),
int(center_filter[1] + filter_height / 2))

# Adding the new filter
filtery = cv2.resize(filter_image1, (filter_width, filter_height))
filtery_gray = cv2.cvtColor(filtery, cv2.COLOR_BGR2GRAY)
_, filter1 = cv2.threshold(filtery_gray, 25, 255, cv2.THRESH_BINARY_INV)

filter_area = image[top_left[1]: top_left[1] + filter_height,
top_left[0]: top_left[0] + filter_width]
filter_area_no_filter = cv2.bitwise_and(filter_area, filter_area, mask=filter1)
final_filter = cv2.add(filter_area_no_filter, filtery)

image[top_left[1]: top_left[1] + filter_height,
top_left[0]: top_left[0] + filter_width,:] = final_filter
print("filter1")
except:
print("except")
return image
# cv2.imshow("Frame", image)
# key = cv2.waitKey(0)

Expand Down
9 changes: 4 additions & 5 deletions filters_live/video_filtering_face.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@

import os
cap = cv2.VideoCapture(0)
_, frame = cap.read()
rows, cols, _ = frame.shape
filter1 = np.zeros((rows, cols), np.uint8)
detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor("../filters_live/shape_predictor_68_face_landmarks.dat")
counte=0
Expand All @@ -19,8 +16,10 @@ def video_filtering_face(path,center,width,height,up,left,path_back,blur,filter_
for i in path:
filter_image.append(cv2.imread(i))
#
filter1 = np.zeros((rows, cols), np.uint8)
_, frame = cap.read()
rows, cols, _ = frame.shape
filter1 = np.zeros((rows, cols), np.uint8)

filter1.fill(0)
gray_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = detector(frame)
Expand Down Expand Up @@ -86,7 +85,7 @@ def change_image(i):
)

mp_selfie_segmentation = mp.solutions.selfie_segmentation
fsize = (520, 720)
fsize = (480, 640)
def background(frame,path,blur =1):


Expand Down
Binary file added saved/yahiasolved.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.