Skip to content

Commit 8045b17

Browse files
Merge pull request #18 from Python-Hiss/khatib
finally I made a push
2 parents 59a9343 + 88b57f3 commit 8045b17

File tree

8 files changed

+76
-100
lines changed

8 files changed

+76
-100
lines changed

.idea/Filteristic.iml

Lines changed: 1 addition & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Tkinter/GUI.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def videoWindow():
3838
def on_closing():
3939
cameraWindow.destroy()
4040
root.deiconify()
41+
4142
backButton = tk.Button(cameraWindow, text="Previous Page", padx=90, pady=10, fg="white", bg="#2596be", font=('arial', 15), command=on_closing)
4243
backButton.grid()
4344

Tkinter/GUI_Image.py

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,17 @@ def browse():
3030
filename = filedialog.askopenfilename(title="select File",
3131
filetypes = (("jpeg files","*.jpg"),("all files","*.*"),('png files', '*.png')))
3232
images.append(filename)
33-
canvas = Canvas(newWindow)
34-
canvas.config(width=1000, height=500)
35-
canvas.pack()
36-
img = ImageTk.PhotoImage(Image.open(images[0]))
37-
38-
# images[0] = cv2.resize(images[0], (200, 200))
39-
40-
filtering = TkinterCustomButton(master=newWindow,text="Add Filter", corner_radius=5,command=lambda: image_filter(filename, canvas, newWindow),
33+
img = Image.open(images[-1])
34+
img = img.resize((500, 500))
35+
img = ImageTk.PhotoImage(img)
36+
img_label = Label(newWindow, image=img)
37+
img_label.photo = img
38+
img_label.place(x=228, y=40)
39+
40+
filtering = TkinterCustomButton(master=newWindow,text="Add Filter", corner_radius=5,command=lambda: image_filter(filename, newWindow),
4141
fg_color="#3319CB", hover_color="#005DFE", width=200,cursor="shuttle", text_font=("sans-serif", 20))
42-
filtering.pack()
42+
filtering.place(x=380, y=550)
4343

44-
test=canvas.create_image(0, 0, anchor="nw", image=img)
45-
test.pack()
4644

4745

4846

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

7068
newWindow.protocol("WM_DELETE_WINDOW", on_closing)
7169

72-
def render(image_withfilter, canvas):
70+
def render(image_withfilter):
7371
image_withfilter = cv2.cvtColor(image_withfilter, cv2.COLOR_BGR2RGB)
74-
photo = ImageTk.PhotoImage(image=Image.fromarray(image_withfilter))
75-
canvas.create_image(0, 0, anchor="nw", image=photo).pack()
76-
77-
def next_fun(path, canvas):
72+
img = Image.fromarray(image_withfilter)
73+
img = img.resize((500, 500))
74+
img = ImageTk.PhotoImage(img)
75+
img_label = Label(newWindow, image=img)
76+
img_label.photo = img
77+
img_label.place(x=228, y=40)
78+
# photo = ImageTk.PhotoImage(image=Image.fromarray(image_withfilter))
79+
# canvas.create_image(0, 0, anchor="nw", image=photo)
80+
81+
def next_fun(path):
7882
global count
7983

8084
images.append(image_filtering_face(
@@ -89,8 +93,8 @@ def next_fun(path, canvas):
8993
))
9094
count += 1
9195
if count == len(change_filter) - 1:
92-
count = -1
93-
render(images[-1], canvas)
96+
count = 0
97+
render(images[-1])
9498

9599
def submit(content,top):
96100
global entry
@@ -101,19 +105,20 @@ def submit(content,top):
101105
top.destroy()
102106
def saving(content, newWindow):
103107
pass
104-
def image_filter(path, canvas, newWindow):
108+
def image_filter(path, newWindow):
105109
images.append(
106110
image_filtering_face(["../assest/tongue.png"], path, [57], [0.6], [1.2], [-25], [0],
107111
[0]))
108112
save = TkinterCustomButton(master=newWindow, text="Save", corner_radius=5,
109113
command=lambda: open_popup(images[-1],newWindow), fg_color="#3319CB",
110114
hover_color="#005DFE", width=200, cursor="shuttle", text_font=("sans-serif", 20))
111-
save.place(x=50, y=544)
115+
save.place(x=50, y=550)
112116
next = TkinterCustomButton(master=newWindow, text="Next", corner_radius=5,
113-
command=lambda: next_fun(path, canvas), fg_color="#3319CB",
117+
command=lambda: next_fun(path), fg_color="#3319CB",
114118
hover_color="#005DFE", width=200, cursor="shuttle", text_font=("sans-serif", 20))
115-
next.place(x=710, y=544)
116-
render(images[-1], canvas)
119+
newWindow.bind("<Right>", lambda x: next_fun(path))
120+
next.place(x=710, y=550)
121+
render(images[-1])
117122

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

Tkinter/GUI_Live.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ def camera(newWindow):
1818
lmain = Label(app)
1919
lmain.grid()
2020

21-
22-
2321
def printInput():
2422
add_path(inputtxt2.get(1.0, "end-1c"))
2523

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

118-
119-
120-
116+
newWindow.bind("<Right>", lambda x: nextWindow())
117+
newWindow.bind("<Left>", lambda x: nextback())
121118
video_stream3()
122119

123120
# newWindow.mainloop()

filters_image/image_filtering_face.py

Lines changed: 39 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -20,74 +20,52 @@ def image_filtering_face(path_filter,path_img,center,width,height,up,left,counte
2020
detector = dlib.get_frontal_face_detector()
2121
faces = detector(image)
2222
if faces:
23-
try:
24-
for i in range(len(path_filter)):
25-
return filter(image,gray_image,faces,filter_image[i],center[i],width[i],height[i],up[i],left[i])
26-
except:
27-
image = cv2.imread(path_img)
28-
print("except")
29-
return image
30-
31-
# key = cv2.waitKey(0)
32-
# if key == ord('n'):
33-
# change_image(counte)
34-
# elif key == ord('q'):
35-
# cv2.destroyAllWindows()
36-
#
37-
# elif key == ord("c"):
38-
# img_name = "../saved/opencv_frame.png"
39-
# cv2.imwrite(img_name, image)
40-
# print("{} written!".format(img_name))
41-
42-
# image = cv2.imread(img_name)
43-
# cv2.imshow("Frame", image)
44-
# key = cv2.waitKey(0)
45-
# os.remove("../saved/opencv_frame.png")
46-
# if key == ord("s"):
47-
# user_name = input("enter name")
48-
# imgdir = f"../saved/{user_name}.png"
49-
# cv2.imwrite(imgdir, image)
50-
# image_filtering_face(["../assest/tongue.png"],"../assest/face.jpg",[57],[0.6],[1.2],[-25],[0])
51-
# if key == ord("e"):
52-
# image_filtering_face(["../assest/tongue.png"],"../assest/face.jpg",[57],[0.6],[1.2],[-25],[0])
53-
23+
# try:
24+
for i in range(len(path_filter)):
25+
return filter(image,gray_image,faces,filter_image[i],center[i],width[i],height[i],up[i],left[i])
26+
# except:
27+
# image = cv2.imread(path_img)
5428

29+
# return image
5530

5631

5732
def filter(image,gray_frame,faces,filter_image1,center,width,height,up=0,left=0):
5833
predictor_path = "../assest/shape_predictor_68_face_landmarks.dat"
5934
predictor = dlib.shape_predictor(predictor_path)
6035
for face in faces:
61-
landmarks = predictor(gray_frame, face)
62-
63-
center_filter = (landmarks.part(center).x-left, landmarks.part(center).y-up)
64-
left_filter = (landmarks.part(4).x, landmarks.part(4).y)
65-
right_filter = (landmarks.part(14).x, landmarks.part(14).y)
66-
67-
filter_width = int(hypot(left_filter[0] - right_filter[0],
68-
left_filter[1] - right_filter[1]) * width)
69-
filter_height = int(filter_width * height)
70-
71-
# New filter position
72-
top_left = (int(center_filter[0] - filter_width / 2),
73-
int(center_filter[1] - filter_height / 2))
74-
bottom_right = (int(center_filter[0] + filter_width / 2),
75-
int(center_filter[1] + filter_height / 2))
76-
77-
# Adding the new filter
78-
filtery = cv2.resize(filter_image1, (filter_width, filter_height))
79-
filtery_gray = cv2.cvtColor(filtery, cv2.COLOR_BGR2GRAY)
80-
_, filter1 = cv2.threshold(filtery_gray, 25, 255, cv2.THRESH_BINARY_INV)
81-
82-
filter_area = image[top_left[1]: top_left[1] + filter_height,
83-
top_left[0]: top_left[0] + filter_width]
84-
filter_area_no_filter = cv2.bitwise_and(filter_area, filter_area, mask=filter1)
85-
final_filter = cv2.add(filter_area_no_filter, filtery)
86-
87-
image[top_left[1]: top_left[1] + filter_height,
88-
top_left[0]: top_left[0] + filter_width,:] = final_filter
89-
print("filter1")
90-
return image
36+
try:
37+
landmarks = predictor(gray_frame, face)
38+
39+
center_filter = (landmarks.part(center).x-left, landmarks.part(center).y-up)
40+
left_filter = (landmarks.part(4).x, landmarks.part(4).y)
41+
right_filter = (landmarks.part(14).x, landmarks.part(14).y)
42+
43+
filter_width = int(hypot(left_filter[0] - right_filter[0],
44+
left_filter[1] - right_filter[1]) * width)
45+
filter_height = int(filter_width * height)
46+
47+
# New filter position
48+
top_left = (int(center_filter[0] - filter_width / 2),
49+
int(center_filter[1] - filter_height / 2))
50+
bottom_right = (int(center_filter[0] + filter_width / 2),
51+
int(center_filter[1] + filter_height / 2))
52+
53+
# Adding the new filter
54+
filtery = cv2.resize(filter_image1, (filter_width, filter_height))
55+
filtery_gray = cv2.cvtColor(filtery, cv2.COLOR_BGR2GRAY)
56+
_, filter1 = cv2.threshold(filtery_gray, 25, 255, cv2.THRESH_BINARY_INV)
57+
58+
filter_area = image[top_left[1]: top_left[1] + filter_height,
59+
top_left[0]: top_left[0] + filter_width]
60+
filter_area_no_filter = cv2.bitwise_and(filter_area, filter_area, mask=filter1)
61+
final_filter = cv2.add(filter_area_no_filter, filtery)
62+
63+
image[top_left[1]: top_left[1] + filter_height,
64+
top_left[0]: top_left[0] + filter_width,:] = final_filter
65+
print("filter1")
66+
except:
67+
print("except")
68+
return image
9169
# cv2.imshow("Frame", image)
9270
# key = cv2.waitKey(0)
9371

filters_live/video_filtering_face.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77

88
import os
99
cap = cv2.VideoCapture(0)
10-
_, frame = cap.read()
11-
rows, cols, _ = frame.shape
12-
filter1 = np.zeros((rows, cols), np.uint8)
1310
detector = dlib.get_frontal_face_detector()
1411
predictor = dlib.shape_predictor("../filters_live/shape_predictor_68_face_landmarks.dat")
1512
counte=0
@@ -19,8 +16,10 @@ def video_filtering_face(path,center,width,height,up,left,path_back,blur,filter_
1916
for i in path:
2017
filter_image.append(cv2.imread(i))
2118
#
22-
filter1 = np.zeros((rows, cols), np.uint8)
2319
_, frame = cap.read()
20+
rows, cols, _ = frame.shape
21+
filter1 = np.zeros((rows, cols), np.uint8)
22+
2423
filter1.fill(0)
2524
gray_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
2625
faces = detector(frame)
@@ -86,7 +85,7 @@ def change_image(i):
8685
)
8786

8887
mp_selfie_segmentation = mp.solutions.selfie_segmentation
89-
fsize = (520, 720)
88+
fsize = (480, 640)
9089
def background(frame,path,blur =1):
9190

9291

saved/yahiasolved.png

1.87 MB
Loading

0 commit comments

Comments
 (0)