From ee16decdc2231d1ee43e14a4a5844d5225a11abb Mon Sep 17 00:00:00 2001 From: Dmitry Godyaev Date: Sun, 16 Oct 2022 16:27:11 +0400 Subject: [PATCH] ADD simple script wait for solve error https://github.com/danielgatis/rembg/issues/312 --- .gitignore | 4 ++++ main.py | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 main.py diff --git a/.gitignore b/.gitignore index c0c219b..969bc03 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ +venv/ +.idea/ +.u2net/ +input_imgs/ # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] diff --git a/main.py b/main.py new file mode 100644 index 0000000..94237bf --- /dev/null +++ b/main.py @@ -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()