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 measurem
(
self,
overlays=(),
depth=False,
segmentation=False,
scene_option=None,
render_flag_overrides=None,
)
| 838 | self._physics.contexts.mujoco.ptr) |
| 839 | |
| 840 | def render( |
| 841 | self, |
| 842 | overlays=(), |
| 843 | depth=False, |
| 844 | segmentation=False, |
| 845 | scene_option=None, |
| 846 | render_flag_overrides=None, |
| 847 | ): |
| 848 | """Renders the camera view as a numpy array of pixel values. |
| 849 | |
| 850 | Args: |
| 851 | overlays: An optional sequence of `TextOverlay` instances to draw. Only |
| 852 | supported if `depth` and `segmentation` are both False. |
| 853 | depth: An optional boolean. If True, makes the camera return depth |
| 854 | measurements. Cannot be enabled if `segmentation` is True. |
| 855 | segmentation: An optional boolean. If True, make the camera return a |
| 856 | pixel-wise segmentation of the scene. Cannot be enabled if `depth` is |
| 857 | True. |
| 858 | scene_option: A custom `wrapper.MjvOption` instance to use to render |
| 859 | the scene instead of the default. If None, will use the default. |
| 860 | render_flag_overrides: Optional mapping containing rendering flags to |
| 861 | override. The keys can be either lowercase strings or `mjtRndFlag` enum |
| 862 | values, and the values are the overridden flag values, e.g. |
| 863 | `{'wireframe': True}` or `{mujoco.mjtRndFlag.mjRND_WIREFRAME: True}`. |
| 864 | See `mujoco.mjtRndFlag` for the set of valid flags. Must be empty if |
| 865 | either `depth` or `segmentation` is True. |
| 866 | |
| 867 | Returns: |
| 868 | The rendered scene. |
| 869 | * If `depth` and `segmentation` are both False (default), this is a |
| 870 | (height, width, 3) uint8 numpy array containing RGB values. |
| 871 | * If `depth` is True, this is a (height, width) float32 numpy array |
| 872 | containing depth values (in meters). |
| 873 | * If `segmentation` is True, this is a (height, width, 2) int32 numpy |
| 874 | array where the first channel contains the integer ID of the object at |
| 875 | each pixel, and the second channel contains the corresponding object |
| 876 | type (a value in the `mjtObj` enum). Background pixels are labeled |
| 877 | (-1, -1). |
| 878 | |
| 879 | Raises: |
| 880 | ValueError: If either `overlays` or `render_flag_overrides` is requested |
| 881 | when `depth` or `segmentation` rendering is enabled. |
| 882 | ValueError: If both depth and segmentation flags are set together. |
| 883 | """ |
| 884 | |
| 885 | if overlays and (depth or segmentation): |
| 886 | raise ValueError(_OVERLAYS_NOT_SUPPORTED_FOR_DEPTH_OR_SEGMENTATION) |
| 887 | |
| 888 | if render_flag_overrides and (depth or segmentation): |
| 889 | raise ValueError( |
| 890 | _RENDER_FLAG_OVERRIDES_NOT_SUPPORTED_FOR_DEPTH_OR_SEGMENTATION) |
| 891 | |
| 892 | if depth and segmentation: |
| 893 | raise ValueError(_BOTH_SEGMENTATION_AND_DEPTH_ENABLED) |
| 894 | |
| 895 | if render_flag_overrides is None: |
| 896 | render_flag_overrides = {} |
| 897 |