Spaces:
Sleeping
Sleeping
import os | |
from utils.background_remover import remove_background_simple, remove_background_advanced | |
# ใในใ็จใใฃใฌใฏใใชใฎไฝๆ | |
test_output_dir = os.path.join('static', 'test_bg_removal') | |
os.makedirs(test_output_dir, exist_ok=True) | |
# ใในใ็ปๅใฎใใน | |
test_img_dir = os.path.join('static', 'test_output', 'refined_animals') | |
if os.path.exists(test_img_dir): | |
print(f'ใในใใใฃใฌใฏใใชใ่ฆใคใใใพใใ: {test_img_dir}') | |
# ใใฃใฌใฏใใชๅ ใฎ็ปๅใๅๅพ | |
image_files = [f for f in os.listdir(test_img_dir) | |
if f.endswith(('.png', '.jpg', '.jpeg'))] | |
if image_files: | |
test_img = os.path.join(test_img_dir, image_files[0]) | |
print(f'ใในใ็ปๅใ่ฆใคใใใพใใ: {test_img}') | |
# ใทใณใใซใช่ๆฏ้คๅปใใในใ | |
simple_output = os.path.join(test_output_dir, 'bg_removed_simple.png') | |
simple_result = remove_background_simple(test_img, simple_output) | |
print(f'ใทใณใใซ่ๆฏ้คๅป็ตๆ: {simple_result}') | |
# ้ซๅบฆใช่ๆฏ้คๅปใใในใ | |
advanced_output = os.path.join(test_output_dir, 'bg_removed_advanced.png') | |
advanced_result = remove_background_advanced(test_img, advanced_output) | |
print(f'้ซๅบฆใช่ๆฏ้คๅป็ตๆ: {advanced_result}') | |
print('่ๆฏ้คๅปใในใๅฎไบ') | |
else: | |
print('ใในใ็ปๅใ่ฆใคใใใพใใใงใใ') | |
else: | |
print(f'ใในใใใฃใฌใฏใใชใ่ฆใคใใใพใใใงใใ: {test_img_dir}') | |
# ใตใณใใซ็ปๅใใฃใฌใฏใใชใ็ขบ่ช | |
sample_dir = 'static' | |
if os.path.exists(sample_dir): | |
print(f'ใตใณใใซใใฃใฌใฏใใชใ่ฆใคใใใพใใ: {sample_dir}') | |
# ใตใณใใซ็ปๅใๆขใ | |
for root, dirs, files in os.walk(sample_dir): | |
image_files = [f for f in files if f.endswith(('.png', '.jpg', '.jpeg'))] | |
if image_files: | |
test_img = os.path.join(root, image_files[0]) | |
print(f'ใตใณใใซ็ปๅใ่ฆใคใใใพใใ: {test_img}') | |
# ใทใณใใซใช่ๆฏ้คๅปใใในใ | |
simple_output = os.path.join(test_output_dir, 'bg_removed_simple.png') | |
simple_result = remove_background_simple(test_img, simple_output) | |
print(f'ใทใณใใซ่ๆฏ้คๅป็ตๆ: {simple_result}') | |
print('่ๆฏ้คๅปใในใๅฎไบ') | |
break | |
else: | |
print('ใตใณใใซ็ปๅใ่ฆใคใใใพใใใงใใ') | |