(
      self,
      overlays=(),
      depth=False,
      segmentation=False,
      scene_option=None,
      render_flag_overrides=None,
  )
return np.flipud(image)
Renders the camera view as a numpy array of pixel values.

    Args:
      overlays: An optional sequence of `TextOverlay` instances to draw. Only
        supported if `depth` and `segmentation` are both False.
      depth: An optional boolean. If True, makes the camera return depth
        measurements. Cannot be enabled if `segmentation` is True.
      segmentation: An optional boolean. If True, make the camera return a
        pixel-wise segmentation of the scene. Cannot be enabled if `depth` is
        True.
      scene_option: A custom `wrapper.MjvOption` instance to use to render
        the scene instead of the default.  If None, will use the default.
      render_flag_overrides: Optional mapping containing rendering flags to
        override. The keys can be either lowercase strings or `mjtRndFlag` enum
        values, and the values are the overridden flag values, e.g.
        `{'wireframe': True}` or `{enums.mjtRndFlag.mjRND_WIREFRAME: True}`. See
        `enums.mjtRndFlag` for the set of valid flags. Must be empty if either
        `depth` or `segmentation` is True.

    Returns:
      The rendered scene.
        * If `depth` and `segmentation` are both False (default), this is a
          (height, width, 3) uint8 numpy array containing RGB values.
        * If `depth` is True, this is a (height, width) float32 numpy array
          containing depth values (in meters).
        * If `segmentation` is True, this is a (height, width, 2) int32 numpy
          array where the first channel contains the integer ID of the object at
          each pixel, and the second channel contains the corresponding object
          type (a value in the `mjtObj` enum). Background pixels are labeled
          (-1, -1).

    Raises:
      ValueError: If either `overlays` or `render_flag_overrides` is requested
        when `depth` or `segmentation` rendering is enabled.
      ValueError: If both depth and segmentation flags are set together.
Renders the camera view as a numpy array of pixel values.
Renders the camera view as a numpy array of pixel values .
def render(
      self,
      overlays=(),
      depth=False,
      segmentation=False,
      scene_option=None,
      render_flag_overrides=None,
  ):
    """Renders the camera view as a numpy array of pixel values.

    Args:
      overlays: An optional sequence of `TextOverlay` instances to draw. Only
        supported if `depth` and `segmentation` are both False.
      depth: An optional boolean. If True, makes the camera return depth
        measurements. Cannot be enabled if `segmentation` is True.
      segmentation: An optional boolean. If True, make the camera return a
        pixel-wise segmentation of the scene. Cannot be enabled if `depth` is
        True.
      scene_option: A custom `wrapper.MjvOption` instance to use to render
        the scene instead of the default.  If None, will use the default.
      render_flag_overrides: Optional mapping containing rendering flags to
        override. The keys can be either lowercase strings or `mjtRndFlag` enum
        values, and the values are the overridden flag values, e.g.
        `{'wireframe': True}` or `{enums.mjtRndFlag.mjRND_WIREFRAME: True}`. See
        `enums.mjtRndFlag` for the set of valid flags. Must be empty if either
        `depth` or `segmentation` is True.

    Returns:
      The rendered scene.
        * If `depth` and `segmentation` are both False (default), this is a
          (height, width, 3) uint8 numpy array containing RGB values.
        * If `depth` is True, this is a (height, width) float32 numpy array
          containing depth values (in meters).
        * If `segmentation` is True, this is a (height, width, 2) int32 numpy
          array where the first channel contains the integer ID of the object at
          each pixel, and the second channel contains the corresponding object
          type (a value in the `mjtObj` enum). Background pixels are labeled
          (-1, -1).

    Raises:
      ValueError: If either `overlays` or `render_flag_overrides` is requested
        when `depth` or `segmentation` rendering is enabled.
      ValueError: If both depth and segmentation flags are set together.
    """

    if overlays and (depth or segmentation):
      raise ValueError(_OVERLAYS_NOT_SUPPORTED_FOR_DEPTH_OR_SEGMENTATION)

    if render_flag_overrides and (depth or segmentation):
      raise ValueError(
          _RENDER_FLAG_OVERRIDES_NOT_SUPPORTED_FOR_DEPTH_OR_SEGMENTATION)

    if depth and segmentation:
      raise ValueError(_BOTH_SEGMENTATION_AND_DEPTH_ENABLED)

    if render_flag_overrides is None:
      render_flag_overrides = {}

    # Update scene geometry.
    self.update(scene_option=scene_option)

    # Enable flags to compute segmentation labels
    if segmentation:
      render_flag_overrides.update({
          enums.mjtRndFlag.mjRND_SEGMENT: True,
          enums.mjtRndFlag.mjRND_IDCOLOR: True,
      })

    # Render scene and text overlays, read contents of RGB or depth buffer.
    with self.scene.override_flags(render_flag_overrides):
      with self._physics.contexts.gl.make_current() as ctx:
        ctx.call(self._render_on_gl_thread, depth=depth, overlays=overlays)

    if depth:
      # Get the distances to the near and far clipping planes.
      extent = self._physics.model.stat.extent
      near = self._physics.model.vis.map_.znear * extent
      far = self._physics.model.vis.map_.zfar * extent
      # Convert from [0 1] to depth in meters, see links below:
      # http://stackoverflow.com/a/6657284/1461210
      # https://www.khronos.org/opengl/wiki/Depth_Buffer_Precision
      image = near / (1 - self._depth_buffer * (1 - near / far))
    elif segmentation:
      # Convert 3-channel uint8 to 1-channel uint32.
      image3 = self._rgb_buffer.astype(np.uint32)
      segimage = (image3[:, :, 0] +
                  image3[:, :, 1] * (2**8) +
                  image3[:, :, 2] * (2**16))
      # Remap segid to 2-channel (object ID, object type) pair.
      # Seg ID 0 is background -- will be remapped to (-1, -1).
      segid2output = np.full((self._scene.ngeom + 1, 2), fill_value=-1,
                             dtype=np.int32)  # Seg id cannot be > ngeom + 1.
      visible_geoms = self._scene.geoms[self._scene.geoms.segid != -1]
      segid2output[visible_geoms.segid + 1, 0] = visible_geoms.objid
      segid2output[visible_geoms.segid + 1, 1] = visible_geoms.objtype
      image = segid2output[segimage]
    else:
      image = self._rgb_buffer

    # The first row in the buffer is the bottom row of pixels in the image.
    return np.flipud(image)
