Buckets:
| from dataclasses import dataclass | |
| import numpy as np | |
| from .geometry import best_rotation | |
| from .skeleton import ARKIT, Skeleton | |
| class Hand: | |
| side: str | |
| poses: np.ndarray | |
| confidence: np.ndarray | |
| skeleton: Skeleton = ARKIT | |
| visible: np.ndarray = None | |
| def __post_init__(self): | |
| if self.visible is None: | |
| self.visible = np.ones(len(self.poses), dtype=bool) | |
| def __len__(self): | |
| return len(self.poses) | |
| def positions(self): | |
| return self.poses[..., :3, 3] | |
| def keypoints(self): | |
| return self.positions[:, list(self.skeleton.keypoints)] | |
| def from_keypoints(cls, side, keypoints, skeleton, visible): | |
| keypoints = _hold(keypoints, visible) | |
| frames, joints = len(keypoints), skeleton.size | |
| reference = int(np.argmax(visible)) | |
| poses = np.tile(np.eye(4), (frames, joints, 1, 1)) | |
| poses[..., :3, 3] = keypoints | |
| for joint in range(joints): | |
| children = skeleton.children[joint] | |
| if children: | |
| rest = ( | |
| keypoints[reference, list(children)] - keypoints[reference, joint] | |
| ) | |
| current = keypoints[:, list(children)] - keypoints[:, [joint]] | |
| poses[:, joint, :3, :3] = best_rotation(rest, current) | |
| else: | |
| poses[:, joint, :3, :3] = poses[:, skeleton.parents[joint], :3, :3] | |
| return cls( | |
| side, | |
| poses, | |
| np.repeat(visible[:, None].astype(float), joints, axis=1), | |
| skeleton, | |
| visible, | |
| ) | |
| def _hold(values, visible): | |
| frames = len(values) | |
| last = np.maximum.accumulate(np.where(visible, np.arange(frames), -1)) | |
| last = np.where(last < 0, int(np.argmax(visible)), last) | |
| return values[last] | |
Xet Storage Details
- Size:
- 1.86 kB
- Xet hash:
- b9acd2cff2d532b01920f6d0556d62b21c3705631cb58ff35dfa0aaa4b79e077
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.