Spaces:
Runtime error
Runtime error
TK156
commited on
Commit
·
2693362
1
Parent(s):
e5808c5
feat: 深度推定機能を追加
Browse files- グラデーションベースの深度マップ生成
- 自動画像処理
- 直感的なUI
- app.py +57 -7
- requirements.txt +3 -1
app.py
CHANGED
@@ -1,13 +1,63 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
|
3 |
-
def
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
if __name__ == "__main__":
|
13 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
from PIL import Image
|
4 |
|
5 |
+
def create_depth_map(image):
|
6 |
+
"""シンプルな深度マップ生成"""
|
7 |
+
if image is None:
|
8 |
+
return None
|
9 |
+
|
10 |
+
try:
|
11 |
+
# 画像をnumpy配列に変換
|
12 |
+
img_array = np.array(image)
|
13 |
+
height, width = img_array.shape[:2]
|
14 |
+
|
15 |
+
# 上から下へのグラデーション(上=遠い/青、下=近い/赤)
|
16 |
+
depth_map = np.zeros((height, width, 3), dtype=np.uint8)
|
17 |
+
|
18 |
+
for y in range(height):
|
19 |
+
ratio = y / height
|
20 |
+
# 青から赤へのグラデーション
|
21 |
+
depth_map[y, :, 0] = int(255 * ratio) # 赤
|
22 |
+
depth_map[y, :, 2] = int(255 * (1 - ratio)) # 青
|
23 |
+
|
24 |
+
return Image.fromarray(depth_map)
|
25 |
+
|
26 |
+
except Exception as e:
|
27 |
+
print(f"Error: {e}")
|
28 |
+
return image
|
29 |
|
30 |
+
# Gradioインターフェース
|
31 |
+
with gr.Blocks(title="深度推定API") as demo:
|
32 |
+
gr.Markdown("# 🌊 深度推定・3D可視化 API")
|
33 |
+
gr.Markdown("画像をアップロードして深度マップを生成します")
|
34 |
+
|
35 |
+
with gr.Row():
|
36 |
+
with gr.Column():
|
37 |
+
input_image = gr.Image(
|
38 |
+
label="入力画像",
|
39 |
+
type="pil",
|
40 |
+
height=300
|
41 |
+
)
|
42 |
+
with gr.Column():
|
43 |
+
output_depth = gr.Image(
|
44 |
+
label="深度マップ(上=遠い/青、下=近い/赤)",
|
45 |
+
height=300
|
46 |
+
)
|
47 |
+
|
48 |
+
# 画像変更時に自動処理
|
49 |
+
input_image.change(
|
50 |
+
fn=create_depth_map,
|
51 |
+
inputs=input_image,
|
52 |
+
outputs=output_depth
|
53 |
+
)
|
54 |
+
|
55 |
+
gr.Markdown("""
|
56 |
+
### 📝 使い方
|
57 |
+
1. 画像をアップロードまたはドラッグ&ドロップ
|
58 |
+
2. 深度マップが自動生成されます
|
59 |
+
3. 青=遠い部分、赤=近い部分
|
60 |
+
""")
|
61 |
|
62 |
if __name__ == "__main__":
|
63 |
demo.launch()
|
requirements.txt
CHANGED
@@ -1 +1,3 @@
|
|
1 |
-
gradio
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
numpy
|
3 |
+
pillow
|