You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Isaac Sim 5.1中如何不写入磁盘直接获取相机图像?

在Isaac Sim 5.1中直接获取相机图像(无需写入磁盘)

以下是几种可行的方法,无需依赖已移除的omni.replicator.core.capture:

方法1:通过Viewport接口获取图像

利用Isaac Sim的Viewport接口直接读取当前相机视口的像素数据,转换为numpy数组即可直接使用:

import omni.kit.viewport
import numpy as np

# 获取当前活跃视口(需确保目标相机已设为视口相机)
viewport_interface = omni.kit.viewport.get_viewport_interface()
viewport = viewport_interface.get_viewport_window()

# 获取RGBA格式的图像缓冲区数据
buffer = viewport.get_texture_resolved_buffer()
img_data = np.frombuffer(buffer, dtype=np.uint8).reshape(buffer.height, buffer.width, 4)

# 可选:转换为RGB格式(剔除Alpha通道)
img_rgb = img_data[..., :3]

方法2:通过相机的Render Product获取图像

针对指定相机(非视口相机),可直接从其渲染产物中提取图像数据:

import omni.replicator.core as rep
import numpy as np

# 替换为你的相机USD路径
camera = rep.get_node("/World/Camera")

# 创建对应分辨率的Render Product
render_product = rep.create.render_product(camera, resolution=(1920, 1080))

# 读取帧数据
reader = rep.create.render_product_reader(render_product)
img_data = reader.get_next_frame()

# img_data为(height, width, 4)格式的numpy数组,可直接用于后续处理

方法3:读取相机的渲染纹理输出

部分相机节点支持直接访问渲染后的纹理,通过USD属性读取:

import omni.usd
import numpy as np
from pxr import UsdGeom
import omni.ui as ui

# 获取USD阶段和目标相机Prim
stage = omni.usd.get_context().get_stage()
camera_prim = stage.GetPrimAtPath("/World/Camera")

# 获取相机绑定的渲染纹理路径
texture_attr = camera_prim.GetAttribute("camera:renderTexture")
texture_path = texture_attr.Get()
texture_prim = stage.GetPrimAtPath(texture_path)

# 将纹理转换为numpy数组
if texture_prim.IsA(UsdGeom.Texture):
    texture_provider = ui.TextureProvider()
    texture_handle = texture_provider.get_texture(texture_path)
    img_data = texture_handle.as_numpy_array()

注意事项

  • 确保相机已配置正确的渲染参数(分辨率、输出格式等)
  • 所有方法获取的图像均为内存中的numpy数组,可直接用于计算机视觉模型输入或其他内存内处理流程
  • 使用Render Product方法时,需确保omni.replicator.core模块已正常加载

内容的提问来源于stack exchange,提问作者user3318590

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.01 13:12:31