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
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.

26 changes: 18 additions & 8 deletions background_image/check_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,30 @@ def saveimage(path):
os.remove(path)
return
def add_path(image_path,origin):

path_image = file_exist(origin)

if ':' in image_path and "\\" in image_path and 'http' not in image_path:
img = cv2.imread(image_path)
cv2.imwrite(path_image, img)

else:
r= requests.get(image_path)
with open(path_image,'wb') as f :
f.write(r.content)

return path_image

def file_exist(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 :
while file_exists:
path_name2 = input('this name is exist try another one or enter q : ')
if path_name2 =='q':
path_image=''
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
7 changes: 6 additions & 1 deletion background_image/filter_background_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ def filter_background_image():
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/')

path_input_image=add_path(input('image path : '),'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(',')))
Expand All @@ -17,4 +21,5 @@ def filter_background_image():
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()
25 changes: 3 additions & 22 deletions background_live/background_live.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import mediapipe as mp
import numpy as np
from request_image import add_path
import os
def background(path,blur =1,img=2):
mp_selfie_segmentation = mp.solutions.selfie_segmentation
back1=1
Expand All @@ -15,10 +14,10 @@ def background(path,blur =1,img=2):

# begin with selfie segmentation model

img_name = ""

while cam.isOpened():
scene = cv2.imread(path) # read the scene image
scene = cv2.blur(scene, (blur, blur))
scene = cv2.blur(scene, (1, 1))
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
Expand Down Expand Up @@ -52,29 +51,11 @@ def background(path,blur =1,img=2):
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
elif key == ord("c"):
img_name = "../saved/opencv_frame.png"
cv2.imwrite(img_name, output_image)
# print("{} written!".format(img_name))
break
frames = cv2.imread(img_name)
cv2.imshow("Background Change with MP", frames)
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, frames)
background('../assest/background/back1.png',blur,img)
if key == ord("e"):
background('../assest/background/back1.png',blur,img)
cam.release()
cv2.destroyAllWindows()

Expand Down
15 changes: 6 additions & 9 deletions background_live/filter_background_live.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
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_filter = (input('add new background [yes,no] ? '))
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)
if type_filter == 'yes':
add_path(input('path image : '))

img =check_image()
background('../assest/background/back1.png',type_blur,img)
24 changes: 17 additions & 7 deletions background_live/request_image.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
import requests
from os.path import exists
import os
import cv2
def add_path(image_path):
r= requests.get(image_path)
img =1
path_image=file_exist()
if ':' in image_path and "\\" in image_path and 'http' not in image_path:
print('hello')
img = cv2.imread(image_path)
cv2.imwrite(path_image, img)
else:
print('hi')
r= requests.get(image_path)
with open(path_image,'wb') as f :
f.write(r.content)


def file_exist():
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
return path_image

def check_image():
img = 1
Expand Down
Binary file not shown.
69 changes: 69 additions & 0 deletions filters_image/change_filter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
## jaso file for adding

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':[0.5,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/beard.png"],
'center': [8],
'width': [1.1],
'height': [1.5],
'up': [0],
'left': [0],
'counte': 8},
{'filter': ["../assest/tongue.png"],
'center': [57],
'width': [0.6],
'height': [1.2],
'up': [-25],
'left': [0],
'counte': 0},


]

Loading