def render ( self , overlays = ( ) , depth = False , segmentation = False , scene_option = None , render_flag_overrides = None , ) : if overlays and ( depth or segmentation ) : raise ValueError ( _OVERLAYS_NOT_SUPPORTED_FOR_DEPTH_OR_SEGMENTATION ) if render_flag_overrides and ( depth or segmentation ) : raise ValueError ( _RENDER_FLAG_OVERRIDES_NOT_SUPPORTED_FOR_DEPTH_OR_SEGMENTATION ) if depth and segmentation : raise ValueError ( _BOTH_SEGMENTATION_AND_DEPTH_ENABLED ) if render_flag_overrides is None : render_flag_overrides = { } # Update scene geometry. self . update ( scene_option = scene_option ) # Enable flags to compute segmentation labels if segmentation : render_flag_overrides . update ( { enums . mjtRndFlag . mjRND_SEGMENT : True , enums . mjtRndFlag . mjRND_IDCOLOR : True , } ) # Render scene and text overlays, read contents of RGB or depth buffer. with self . scene . override_flags ( render_flag_overrides ) : with self . _physics . contexts . gl . make_current ( ) as ctx : ctx . call ( self . _render_on_gl_thread , depth = depth , overlays = overlays ) if depth : # Get the distances to the near and far clipping planes. extent = self . _physics . model . stat . extent near = self . _physics . model . vis . map_ . znear * extent far = self . _physics . model . vis . map_ . zfar * extent # Convert from [0 1] to depth in meters, see links below: # http://stackoverflow.com/a/6657284/1461210 # https://www.khronos.org/opengl/wiki/Depth_Buffer_Precision image = near / ( 1 - self . _depth_buffer * ( 1 - near / far ) ) elif segmentation : # Convert 3-channel uint8 to 1-channel uint32. image3 = self . _rgb_buffer . astype ( np . uint32 ) segimage = ( image3 [ : , : , 0 ] + image3 [ : , : , 1 ] * ( 2 ** 8 ) + image3 [ : , : , 2 ] * ( 2 ** 16 ) ) # Remap segid to 2-channel (object ID, object type) pair. # Seg ID 0 is background -- will be remapped to (-1, -1). segid2output = np . full ( ( self . _scene . ngeom + 1 , 2 ) , fill_value = - 1 , dtype = np . int32 ) # Seg id cannot be > ngeom + 1. visible_geoms = self . _scene . geoms [ self . _scene . geoms . segid != - 1 ] segid2output [ visible_geoms . segid + 1 , 0 ] = visible_geoms . objid segid2output [ visible_geoms . segid + 1 , 1 ] = visible_geoms . objtype image = segid2output [ segimage ] else : image = self . _rgb_buffer # The first row in the buffer is the bottom row of pixels in the image. return np . flipud ( image )