Skip to content

Commit

Permalink
ADD simple script
Browse files Browse the repository at this point in the history
wait for solve error danielgatis/rembg#312
  • Loading branch information
noDGodiaev committed Oct 16, 2022
1 parent 7cbd6ec commit ee16dec
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
venv/
.idea/
.u2net/
input_imgs/
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
35 changes: 35 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import os
import logging
from rembg import remove
from PIL import Image
from pathlib import Path


def remove_bg():
list_of_extensions = ['*.png', '*.jpg', '*.jfif']
all_files = []
for ext in list_of_extensions:
all_files.extend(Path('input_imgs').glob(ext))

for index, item in enumerate(all_files):
input_path = Path(item)
file_name = input_path.stem

# create save folder
output_folder = 'output_imgs'
if not os.path.exists(output_folder):
os.mkdir(output_folder)
output_path = f'output_imgs/{file_name}_output.png'
input_img = Image.open(input_path)
output_img = remove(input_img)
output_img.save(output_path)

logging.info(f'Completed: {index + 1}/{len(all_files)}')


def main():
remove_bg()


if __name__ == '__main__':
main()

0 comments on commit ee16dec

Please sign in to comment.