MCPcopy Create free account
hub / github.com/google-deepmind/dm_control / Camera

Class Camera

dm_control/mujoco/engine.py:642–1000  ·  view source on GitHub ↗

Mujoco scene camera. Holds rendering properties such as the width and height of the viewport. The camera position and rotation is defined by the Mujoco camera corresponding to the `camera_id`. Multiple `Camera` instances may exist for a single `camera_id`, for example to render the same vie

Source from the content-addressed store, hash-verified

640
641
642class Camera:
643 """Mujoco scene camera.
644
645 Holds rendering properties such as the width and height of the viewport. The
646 camera position and rotation is defined by the Mujoco camera corresponding to
647 the `camera_id`. Multiple `Camera` instances may exist for a single
648 `camera_id`, for example to render the same view at different resolutions.
649 """
650
651 def __init__(
652 self,
653 physics: Physics,
654 height: int = 240,
655 width: int = 320,
656 camera_id: Union[int, str] = -1,
657 max_geom: Optional[int] = None,
658 scene_callback: Optional[Callable[[Physics, mujoco.MjvScene],
659 None]] = None,
660 ):
661 """Initializes a new `Camera`.
662
663 Args:
664 physics: Instance of `Physics`.
665 height: Optional image height. Defaults to 240.
666 width: Optional image width. Defaults to 320.
667 camera_id: Optional camera name or index. Defaults to -1, the free
668 camera, which is always defined. A nonnegative integer or string
669 corresponds to a fixed camera, which must be defined in the model XML.
670 If `camera_id` is a string then the camera must also be named.
671 max_geom: Optional integer specifying the maximum number of geoms that can
672 be rendered in the same scene. If None this will be chosen automatically
673 based on the estimated maximum number of renderable geoms in the model.
674 scene_callback: Called after the scene has been created and before
675 it is rendered. Can be used to add more geoms to the scene.
676 Raises:
677 ValueError: If `camera_id` is outside the valid range, or if `width` or
678 `height` exceed the dimensions of MuJoCo's offscreen framebuffer.
679 """
680 buffer_width = physics.model.vis.global_.offwidth
681 buffer_height = physics.model.vis.global_.offheight
682 if width > buffer_width:
683 raise ValueError('Image width {} > framebuffer width {}. Either reduce '
684 'the image width or specify a larger offscreen '
685 'framebuffer in the model XML using the clause\n'
686 '<visual>\n'
687 ' <global offwidth="my_width"/>\n'
688 '</visual>'.format(width, buffer_width))
689 if height > buffer_height:
690 raise ValueError('Image height {} > framebuffer height {}. Either reduce '
691 'the image height or specify a larger offscreen '
692 'framebuffer in the model XML using the clause\n'
693 '<visual>\n'
694 ' <global offheight="my_height"/>\n'
695 '</visual>'.format(height, buffer_height))
696 if isinstance(camera_id, str):
697 camera_id = physics.model.name2id(camera_id, 'camera')
698 if camera_id < -1:
699 raise ValueError('camera_id cannot be smaller than -1.')

Callers 1

renderMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…