Convert rotation matrixs to quaternions. Args: matrix (Union[torch.Tensor, numpy.ndarray]): input shape should be (..., 3, 3). ndim of input is unlimited. Returns: Union[torch.Tensor, numpy.ndarray]: shape would be (..., 4).
(
matrix: Union[torch.Tensor, numpy.ndarray]
)
| 146 | |
| 147 | |
| 148 | def rotmat_to_quat( |
| 149 | matrix: Union[torch.Tensor, numpy.ndarray] |
| 150 | ) -> Union[torch.Tensor, numpy.ndarray]: |
| 151 | """Convert rotation matrixs to quaternions. |
| 152 | |
| 153 | Args: |
| 154 | matrix (Union[torch.Tensor, numpy.ndarray]): input shape |
| 155 | should be (..., 3, 3). ndim of input is unlimited. |
| 156 | Returns: |
| 157 | Union[torch.Tensor, numpy.ndarray]: shape would be (..., 4). |
| 158 | """ |
| 159 | if matrix.shape[-1] != 3 or matrix.shape[-2] != 3: |
| 160 | raise ValueError(f'Invalid rotation matrix shape f{matrix.shape}.') |
| 161 | t = Compose([matrix_to_quaternion]) |
| 162 | return t(matrix) |
| 163 | |
| 164 | |
| 165 | def rotmat_to_rot6d( |