-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wait for solve error danielgatis/rembg#312
- Loading branch information
1 parent
7cbd6ec
commit ee16dec
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |