查看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全部场景

相关推荐
用户8356290780512 小时前
使用 C# 在 Excel 中创建数据透视表
后端·python
码路飞5 小时前
FastMCP 实战:一个 .py 文件,给 Claude Code 装上 3 个超实用工具
python·ai编程·mcp
dev派7 小时前
AI Agent 系统中的常用 Workflow 模式(2) Evaluator-Optimizer模式
python·langchain
前端付豪9 小时前
AI 数学辅导老师项目构想和初始化
前端·后端·python
用户0332126663679 小时前
将 PDF 文档转换为图片【Python 教程】
python
悟空爬虫10 小时前
UV实战教程,我啥要从Anaconda切换到uv来管理包?
python
dev派10 小时前
AI Agent 系统中的常用 Workflow 模式(1)
python·langchain
明月_清风12 小时前
从“能用”到“专业”:构建生产级装饰器与三层逻辑拆解
后端·python
曲幽1 天前
数据库实战:FastAPI + SQLAlchemy 2.0 + Alembic 从零搭建,踩坑实录
python·fastapi·web·sqlalchemy·db·asyncio·alembic
用户8356290780511 天前
Python 实现 PowerPoint 形状动画设置
后端·python