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 n
(
self,
physics: Physics,
height: int = 240,
width: int = 320,
camera_id: Union[int, str] = -1,
max_geom: Optional[int] = None,
scene_callback: Optional[Callable[[Physics, mujoco.MjvScene],
None]] = None,
)
| 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.') |
| 700 | if camera_id >= physics.model.ncam: |
| 701 | raise ValueError('model has {} fixed cameras. camera_id={} is invalid.'. |
| 702 | format(physics.model.ncam, camera_id)) |
| 703 | |
| 704 | self._width = width |
| 705 | self._height = height |
| 706 | self._physics = physics |
| 707 | self._scene_callback = scene_callback |
| 708 |
no test coverage detected