Converting PyTorch3D cameras to extrinsics, intrinsics matrix Return extrinsics, intrinsics, focal_length, principal_point
(pred_cameras, image_size, B, S, default_focal=False)
| 185 | |
| 186 | |
| 187 | def get_EFP(pred_cameras, image_size, B, S, default_focal=False): |
| 188 | """ |
| 189 | Converting PyTorch3D cameras to extrinsics, intrinsics matrix |
| 190 | |
| 191 | Return extrinsics, intrinsics, focal_length, principal_point |
| 192 | """ |
| 193 | scale = image_size.min() |
| 194 | |
| 195 | focal_length = pred_cameras.focal_length |
| 196 | |
| 197 | principal_point = torch.zeros_like(focal_length) |
| 198 | |
| 199 | focal_length = focal_length * scale / 2 |
| 200 | principal_point = (image_size[None] - principal_point * scale) / 2 |
| 201 | |
| 202 | Rots = pred_cameras.R.clone() |
| 203 | Trans = pred_cameras.T.clone() |
| 204 | |
| 205 | extrinsics = torch.cat([Rots, Trans[..., None]], dim=-1) |
| 206 | |
| 207 | # reshape |
| 208 | extrinsics = extrinsics.reshape(B, S, 3, 4) |
| 209 | focal_length = focal_length.reshape(B, S, 2) |
| 210 | principal_point = principal_point.reshape(B, S, 2) |
| 211 | |
| 212 | # only one dof focal length |
| 213 | if default_focal: |
| 214 | focal_length[:] = scale |
| 215 | else: |
| 216 | focal_length = focal_length.mean(dim=-1, keepdim=True).expand(-1, -1, 2) |
| 217 | focal_length = focal_length.clamp(0.2 * scale, 5 * scale) |
| 218 | |
| 219 | intrinsics = create_intri_matrix(focal_length, principal_point) |
| 220 | return extrinsics, intrinsics |
| 221 | |
| 222 | def quaternion_to_matrix(quaternions: torch.Tensor) -> torch.Tensor: |
| 223 | """ |
nothing calls this directly
no test coverage detected