diff --git a/.idea/Filteristic.iml b/.idea/Filteristic.iml
index d28d420..8aeb520 100644
--- a/.idea/Filteristic.iml
+++ b/.idea/Filteristic.iml
@@ -2,11 +2,10 @@
-
-
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index b534b89..8d93904 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,4 +1,4 @@
-
+
\ No newline at end of file
diff --git a/__pycache__/main.cpython-38.pyc b/__pycache__/main.cpython-38.pyc
deleted file mode 100644
index cae4fd6..0000000
Binary files a/__pycache__/main.cpython-38.pyc and /dev/null differ
diff --git a/assest/background/back1.png b/assest/background/back1.png
new file mode 100644
index 0000000..d9f9437
Binary files /dev/null and b/assest/background/back1.png differ
diff --git a/assest/background/back2.png b/assest/background/back2.png
new file mode 100644
index 0000000..5c05343
Binary files /dev/null and b/assest/background/back2.png differ
diff --git a/assest/background/back3.png b/assest/background/back3.png
new file mode 100644
index 0000000..bc5b5f2
Binary files /dev/null and b/assest/background/back3.png differ
diff --git a/assest/background/back4.png b/assest/background/back4.png
new file mode 100644
index 0000000..9454d5e
Binary files /dev/null and b/assest/background/back4.png differ
diff --git a/assest/background/back5.png b/assest/background/back5.png
new file mode 100644
index 0000000..ee5614d
Binary files /dev/null and b/assest/background/back5.png differ
diff --git a/assest/eye1.png b/assest/eye1.png
new file mode 100644
index 0000000..c6fb1a0
Binary files /dev/null and b/assest/eye1.png differ
diff --git a/assest/eye2.png b/assest/eye2.png
new file mode 100644
index 0000000..e53e72f
Binary files /dev/null and b/assest/eye2.png differ
diff --git a/assest/ghoul2.png b/assest/ghoul2.png
new file mode 100644
index 0000000..8b4ca39
Binary files /dev/null and b/assest/ghoul2.png differ
diff --git a/assest/hair9.png b/assest/hair9.png
new file mode 100644
index 0000000..b835895
Binary files /dev/null and b/assest/hair9.png differ
diff --git a/background_image/backgorund_image.py b/background_image/backgorund_image.py
new file mode 100644
index 0000000..b6b2705
--- /dev/null
+++ b/background_image/backgorund_image.py
@@ -0,0 +1,23 @@
+import pixellib
+from check_directory import saveimage,check_image
+from pixellib.tune_bg import alter_bg
+def backgroundImage(type,input_image,color,back_ground=''):
+ path_name =check_image()
+ if path_name:
+ change_bg = alter_bg(model_type = "pb")
+ change_bg.load_pascalvoc_model("xception_pascalvoc.pb")
+
+ if type == 'image':
+ change_bg.change_bg_img(f_image_path = input_image,b_image_path = back_ground, output_image_name=path_name)
+ if type == 'gray':
+ change_bg.gray_bg(input_image, output_image_name=path_name)
+ if type =='color':
+ change_bg.color_bg(input_image, colors=color, output_image_name=path_name)
+ if type == 'blur':
+ change_bg.blur_bg(input_image, low=True, output_image_name=path_name)
+ saveimage(path_name)
+
+
+
+
+# backgroundImage('gray','Output_image/test2.png','Input_image/lena.jpg')
diff --git a/background_image/check_directory.py b/background_image/check_directory.py
new file mode 100644
index 0000000..3691be4
--- /dev/null
+++ b/background_image/check_directory.py
@@ -0,0 +1,46 @@
+from os.path import exists
+import os
+import cv2
+import requests
+def check_image():
+ path = input('enter the name of path output : ')
+ path_image = f'Output_image/{path}.png'
+ file_exists = exists(path_image)
+ while file_exists:
+ path_name2 = input('this name is exist try another one or enter q : ')
+ if path_name2 == 'q':
+ path_image = False
+ break
+
+ path_image = f'Output_image/{path_name2}.png'
+ file_exists = exists(path_image)
+ return path_image
+
+def saveimage(path):
+ print("close the window for image")
+ image = cv2.imread(path)
+ cv2.imshow('image window', image)
+ cv2.waitKey(0)
+ cv2.destroyAllWindows()
+ save = input('do you want to save image ?')
+ if not save == 'yes':
+ os.remove(path)
+ return
+def add_path(image_path,origin):
+ path_name = input('add path name : ')
+ r= requests.get(image_path)
+ path_image = f'{origin}{path_name}.png'
+ file_exists = exists(path_image)
+ while file_exists :
+ path_name2 = input('this name is exist try another one or enter q : ')
+ if path_name2 =='q':
+ path_image=''
+ break
+
+ path_image = f'{origin}{path_name2}.png'
+ file_exists = exists(path_image)
+
+ with open(path_image,'wb') as f :
+ f.write(r.content)
+
+ return path_image
\ No newline at end of file
diff --git a/background_image/filter_background_image.py b/background_image/filter_background_image.py
new file mode 100644
index 0000000..71c5b57
--- /dev/null
+++ b/background_image/filter_background_image.py
@@ -0,0 +1,20 @@
+from backgorund_image import backgroundImage
+from check_directory import add_path
+def filter_background_image():
+ type_filter = int(input('type_filter : '))
+ background_filter =''
+ color = ''
+ type_of_background = input('enter type of background : [gray,image,blur,color] : ')
+ path_input_image = add_path(input('path image : '),'Input_image/')
+ if type_filter ==0 and type_of_background == 'image' :
+ background_filter = add_path(input('path image : '), 'input_background/')
+ backgroundImage(type_of_background, path_input_image,color, background_filter)
+ if type_of_background=='color':
+ add_color = input('input color rgb : 0,0,255 : ')
+ color = tuple(map(int, add_color.split(',')))
+
+ if type_filter == 1 :
+ backgroundImage(type_of_background,path_input_image,color,'../assest/background/back1.jpg')
+ if type_filter == 2 :
+ backgroundImage(type_of_background,path_input_image,background_filter,color,'../assest/background/back2.jpg')
+filter_background_image()
\ No newline at end of file
diff --git a/background_live/background_live.py b/background_live/background_live.py
new file mode 100644
index 0000000..8e3c224
--- /dev/null
+++ b/background_live/background_live.py
@@ -0,0 +1,65 @@
+import cv2
+import mediapipe as mp
+import numpy as np
+from request_image import add_path
+def background(path,blur =1,img=2):
+ mp_selfie_segmentation = mp.solutions.selfie_segmentation
+ back1=1
+ cam = cv2.VideoCapture(0)
+ cam.set(3, 1280)
+ cam.set(4, 720)
+ fsize = (520, 720)
+
+
+
+ # begin with selfie segmentation model
+
+
+ while cam.isOpened():
+ scene = cv2.imread(path) # read the scene image
+ scene = cv2.blur(scene, (blur, blur))
+ scene = cv2.resize(scene, (fsize[1], fsize[0])) # resize scene to the size of frame
+ with mp_selfie_segmentation.SelfieSegmentation(model_selection=1) as selfie_seg:
+ bg_image = scene
+ ret, frame = cam.read()
+ if not ret:
+ print("Error reading frame...")
+ continue
+ frame = cv2.resize(frame, (fsize[1], fsize[0]))
+
+ # flip it to look like selfie camera
+ frame = cv2.flip(frame, 1)
+
+ # get rgb image to pass that on selfie segmentation
+ rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
+
+ # process it!
+ results = selfie_seg.process(rgb)
+
+ # get the condition from result's segmentation mask
+ condition = np.stack((results.segmentation_mask,) * 3, axis=-1) > 0.1
+
+ # apply background change if condition matches
+ output_image = np.where(condition, frame, bg_image)
+
+ # show the output
+ cv2.imshow('Background Change with MP', output_image)
+ key = cv2.waitKey(5) & 0xFF
+
+ if key == ord('n'):
+ back1+=1
+ if back1 ==img+1:
+ back1=1
+ path = f'../assest/background/back{back1}.png'
+ if key == ord('a'):
+ path = add_path(input('path image : '))
+ # wait until any key is pressed
+
+ if key == ord('q'):
+ cam.release()
+ cv2.destroyAllWindows() # wait until any key is pressed
+ cam.release()
+ cv2.destroyAllWindows()
+
+
+
diff --git a/background_live/filter_background_live.py b/background_live/filter_background_live.py
new file mode 100644
index 0000000..b002c31
--- /dev/null
+++ b/background_live/filter_background_live.py
@@ -0,0 +1,13 @@
+from background_live import background
+from request_image import add_path,check_image
+from os.path import exists
+
+type_filter = int(input('type_filter : '))
+type_blur=int(input('number for blur start from 1 : '))
+if type_filter == 0:
+ path,img = add_path(input('path image : '))
+ background('../assest/background/back1.png', type_blur,img)
+if type_filter ==1:
+ img =check_image()
+ print(img)
+ background('../assest/background/back1.png',type_blur,img)
diff --git a/background_live/request_image.py b/background_live/request_image.py
new file mode 100644
index 0000000..1e548ca
--- /dev/null
+++ b/background_live/request_image.py
@@ -0,0 +1,27 @@
+import requests
+from os.path import exists
+def add_path(image_path):
+ r= requests.get(image_path)
+ img =1
+ path_image = f'../assest/background/back{img}.png'
+ file_exists = exists(path_image)
+ while file_exists :
+ img+=1
+ path_image = f'../assest/background/back{img}.png'
+ file_exists = exists(path_image)
+
+ with open(path_image,'wb') as f :
+ f.write(r.content)
+
+ return path_image,img
+
+def check_image():
+ img = 1
+ path_image = f'../assest/background/back{img}.png'
+ file_exists = exists(path_image)
+ while file_exists:
+ img += 1
+ path_image = f'../assest/background/back{img}.png'
+ file_exists = exists(path_image)
+ return img-1
+
diff --git a/filters/__pycache__/beardfilter.cpython-39.pyc b/filters/__pycache__/beardfilter.cpython-39.pyc
new file mode 100644
index 0000000..9458e5e
Binary files /dev/null and b/filters/__pycache__/beardfilter.cpython-39.pyc differ
diff --git a/filters/__pycache__/change_filter.cpython-39.pyc b/filters/__pycache__/change_filter.cpython-39.pyc
new file mode 100644
index 0000000..33bce6b
Binary files /dev/null and b/filters/__pycache__/change_filter.cpython-39.pyc differ
diff --git a/filters/__pycache__/video_filtering_face.cpython-39.pyc b/filters/__pycache__/video_filtering_face.cpython-39.pyc
new file mode 100644
index 0000000..02cfcd9
Binary files /dev/null and b/filters/__pycache__/video_filtering_face.cpython-39.pyc differ
diff --git a/filters/beardfilter.py b/filters/beardfilter.py
index ccec66c..cc820ca 100644
--- a/filters/beardfilter.py
+++ b/filters/beardfilter.py
@@ -2,66 +2,92 @@
import numpy as np
import dlib
from math import hypot
+from change_filter import change_filter
+# change_filter =[{'filter':['../assest/hair9.png','../assest/ghoul2.png'],'center':[27,66],'width':[1.5,1],'height':[1,1],'up':[100,20],'left':[0,0]}]
+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("shape_predictor_68_face_landmarks.dat")
+counte=0
+def video_filtering_face(path,center,width,height,up,left,counte=0):
+
+ filter_image = []
+ for i in path:
+ filter_image.append(cv2.imread(i))
+
-def video_filtering_face(path,center,width,height,up=0,left=0,yahia = False):
- filter_path = path
- filter_image = cv2.imread(filter_path)
- detector = dlib.get_frontal_face_detector()
- predictor = dlib.shape_predictor("shape_predictor_68_face_landmarks.dat")
- cap = cv2.VideoCapture(0)
- _, frame = cap.read()
- rows, cols, _ = frame.shape
- filter1 = np.zeros((rows, cols), np.uint8)
while cap.isOpened():
+ filter1 = np.zeros((rows, cols), np.uint8)
+
_, frame = cap.read()
filter1.fill(0)
gray_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = detector(frame)
if faces:
try:
+ for i in range(len(path)):
+ filter(frame,gray_frame,faces,filter_image[i],center[i],width[i],height[i],up[i],left[i])
+ except:
+ _, frame_f = cap.read()
+ cv2.imshow("Frame", frame_f)
+ else:
+ _, frame_f = cap.read()
+ cv2.imshow("Frame", frame_f)
+ key = cv2.waitKey(1)
+ if key == ord('n'):
+ # print('first : ' ,i)
+ change_image(counte)
+ # print('second : ', i)
- for face in faces:
- landmarks = predictor(gray_frame, face)
- # filter coordinates
- if yahia:
- up = (landmarks.part(8).y - landmarks.part(62).y)*3
- center_filter = (landmarks.part(center).x-left, landmarks.part(center).y-up)
- left_filter = (landmarks.part(3).x, landmarks.part(3).y)
- right_filter = (landmarks.part(13).x, landmarks.part(13).y)
- filter_width = int(hypot(left_filter[0] - right_filter[0],
- left_filter[1] - right_filter[1]) * width)
- filter_height = int(filter_width *height)
+def filter(frame,gray_frame,faces,filter_image1,center,width,height,up=0,left=0):
+ for face in faces:
+ landmarks = predictor(gray_frame, face)
- # 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))
+ # filter coordinates
+ # top_filter = (landmarks.part(27).x+10, landmarks.part(24).y+10)
+ # if yahia:
+ # up = (landmarks.part(8).y - landmarks.part(62).y) * 3
+ 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)
- # Adding the new filter
- # coloring
- filtery = cv2.resize(filter_image, (filter_width, filter_height))
- filtery_gray = cv2.cvtColor(filtery, cv2.COLOR_BGR2GRAY)
+ filter_width = int(hypot(left_filter[0] - right_filter[0],
+ left_filter[1] - right_filter[1]) * width)
+ filter_height = int(filter_width * height)
- _, filter1 = cv2.threshold(filtery_gray, 25, 255, cv2.THRESH_BINARY_INV)
+ # 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))
- filter_area = frame[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)
+ # Adding the new filter
+ # coloring
+ 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)
- frame[top_left[1]: top_left[1] + filter_height,
- top_left[0]: top_left[0] + filter_width] = final_filter
+ filter_area = frame[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)
- cv2.imshow("Frame", frame)
- except:
- _, frame_f = cap.read()
- cv2.imshow("Frame", frame_f)
- else:
- _, frame_f = cap.read()
- cv2.imshow("Frame", frame_f)
- key = cv2.waitKey(1)
- if key == 27:
- break
\ No newline at end of file
+ frame[top_left[1]: top_left[1] + filter_height,
+ top_left[0]: top_left[0] + filter_width,:] = final_filter
+
+ cv2.imshow("Frame", frame)
+
+def change_image(i):
+ video_filtering_face(
+ change_filter[i]['filter'],
+ change_filter[i]['center'],
+ change_filter[i]['width'],
+ change_filter[i]['height'],
+ change_filter[i]['up'],
+ change_filter[i]['left'],
+ change_filter[i]['counte']
+ )
diff --git a/filters/change_filter.py b/filters/change_filter.py
new file mode 100644
index 0000000..c3ecd0d
--- /dev/null
+++ b/filters/change_filter.py
@@ -0,0 +1,62 @@
+
+
+change_filter =[{'filter':['../assest/hair9.png','../assest/ghoul2.png','../assest/eye1.png','../assest/eye2.png'],
+ 'center':[27,66,40,46],
+ 'width':[1.5,1,0.2,0.2],
+ 'height':[1,1,0.4,0.4],
+ 'up':[100,20,5,5],
+ 'left':[0,0,0,0],
+ 'counte':1},
+ {'filter': ["../assest/birthday-hat.png"],
+ 'center': [27],
+ 'width': [1.3],
+ 'height': [1],
+ 'up': [120],
+ 'left': [0],
+ 'counte':2},
+ {'filter': ["../assest/gold-crown.png"],
+ 'center': [27],
+ 'width': [1.3],
+ 'height': [1],
+ 'up': [120],
+ 'left': [0],
+ 'counte':3},
+ {'filter': ["../assest/queens-crown.png"],
+ 'center': [27],
+ 'width': [1.3],
+ 'height': [1],
+ 'up': [120],
+ 'left': [0],
+ 'counte':4},
+ {'filter': ["../assest/flower-crown.png"],
+ 'center': [27],
+ 'width': [1.3],
+ 'height': [1],
+ 'up': [80],
+ 'left': [0],
+ 'counte': 5},
+ {'filter': ["../assest/funny-sunglass.png"],
+ 'center': [27],
+ 'width': [1.05],
+ 'height': [0.33],
+ 'up': [0],
+ 'left': [0],
+ 'counte': 6},
+ {'filter': ['../assest/moustache2.png'],
+ 'center': [51],
+ 'width': [1],
+ 'height': [0.5],
+ 'up': [1],
+ 'left': [-3],
+ 'counte': 7},
+ {'filter': ["../assest/tongue.png"],
+ 'center': [57],
+ 'width': [0.6],
+ 'height': [1.2],
+ 'up': [-25],
+ 'left': [0],
+ 'counte': 0},
+
+
+ ]
+
diff --git a/filters/fliter_face.json b/filters/fliter_face.json
new file mode 100644
index 0000000..e6c7b90
--- /dev/null
+++ b/filters/fliter_face.json
@@ -0,0 +1,6 @@
+change_filter =[{'filter':['../assest/hair9.png','../assest/ghoul2.png'],
+ 'center':[27,66],
+ 'width':[1.5,1],
+ 'height':[1,1],
+ 'up':[100,20],
+ 'left':[0,0]}]
diff --git a/filters/video_filtering_face.py b/filters/video_filtering_face.py
index 85995d4..09ebfb5 100644
--- a/filters/video_filtering_face.py
+++ b/filters/video_filtering_face.py
@@ -2,11 +2,11 @@
# video_filtering_face("beard.png",8,1.1,1.5)
-# video_filtering_face("../assest/birthday-hat.png",27,1.3,1.2,yahia=True)
-# video_filtering_face("../assest/gold-crown.png",29,1.5,0.5, yahia = True)
-# video_filtering_face("../assest/queens-crown.png",29,1.5,0.5, yahia = True)
-# video_filtering_face("../assest/flower-crown.png",27,1.5,0.5,90)
+
# video_filtering_face("../assest/sunglasses2.png",27,1,0.35) ## not working
# video_filtering_face("../assest/funny-sunglass.png",27,1.05,0.33)
-# video_filtering_face("../assest/moustache2.png",51,1,0.5,1,-3)
-video_filtering_face("../assest/tongue.png",57,0.6,1.2,-25)
\ No newline at end of file
+# video_filtering_face(['../assest/moustache2.png'],[51],[1],[0.5],[1],[-3])
+video_filtering_face(["../assest/tongue.png"],[57],[0.6],[1.2],[-25],[0])
+# video_filtering_face(['../assest/hair9.png','../assest/ghoul2.png','../assest/eye1.png','../assest/eye2.png'],
+# [27,66,40,46],[1.5,1,0.2,0.2],[1,1,0.4,0.4],[100,20,5,5],[0,0,0,0])
+