File size: 1,499 Bytes
2e78bab
 
 
 
b82f603
 
 
 
 
2e78bab
b82f603
 
2e78bab
b82f603
 
 
 
2e78bab
b82f603
 
 
 
2e78bab
b82f603
2e78bab
b82f603
2e78bab
 
b82f603
2e78bab
 
b82f603
 
 
 
2e78bab
 
b82f603
 
2e78bab
 
b82f603
 
 
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
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:
        # 画像サイズ取得
        width, height = image.size
        
        # 上から下へのグラデーション
        depth_array = np.zeros((height, width), dtype=np.uint8)
        for y in range(height):
            depth_array[y, :] = int(255 * y / height)
        
        # カラー深度マップ作成(青から赤へ)
        depth_colored = np.zeros((height, width, 3), dtype=np.uint8)
        depth_colored[:, :, 0] = 255 - depth_array  # 赤チャンネル
        depth_colored[:, :, 2] = depth_array        # 青チャンネル
        
        depth_image = Image.fromarray(depth_colored)
        
        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():
        input_image = gr.Image(label="入力画像", type="pil")
        output_depth = gr.Image(label="深度マップ")
    
    input_image.change(
        fn=create_depth_map,
        inputs=input_image,
        outputs=[input_image, output_depth]
    )

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