Computes the component matrices used to compute the camera matrix. Returns: An instance of `CameraMatrices` containing the image, focal, rotation, and translation matrices of the camera.
(self)
| 757 | return self._scene |
| 758 | |
| 759 | def matrices(self) -> CameraMatrices: |
| 760 | """Computes the component matrices used to compute the camera matrix. |
| 761 | |
| 762 | Returns: |
| 763 | An instance of `CameraMatrices` containing the image, focal, rotation, and |
| 764 | translation matrices of the camera. |
| 765 | """ |
| 766 | camera_id = self._render_camera.fixedcamid |
| 767 | if camera_id == -1: |
| 768 | # If the camera is a 'free' camera, we get its position and orientation |
| 769 | # from the scene data structure. It is a stereo camera, so we average over |
| 770 | # the left and right channels. Note: we call `self.update()` in order to |
| 771 | # ensure that the contents of `scene.camera` are correct. |
| 772 | self.update() |
| 773 | pos = np.mean([camera.pos for camera in self.scene.camera], axis=0) |
| 774 | z = -np.mean([camera.forward for camera in self.scene.camera], axis=0) |
| 775 | y = np.mean([camera.up for camera in self.scene.camera], axis=0) |
| 776 | rot = np.vstack((np.cross(y, z), y, z)) |
| 777 | fov = self._physics.model.vis.global_.fovy |
| 778 | else: |
| 779 | pos = self._physics.data.cam_xpos[camera_id] |
| 780 | rot = self._physics.data.cam_xmat[camera_id].reshape(3, 3).T |
| 781 | fov = self._physics.model.cam_fovy[camera_id] |
| 782 | |
| 783 | # Translation matrix (4x4). |
| 784 | translation = np.eye(4) |
| 785 | translation[0:3, 3] = -pos |
| 786 | # Rotation matrix (4x4). |
| 787 | rotation = np.eye(4) |
| 788 | rotation[0:3, 0:3] = rot |
| 789 | # Focal transformation matrix (3x4). |
| 790 | focal_scaling = (1./np.tan(np.deg2rad(fov)/2)) * self.height / 2.0 |
| 791 | focal = np.diag([-focal_scaling, focal_scaling, 1.0, 0])[0:3, :] |
| 792 | # Image matrix (3x3). |
| 793 | image = np.eye(3) |
| 794 | image[0, 2] = (self.width - 1) / 2.0 |
| 795 | image[1, 2] = (self.height - 1) / 2.0 |
| 796 | return CameraMatrices( |
| 797 | image=image, focal=focal, rotation=rotation, translation=translation) |
| 798 | |
| 799 | @property |
| 800 | def matrix(self): |
no test coverage detected