Returns a camera view as a NumPy array of pixel values. Args: height: Viewport height (number of pixels). Optional, defaults to 240. width: Viewport width (number of pixels). Optional, defaults to 320. camera_id: Optional camera name or index. Defaults to -1, the free
(
self,
height=240,
width=320,
camera_id=-1,
overlays=(),
depth=False,
segmentation=False,
scene_option=None,
render_flag_overrides=None,
scene_callback: Optional[Callable[['Physics', mujoco.MjvScene],
None]] = None,
)
| 176 | mujoco.mj_step(self.model.ptr, self.data.ptr, nstep) |
| 177 | |
| 178 | def render( |
| 179 | self, |
| 180 | height=240, |
| 181 | width=320, |
| 182 | camera_id=-1, |
| 183 | overlays=(), |
| 184 | depth=False, |
| 185 | segmentation=False, |
| 186 | scene_option=None, |
| 187 | render_flag_overrides=None, |
| 188 | scene_callback: Optional[Callable[['Physics', mujoco.MjvScene], |
| 189 | None]] = None, |
| 190 | ): |
| 191 | """Returns a camera view as a NumPy array of pixel values. |
| 192 | |
| 193 | Args: |
| 194 | height: Viewport height (number of pixels). Optional, defaults to 240. |
| 195 | width: Viewport width (number of pixels). Optional, defaults to 320. |
| 196 | camera_id: Optional camera name or index. Defaults to -1, the free |
| 197 | camera, which is always defined. A nonnegative integer or string |
| 198 | corresponds to a fixed camera, which must be defined in the model XML. |
| 199 | If `camera_id` is a string then the camera must also be named. |
| 200 | overlays: An optional sequence of `TextOverlay` instances to draw. Only |
| 201 | supported if `depth` is False. |
| 202 | depth: If `True`, this method returns a NumPy float array of depth values |
| 203 | (in meters). Defaults to `False`, which results in an RGB image. |
| 204 | segmentation: If `True`, this method returns a 2-channel NumPy int32 array |
| 205 | of label values where the pixels of each object are labeled with the |
| 206 | pair (mjModel ID, mjtObj enum object type). Background pixels are |
| 207 | labeled (-1, -1). Defaults to `False`, which returns an RGB image. |
| 208 | scene_option: An optional `wrapper.MjvOption` instance that can be used to |
| 209 | render the scene with custom visualization options. If None then the |
| 210 | default options will be used. |
| 211 | render_flag_overrides: Optional mapping specifying rendering flags to |
| 212 | override. The keys can be either lowercase strings or `mjtRndFlag` enum |
| 213 | values, and the values are the overridden flag values, e.g. |
| 214 | `{'wireframe': True}` or `{mujoco.mjtRndFlag.mjRND_WIREFRAME: True}`. |
| 215 | See `mujoco.mjtRndFlag` for the set of valid flags. Must be None if |
| 216 | either `depth` or `segmentation` is True. |
| 217 | scene_callback: Called after the scene has been created and before |
| 218 | it is rendered. Can be used to add more geoms to the scene. |
| 219 | |
| 220 | Returns: |
| 221 | The rendered RGB, depth or segmentation image. |
| 222 | """ |
| 223 | camera = Camera( |
| 224 | physics=self, |
| 225 | height=height, |
| 226 | width=width, |
| 227 | camera_id=camera_id, |
| 228 | scene_callback=scene_callback) |
| 229 | image = camera.render( |
| 230 | overlays=overlays, depth=depth, segmentation=segmentation, |
| 231 | scene_option=scene_option, render_flag_overrides=render_flag_overrides) |
| 232 | camera._scene.free() # pylint: disable=protected-access |
| 233 | return image |
| 234 | |
| 235 | def get_state(self, sig=None): |