(self,
               physics,
               height=240,
               width=320,
               camera_id=-1,
               max_geom=None)
Initializes a new `Camera`.

    Args:
      physics: Instance of `Physics`.
      height: Optional image height. Defaults to 240.
      width: Optional image width. Defaults to 320.
      camera_id: Optional camera name or index. Defaults to -1, the free
        camera, which is always defined. A nonnegative integer or string
        corresponds to a fixed camera, which must be defined in the model XML.
        If `camera_id` is a string then the camera must also be named.
      max_geom: Optional integer specifying the maximum number of geoms that can
        be rendered in the same scene. If None this will be chosen automatically
        based on the estimated maximum number of renderable geoms in the model.
    Raises:
      ValueError: If `camera_id` is outside the valid range, or if `width` or
        `height` exceed the dimensions of MuJoCo's offscreen framebuffer.
Initializes a new `Camera`.
Initializes a new Camera .
def __init__(self,
               physics,
               height=240,
               width=320,
               camera_id=-1,
               max_geom=None):
    """Initializes a new `Camera`.

    Args:
      physics: Instance of `Physics`.
      height: Optional image height. Defaults to 240.
      width: Optional image width. Defaults to 320.
      camera_id: Optional camera name or index. Defaults to -1, the free
        camera, which is always defined. A nonnegative integer or string
        corresponds to a fixed camera, which must be defined in the model XML.
        If `camera_id` is a string then the camera must also be named.
      max_geom: Optional integer specifying the maximum number of geoms that can
        be rendered in the same scene. If None this will be chosen automatically
        based on the estimated maximum number of renderable geoms in the model.
    Raises:
      ValueError: If `camera_id` is outside the valid range, or if `width` or
        `height` exceed the dimensions of MuJoCo's offscreen framebuffer.
    """
    buffer_width = physics.model.vis.global_.offwidth
    buffer_height = physics.model.vis.global_.offheight
    if width > buffer_width:
      raise ValueError('Image width {} > framebuffer width {}. Either reduce '
                       'the image width or specify a larger offscreen '
                       'framebuffer in the model XML using the clause\n'
                       '<visual>\n'
                       '  <global offwidth="my_width"/>\n'
                       '</visual>'.format(width, buffer_width))
    if height > buffer_height:
      raise ValueError('Image height {} > framebuffer height {}. Either reduce '
                       'the image height or specify a larger offscreen '
                       'framebuffer in the model XML using the clause\n'
                       '<visual>\n'
                       '  <global offheight="my_height"/>\n'
                       '</visual>'.format(height, buffer_height))
    if isinstance(camera_id, str):
      camera_id = physics.model.name2id(camera_id, 'camera')
    if camera_id < -1:
      raise ValueError('camera_id cannot be smaller than -1.')
    if camera_id >= physics.model.ncam:
      raise ValueError('model has {} fixed cameras. camera_id={} is invalid.'.
                       format(physics.model.ncam, camera_id))

    self._width = width
    self._height = height
    self._physics = physics

    # Variables corresponding to structs needed by Mujoco's rendering functions.
    self._scene = wrapper.MjvScene(model=physics.model, max_geom=max_geom)
    self._scene_option = wrapper.MjvOption()

    self._perturb = wrapper.MjvPerturb()
    self._perturb.active = 0
    self._perturb.select = 0

    self._rect = types.MJRRECT(0, 0, self._width, self._height)

    self._render_camera = wrapper.MjvCamera()
    self._render_camera.fixedcamid = camera_id

    if camera_id == -1:
      self._render_camera.type_ = enums.mjtCamera.mjCAMERA_FREE
    else:
      # As defined in the Mujoco documentation, mjCAMERA_FIXED refers to a
      # camera explicitly defined in the model.
      self._render_camera.type_ = enums.mjtCamera.mjCAMERA_FIXED

    # Internal buffers.
    self._rgb_buffer = np.empty((self._height, self._width, 3), dtype=np.uint8)
    self._depth_buffer = np.empty((self._height, self._width), dtype=np.float32)

    if self._physics.contexts.mujoco is not None:
      with self._physics.contexts.gl.make_current() as ctx:
        ctx.call(mjlib.mjr_setBuffer,
                 enums.mjtFramebuffer.mjFB_OFFSCREEN,
                 self._physics.contexts.mujoco.ptr)
def __init__ ( self , physics , height = 240 , width = 320 , camera_id = - 1 , max_geom = None ) : buffer_width = physics . model . vis . global_ . offwidth buffer_height = physics . model . vis . global_ . offheight if width > buffer_width : raise ValueError ( 'Image width {} > framebuffer width {}. Either reduce ' 'the image width or specify a larger offscreen ' 'framebuffer in the model XML using the clause\n' '<visual>\n' '  <global offwidth="my_width"/>\n' '</visual>' . format ( width , buffer_width ) ) if height > buffer_height : raise ValueError ( 'Image height {} > framebuffer height {}. Either reduce ' 'the image height or specify a larger offscreen ' 'framebuffer in the model XML using the clause\n' '<visual>\n' '  <global offheight="my_height"/>\n' '</visual>' . format ( height , buffer_height ) ) if isinstance ( camera_id , str ) : camera_id = physics . model . name2id ( camera_id , 'camera' ) if camera_id < - 1 : raise ValueError ( 'camera_id cannot be smaller than -1.' ) if camera_id >= physics . model . ncam : raise ValueError ( 'model has {} fixed cameras. camera_id={} is invalid.' . format ( physics . model . ncam , camera_id ) ) self . _width = width self . _height = height self . _physics = physics # Variables corresponding to structs needed by Mujoco's rendering functions. self . _scene = wrapper . MjvScene ( model = physics . model , max_geom = max_geom ) self . _scene_option = wrapper . MjvOption ( ) self . _perturb = wrapper . MjvPerturb ( ) self . _perturb . active = 0 self . _perturb . select = 0 self . _rect = types . MJRRECT ( 0 , 0 , self . _width , self . _height ) self . _render_camera = wrapper . MjvCamera ( ) self . _render_camera . fixedcamid = camera_id if camera_id == - 1 : self . _render_camera . type_ = enums . mjtCamera . mjCAMERA_FREE else : # As defined in the Mujoco documentation, mjCAMERA_FIXED refers to a # camera explicitly defined in the model. self . _render_camera . type_ = enums . mjtCamera . mjCAMERA_FIXED # Internal buffers. self . _rgb_buffer = np . empty ( ( self . _height , self . _width , 3 ) , dtype = np . uint8 ) self . _depth_buffer = np . empty ( ( self . _height , self . _width ) , dtype = np . float32 ) if self . _physics . contexts . mujoco is not None : with self . _physics . contexts . gl . make_current ( ) as ctx : ctx . call ( mjlib . mjr_setBuffer , enums . mjtFramebuffer . mjFB_OFFSCREEN , self . _physics . contexts . mujoco . ptr )