Spaces:
Runtime error
Runtime error
File size: 1,932 Bytes
2e78bab b899d5f 2e78bab 4f55111 b899d5f 4f55111 b899d5f 4f55111 b899d5f 4f55111 b899d5f 4f55111 b899d5f 2e78bab 4f55111 2e78bab b899d5f |
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 59 60 61 |
import gradio as gr
import numpy as np
from PIL import Image
def create_depth_map(image):
"""グラデーション深度マップ生成"""
if image is None:
return None, None
try:
# 画像をnumpy配列に変換
img_array = np.array(image)
height, width = img_array.shape[:2]
# 上から下へのグラデーション深度マップ
depth_map = np.zeros((height, width, 3), dtype=np.uint8)
for y in range(height):
ratio = y / height
# 青(遠い)から赤(近い)へのグラデーション
depth_map[y, :, 0] = int(255 * ratio) # 赤
depth_map[y, :, 1] = int(128 * (1 - ratio)) # 緑
depth_map[y, :, 2] = int(255 * (1 - ratio)) # 青
depth_image = Image.fromarray(depth_map)
return image, depth_image
except Exception as e:
print(f"Error: {e}")
return image, image
# Gradio インターフェース
with gr.Blocks(title="深度推定API") as demo:
gr.Markdown("# 🌊 深度推定・3D可視化 API")
gr.Markdown("画像をアップロードして深度マップを生成します")
with gr.Row():
with gr.Column():
input_image = gr.Image(
label="入力画像",
type="pil"
)
with gr.Column():
output_original = gr.Image(label="元画像")
output_depth = gr.Image(label="深度マップ")
# 画像変更時に自動処理
input_image.change(
fn=create_depth_map,
inputs=input_image,
outputs=[output_original, output_depth]
)
gr.Markdown("""
### 📝 使い方
- 画像をアップロードすると自動で深度マップが生成されます
- 青=遠い部分、赤=近い部分
""")
if __name__ == "__main__":
demo.launch() |