相机 (Camera)#

class genesis.vis.camera.Camera(visualizer, idx=0, model='pinhole', res=(320, 320), pos=(0.5, 2.5, 3.5), lookat=(0.5, 0.5, 0.5), up=(0.0, 0.0, 1.0), fov=30, aperture=2.8, focus_dist=None, GUI=False, spp=256, denoise=True, near=0.05, far=100.0, transform=None)[源代码]#

基类:RBC

Genesis camera class. The camera can be used to render RGB, depth, and segmentation images. The camera can use either rasterizer or raytracer for rendering, specified by scene.renderer. The camera also comes with handy tools such as video recording.

参数:
  • visualizer (genesis.Visualizer) – The visualizer object that the camera is associated with.

  • idx (int) – The index of the camera.

  • model (str) – Specifies the camera model. Options are ‘pinhole’ or ‘thinlens’.

  • res (tuple of int, shape (2,)) – The resolution of the camera, specified as a tuple (width, height).

  • pos (tuple of float, shape (3,)) – The position of the camera in the scene, specified as (x, y, z).

  • lookat (tuple of float, shape (3,)) – The point in the scene that the camera is looking at, specified as (x, y, z).

  • up (tuple of float, shape (3,)) – The up vector of the camera, defining its orientation, specified as (x, y, z).

  • fov (float) – The vertical field of view of the camera in degrees.

  • aperture (float) – The aperture size of the camera, controlling depth of field.

  • focus_dist (float | None) – The focus distance of the camera. If None, it will be auto-computed using pos and lookat.

  • GUI (bool) – Whether to display the camera’s rendered image in a separate GUI window.

  • spp (int, optional) – Samples per pixel. Defaults to 256.

  • denoise (bool) – Whether to denoise the camera’s rendered image.

  • near (float) – The near plane of the camera.

  • far (float) – The far plane of the camera.

  • transform (np.ndarray, shape (4, 4), optional) – The transform matrix of the camera.

render(rgb=True, depth=False, segmentation=False, colorize_seg=False, normal=False)[源代码]#

Render the camera view. Note that the segmentation mask can be colorized, and if not colorized, it will store an object index in each pixel based on the segmentation level specified in vis_options.segmentation_level. For example, if segmentation_level=’link’, the segmentation mask will store link_idx, which can then be used to retrieve the actual link objects using scene.rigid_solver.links[link_idx].

参数:
  • rgb (bool, optional) – Whether to render an RGB image.

  • depth (bool, optional) – Whether to render a depth image.

  • segmentation (bool, optional) – Whether to render the segmentation mask.

  • colorize_seg (bool, optional) – If True, the segmentation mask will be colorized.

  • normal (bool, optional) – Whether to render the surface normal.

返回:

  • rgb_arr (np.ndarray) – The rendered RGB image.

  • depth_arr (np.ndarray) – The rendered depth image.

  • seg_arr (np.ndarray) – The rendered segmentation mask.

  • normal_arr (np.ndarray) – The rendered surface normal.

set_pose(transform=None, pos=None, lookat=None, up=None)[源代码]#

Set the pose of the camera. Note that transform has a higher priority than pos, lookat, and up. If transform is provided, the camera pose will be set based on the transform matrix. Otherwise, the camera pose will be set based on pos, lookat, and up.

参数:
  • transform (np.ndarray, shape (4, 4), optional) – The transform matrix of the camera.

  • pos (array-like, shape (3,), optional) – The position of the camera.

  • lookat (array-like, shape (3,), optional) – The lookat point of the camera.

  • up (array-like, shape (3,), optional) – The up vector of the camera.

set_params(fov=None, aperture=None, focus_dist=None)[源代码]#

Update the camera parameters.

参数:
  • fov (float, optional) – The vertical field of view of the camera.

  • aperture (float, optional) – The aperture of the camera. Only supports ‘thinlens’ camera model.

  • focus_dist (float, optional) – The focus distance of the camera. Only supports ‘thinlens’ camera model.

start_recording()[源代码]#

Start recording on the camera. After recording is started, all the rgb images rendered by camera.render() will be stored, and saved to a video file when camera.stop_recording() is called.

pause_recording()[源代码]#

Pause recording on the camera. After recording is paused, the rgb images rendered by camera.render() will not be stored. Recording can be resumed by calling camera.start_recording() again.

stop_recording(save_to_filename=None, fps=60)[源代码]#

Stop recording on the camera. Once this is called, all the rgb images stored so far will be saved to a video file. If save_to_filename is None, the video file will be saved with the name ‘{caller_file_name}_cam_{camera.idx}.mp4’.

参数:
  • save_to_filename (str, optional) – Name of the output video file. If not provided, the name will be default to the name of the caller file, with camera idx, a timestamp and ‘.mp4’ extension.

  • fps (int, optional) – The frames per second of the video file.

property is_built#

Whether the camera is built.

property idx#

The integer index of the camera.

property uid#

The unique ID of the camera

property model#

pinhole or thinlens.

Type:

The camera model

property res#

The resolution of the camera.

property fov#

The field of view of the camera.

property aperture#

The aperture of the camera.

property focal_len#

The focal length for thinlens camera. Returns -1 for pinhole camera.

property focus_dist#

The focus distance of the camera.

property GUI#

Whether the camera will display the rendered images in a separate window.

property spp#

Samples per pixel of the camera.

property denoise#

Whether the camera will denoise the rendered image in raytracer.

property near#

The near plane of the camera.

property far#

The far plane of the camera.

property aspect_ratio#

The aspect ratio of the camera.

property pos#

The current position of the camera.

property lookat#

The current lookat point of the camera.

property up#

The current up vector of the camera.

property transform#

The current transform matrix of the camera.

property extrinsics#

The current extrinsics matrix of the camera.

property intrinsics#

The current intrinsics matrix of the camera.