Spaces:
Sleeping
Sleeping
File size: 2,689 Bytes
ad8cacf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
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('サンプル画像が見つかりませんでした')
|