jandan138 commited on
Commit
c3f4714
·
1 Parent(s): 3f871ba

add scene png to pos

Browse files
Files changed (2) hide show
  1. app.py +37 -0
  2. scene.png +0 -0
app.py CHANGED
@@ -3,6 +3,7 @@ import requests
3
  # import json
4
  import os
5
  from typing import Optional
 
6
 
7
  # 后端API配置(可配置化)
8
  BACKEND_URL = os.getenv("BACKEND_URL", "http://your-backend-server:5000")
@@ -38,6 +39,24 @@ MODEL_CHOICES = [
38
  "AcT+CLIP"
39
  ]
40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  def submit_to_backend(
42
  scene: str,
43
  prompt: str,
@@ -227,6 +246,17 @@ with gr.Blocks(title="机器人导航仿真系统", css=custom_css) as demo:
227
  interactive=False,
228
  format="mp4"
229
  )
 
 
 
 
 
 
 
 
 
 
 
230
 
231
  # 指标展示
232
  metrics_output = gr.JSON(
@@ -268,6 +298,13 @@ with gr.Blocks(title="机器人导航仿真系统", css=custom_css) as demo:
268
  outputs=scene_description
269
  )
270
 
 
 
 
 
 
 
 
271
 
272
  # 启动应用
273
  if __name__ == "__main__":
 
3
  # import json
4
  import os
5
  from typing import Optional
6
+ import numpy as np
7
 
8
  # 后端API配置(可配置化)
9
  BACKEND_URL = os.getenv("BACKEND_URL", "http://your-backend-server:5000")
 
39
  "AcT+CLIP"
40
  ]
41
 
42
+ def image_to_position(image: np.ndarray, evt: gr.SelectData) -> str:
43
+ """
44
+ 根据点击图像的位置(像素坐标)转换为仿真空间中的起始位置坐标
45
+ - image: 被点击图像的像素数据
46
+ - evt: 包含用户点击的位置 evt.index = (x, y)
47
+
48
+ 这里假设图像宽高映射到 -1 到 1 的世界坐标范围
49
+ """
50
+ h, w = image.shape[:2]
51
+ px, py = evt.index # 点击位置 (x, y)
52
+
53
+ # 映射为 -1 到 1 的标准坐标(你可按需改成真实比例)
54
+ x = (px / w) * 2 - 1
55
+ y = -((py / h) * 2 - 1) # 注意y坐标反向(图像是从上往下)
56
+ z = 0.1 # 默认高度
57
+
58
+ return f"{x:.2f}, {y:.2f}, {z:.2f}"
59
+
60
  def submit_to_backend(
61
  scene: str,
62
  prompt: str,
 
246
  interactive=False,
247
  format="mp4"
248
  )
249
+
250
+ # 场景俯视图图像(点击获取起点)
251
+ scene_image = gr.Image(
252
+ value="/scene.png", # 占位图路径
253
+ label="点击选择起点位置(场景俯视图)",
254
+ source="upload",
255
+ tool=None,
256
+ type="numpy", # 获取坐标
257
+ interactive=True,
258
+ height=300
259
+ )
260
 
261
  # 指标展示
262
  metrics_output = gr.JSON(
 
298
  outputs=scene_description
299
  )
300
 
301
+ # ✅ 添加点击图片 → 自动设置起始位置
302
+ scene_image.select(
303
+ fn=image_to_position,
304
+ inputs=[scene_image],
305
+ outputs=start_pos_input
306
+ )
307
+
308
 
309
  # 启动应用
310
  if __name__ == "__main__":
scene.png ADDED