Convert transformation matrix to quaternion and translation.
(RT, Tquad=False)
| 181 | |
| 182 | |
| 183 | def get_tensor_from_camera(RT, Tquad=False): |
| 184 | """ |
| 185 | Convert transformation matrix to quaternion and translation. |
| 186 | |
| 187 | """ |
| 188 | # gpu_id = -1 |
| 189 | # if type(RT) == torch.Tensor: |
| 190 | # if RT.get_device() != -1: |
| 191 | # gpu_id = RT.get_device() |
| 192 | # RT = RT.detach().cpu() |
| 193 | # RT = RT.numpy() |
| 194 | # from mathutils import Matrix |
| 195 | # |
| 196 | # R, T = RT[:3, :3], RT[:3, 3] |
| 197 | # rot = Matrix(R) |
| 198 | # quad = rot.to_quaternion() |
| 199 | # if Tquad: |
| 200 | # tensor = np.concatenate([T, quad], 0) |
| 201 | # else: |
| 202 | # tensor = np.concatenate([quad, T], 0) |
| 203 | # tensor = torch.from_numpy(tensor).float() |
| 204 | # if gpu_id != -1: |
| 205 | # tensor = tensor.to(gpu_id) |
| 206 | # return tensor |
| 207 | |
| 208 | if not isinstance(RT, torch.Tensor): |
| 209 | RT = torch.tensor(RT).cuda() |
| 210 | |
| 211 | rot = RT[:3, :3].unsqueeze(0).detach() |
| 212 | quat = rotation2quad(rot).squeeze() |
| 213 | tran = RT[:3, 3].detach() |
| 214 | |
| 215 | return torch.cat([quat, tran]) |
| 216 | |
| 217 | def normalize(x): |
| 218 | return x / np.linalg.norm(x) |
no test coverage detected