File size: 1,885 Bytes
2e78bab
2693362
 
2e78bab
2693362
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2e78bab
2693362
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2e78bab
 
b82f603
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
62
63
import gradio as gr
import numpy as np
from PIL import Image

def create_depth_map(image):
    """シンプルな深度マップ生成"""
    if image is None:
        return 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, :, 2] = int(255 * (1 - ratio)) # 青
        
        return Image.fromarray(depth_map)
        
    except Exception as e:
        print(f"Error: {e}")
        return 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",
                height=300
            )
        with gr.Column():
            output_depth = gr.Image(
                label="深度マップ(上=遠い/青、下=近い/赤)",
                height=300
            )
    
    # 画像変更時に自動処理
    input_image.change(
        fn=create_depth_map,
        inputs=input_image,
        outputs=output_depth
    )
    
    gr.Markdown("""
    ### 📝 使い方
    1. 画像をアップロードまたはドラッグ&ドロップ
    2. 深度マップが自動生成されます
    3. 青=遠い部分、赤=近い部分
    """)

if __name__ == "__main__":
    demo.launch()