查看ITHOR全部仿真家庭场景

1. 目标

  1. 按序号显示所有120个家庭场景
  2. 统计单个场景里物体数量

2. 代码

python 复制代码
import time
from ai2thor.controller import Controller

# 统计当前场景中的物体数量
def count_objects_in_scene(controller):
    objects = controller.last_event.metadata["objects"]
    object_count = len(objects)
    return object_count

# 初始化控制器
controller = Controller(
    width=1280,
    height=720,
    fieldOfView=110,
    visibilityDistance=5,
    renderInstanceSegmentation=True
)

input("请按任意键启动场景遍历:")

# 定义需要遍历的场景编号范围
scene_ranges = [
range(1, 31),   # 厨房
range(201, 231), # 客厅
range(301, 331), # 卧室
range(401, 431)  # 浴室
]

for scene_range in scene_ranges:
    for scene_number in scene_range:            
        selected_scene = f"FloorPlan{scene_number}"
        # 刷新到选定的场景
        controller.reset(selected_scene)
        # 统计当前场景中的物体数量
        object_count = count_objects_in_scene(controller)        
        print(f"{selected_scene}场景中共有 {object_count} 个物体")
        time.sleep(0.5)  # 等待0.5秒后进入下一个场景

3. 最终成果

ithor全部场景

相关推荐
SelectDB40 分钟前
Apache Doris Python UDF:让 SQL 直接调用 Python 生态,支撑 Agent 时代复杂业务逻辑
大数据·数据库·python
荣码8 小时前
GraphRAG:普通RAG只能回答"点"的问题,我踩了4个坑才搞懂
java·python
金銀銅鐵19 小时前
[Python] 基于欧几里得算法,实现分数约分计算器
python·数学
Lyn_Li21 小时前
Kaggle Top 5 | 198只股票、200条数据的金融预测——BattleFin高分方案从零复现
python·kaggle·比赛复盘·金融预测
小九九的爸爸1 天前
前端想要入门Agent开发,要具备哪些Python基础?
python·agent·ai编程
阿耶同学1 天前
手把手教你用 LangGraph 搭建三层嵌套 Agent 架构
python·程序员
花酒锄作田2 天前
Pydantic校验配置文件
python
hboot2 天前
AI工程师第四课 - 深度学习入门
pytorch·python·神经网络
ZhengEnCi2 天前
P2M-Matplotlib折线图完全指南-从数据可视化到趋势分析的Python绘图利器
python·matlab·数据可视化
ZhengEnCi2 天前
P2L-Matplotlib饼图完全指南-从数据可视化到图表定制的Python绘图利器
python·matlab