Download code/agt/recon/pose_rule.py from MRBSTUDIO/AGT: direct link, hf CLI and curl.
- Browser
- Download file 1.38 kB
-
https://huggingface.co/MRBSTUDIO/AGT/resolve/main/code/agt/recon/pose_rule.py
- Command line
-
hf download hf://MRBSTUDIO/AGT/code/agt/recon/pose_rule.py
-
curl -L -o pose_rule.py https://huggingface.co/MRBSTUDIO/AGT/resolve/main/code/agt/recon/pose_rule.py
1.38 kB
| from __future__ import annotations | |
| import numpy as np | |
| from scipy.spatial.transform import Rotation, Slerp | |
| def interpolate_poses(context_times, context_c2w, target_times) -> np.ndarray: | |
| t = np.asarray(context_times, dtype=np.float64) | |
| poses = np.asarray(context_c2w, dtype=np.float64) | |
| targets = np.atleast_1d(np.asarray(target_times, dtype=np.float64)) | |
| if t.ndim != 1 or len(t) < 2 or poses.shape != (len(t), 4, 4) or np.any(np.diff(t) <= 0): | |
| raise ValueError('Need >= 2 context poses with strictly increasing times') | |
| rotations = Rotation.from_matrix(poses[:, :3, :3]) | |
| centres = poses[:, :3, 3] | |
| out = np.tile(np.eye(4), (len(targets), 1, 1)) | |
| inside = (targets >= t[0]) & (targets <= t[-1]) | |
| if inside.any(): | |
| out[inside, :3, :3] = Slerp(t, rotations)(targets[inside]).as_matrix() | |
| out[inside, :3, 3] = np.stack([np.interp(targets[inside], t, centres[:, k]) for k in range(3)], -1) | |
| for mask, a, b in ((targets > t[-1], -2, -1), (targets < t[0], 0, 1)): | |
| if mask.any(): | |
| alpha = (targets[mask] - t[a]) / (t[b] - t[a]) | |
| relative = (rotations[a].inv() * rotations[b]).as_rotvec() | |
| out[mask, :3, :3] = (rotations[a] * Rotation.from_rotvec(alpha[:, None] * relative[None])).as_matrix() | |
| out[mask, :3, 3] = centres[a] + alpha[:, None] * (centres[b] - centres[a]) | |
| return out | |