Omniverse Replicator的Camera示例

Camera示例

本教程的目的是提供 Omniverse Replicator 中相机常见用例的示例。 以下是使用 Replicator API 在场景中应用相机使用的几个示例。

学习目标

通过此页面,您将看到一些突出显示的相机示例以及如何使用它们。 但是,有关复制相机使用的所有信息,请参阅 API 文档。

设置

下面显示的每个相机示例都是独立脚本,可以按照设置脚本编辑器和运行和预览复制器中描述的设置运行。

创建相机并设置属性

创建相机并初始化其属性非常简单。 下面是一个小片段作为示例,但 API 记录了所有可用选项。

import omni.replicator.core as rep

# Create camera
camera = rep.create.camera(
    position=rep.distribution.uniform((0,0,0), (100, 100, 100)),
    rotation=(45, 45, 0),
    focus_distance=rep.distribution.normal(400.0, 100),
    f_stop=1.8,
)

均匀随机化相机的位置

示例显示如何将相机移动到一个区域中的随机位置,该区域由均匀分布选择。

import omni.replicator.core as rep

# Randomize the camera position using basic uniform distribution

with rep.new_layer():

    # Create camera
    # https://docs.omniverse.nvidia.com/py/replicator/source/extensions/omni.replicator.core/docs/API.html#omni.replicator.core.create.camera
    camera = rep.create.camera(focus_distance=200,f_stop=0.5)

    cube = rep.create.cube(semantics=[('class', 'cube')],  position=(0, 0, 0))
    render_product  = rep.create.render_product(camera, (1024, 1024))

    # Initialize and attach writer
    writer = rep.WriterRegistry.get("BasicWriter")
    writer.initialize(output_dir="_output_camera_uniformpos", rgb=True, bounding_box_2d_tight=True)
    writer.attach([render_product])

    with rep.trigger.on_frame(num_frames=10):
        with camera:
            rep.modify.pose(position=rep.distribution.uniform((-500, 200, -500), (500, 500, 500)), look_at=(0,0,0))

使用列表随机化相机的位置

显示如何使用选择分布将相机移动到从列表中选择的随机位置的示例。

import omni.replicator.core as rep

# Pick a random camera location each frame, from a list

with rep.new_layer():

    # Create camera
    # https://docs.omniverse.nvidia.com/py/replicator/source/extensions/omni.replicator.core/docs/API.html#omni.replicator.core.create.camera
    camera_positions = [(-500, 200, -500), (500, 500, 500)]

    camera = rep.create.camera(focus_distance=200,f_stop=0.5)

    cube = rep.create.cube(semantics=[('class', 'cube')],  position=(0, 0, 0))
    render_product  = rep.create.render_product(camera, (1024, 1024))

    # Initialize and attach writer
    writer = rep.WriterRegistry.get("BasicWriter")
    writer.initialize(output_dir="_output_camera_posfromlist", rgb=True, bounding_box_2d_tight=True)
    writer.attach([render_product])

    with rep.trigger.on_frame(num_frames=10):
        with camera:
            rep.modify.pose(position=rep.distribution.choice(camera_positions), look_at=(0,0,0))

Basic Writer 多摄像头

Replicator 支持多个摄像头。 下面是场景中有两个摄像机的基本编写器的一个小示例,为每个帧写入输出。


import omni.replicator.core as rep

camera1_pos = [(0, 100, 500),(500, 100, 500),(-500, 100, 500),]
camera2_pos = [(0, 500, 0),(500, 500, 0),(-500, 500, 0),]

with rep.new_layer():
    cube = rep.create.cube(position=(200, 0, 0), semantics=[('class', 'cube')])
    sphere = rep.create.sphere(position=(0, 0, 0), semantics=[('class', 'sphere')])
    cone = rep.create.cone(position=(-200, 0, 0), semantics=[('class', 'cone')])

    camera = rep.create.camera(position=camera1_pos[0], look_at=(0,0,0))
    camera2 = rep.create.camera(position=camera2_pos[0], look_at=(0,0,0))

    with rep.trigger.on_frame(num_frames=3):
        with camera:
            rep.modify.pose(look_at=(0,0,0), position=rep.distribution.sequence(camera1_pos))
        with camera2:
            rep.modify.pose(look_at=(0,0,0), position=rep.distribution.sequence(camera2_pos))

# Will render 512x512 images and 320x240 images
render_product = rep.create.render_product(camera, (512, 512))
render_product2 = rep.create.render_product(camera2, (320, 240))

basic_writer = rep.WriterRegistry.get("BasicWriter")
basic_writer.initialize(
    output_dir=f"~/replicator_examples/multi_render_product/basic",
    rgb=True,
    bounding_box_2d_loose=True,
    bounding_box_2d_tight=True,
    bounding_box_3d=True,
    distance_to_camera=True,
    distance_to_image_plane=True,
    instance_segmentation=True,
    normals=True,
    semantic_segmentation=True,
)
# Attach render_product to the writer
basic_writer.attach([render_product, render_product2])
# Run the simulation graph
rep.orchestrator.run()

你可能感兴趣的:(Omniverse,Replicator开发文档,人工智能,深度学习,计算机视觉,机器学习,Omniverse)