Skip to content
Open
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
3 changes: 1 addition & 2 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.

Binary file removed __pycache__/main.cpython-38.pyc
Binary file not shown.
Binary file added assest/background/back1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assest/background/back2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assest/background/back3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assest/background/back4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assest/background/back5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assest/birthday-hat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assest/eye1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assest/eye2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assest/flower-crown.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assest/funny-sunglass.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assest/ghoul2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assest/gold-crown.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assest/hair9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assest/moustache2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assest/queens-crown.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Binary file added assest/tongue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions background_image/backgorund_image.py
Original file line number Diff line number Diff line change
@@ -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')
46 changes: 46 additions & 0 deletions background_image/check_directory.py
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions background_image/filter_background_image.py
Original file line number Diff line number Diff line change
@@ -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()
65 changes: 65 additions & 0 deletions background_live/background_live.py
Original file line number Diff line number Diff line change
@@ -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()



13 changes: 13 additions & 0 deletions background_live/filter_background_live.py
Original file line number Diff line number Diff line change
@@ -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)
27 changes: 27 additions & 0 deletions background_live/request_image.py
Original file line number Diff line number Diff line change
@@ -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

Binary file added filters/__pycache__/beardfilter.cpython-39.pyc
Binary file not shown.
Binary file added filters/__pycache__/change_filter.cpython-39.pyc
Binary file not shown.
Binary file removed filters/__pycache__/filter1.cpython-39.pyc
Binary file not shown.
Binary file not shown.
93 changes: 93 additions & 0 deletions filters/beardfilter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import cv2
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))


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)



def filter(frame,gray_frame,faces,filter_image1,center,width,height,up=0,left=0):
for face in faces:
landmarks = predictor(gray_frame, face)

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

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

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)

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']
)
73 changes: 0 additions & 73 deletions filters/cat-filter.py

This file was deleted.

Loading