| 205 | |
| 206 | |
| 207 | def get_pytorch3d_camera_params(batch: dotdict): |
| 208 | # Extract pytorc3d camera parameters from batch input |
| 209 | # R and T are applied on the right (requires a transposed R from OpenCV camera format) |
| 210 | # Coordinate system is different from that of OpenCV (cv: right down front, 3d: left up front) |
| 211 | # However, the correction has to be down on both T and R... (instead of just R) |
| 212 | C = -batch.R.mT @ batch.T # B, 3, 1 |
| 213 | R = batch.R.clone() |
| 214 | R[..., 0, :] *= -1 # flip x row |
| 215 | R[..., 1, :] *= -1 # flip y row |
| 216 | T = (-R @ C)[..., 0] # c2w back to w2c |
| 217 | R = R.mT # applied left (left multiply to right multiply, god knows why...) |
| 218 | |
| 219 | H = batch.meta.H[0].item() # !: BATCH |
| 220 | W = batch.meta.W[0].item() # !: BATCH |
| 221 | K = get_pytorch3d_ndc_K(batch.K, H, W) |
| 222 | |
| 223 | return H, W, K, R, T, C |
| 224 | |
| 225 | # TODO: Remove pcd_t and with_t semantics, this is a legacy API |
| 226 | |