Upload folder using huggingface_hub
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +1 -0
- HOT3DHUGGFACE/.gitattributes +2 -0
- HOT3DHUGGFACE/.gitignore +4 -0
- HOT3DHUGGFACE/Data_Reader.ipynb +675 -0
- HOT3DHUGGFACE/HOT3D_Tutorial.ipynb +1045 -0
- HOT3DHUGGFACE/Hot3DVisualizer.py +593 -0
- HOT3DHUGGFACE/data_loaders/AlignedBox2d.py +156 -0
- HOT3DHUGGFACE/data_loaders/AriaDataProvider.py +377 -0
- HOT3DHUGGFACE/data_loaders/HandBox2dDataProvider.py +188 -0
- HOT3DHUGGFACE/data_loaders/HandDataProviderBase.py +184 -0
- HOT3DHUGGFACE/data_loaders/HeadsetPose3dProvider.py +171 -0
- HOT3DHUGGFACE/data_loaders/ManoHandDataProvider.py +128 -0
- HOT3DHUGGFACE/data_loaders/ObjectBox2dDataProvider.py +219 -0
- HOT3DHUGGFACE/data_loaders/ObjectPose3dProvider.py +189 -0
- HOT3DHUGGFACE/data_loaders/PathProvider.py +141 -0
- HOT3DHUGGFACE/data_loaders/QuestDataProvider.py +257 -0
- HOT3DHUGGFACE/data_loaders/UmeTrackHandDataProvider.py +186 -0
- HOT3DHUGGFACE/data_loaders/constants.py +53 -0
- HOT3DHUGGFACE/data_loaders/frameset.py +66 -0
- HOT3DHUGGFACE/data_loaders/hand_common.py +169 -0
- HOT3DHUGGFACE/data_loaders/headsets.py +20 -0
- HOT3DHUGGFACE/data_loaders/io_utils.py +70 -0
- HOT3DHUGGFACE/data_loaders/loader_hand_poses.py +175 -0
- HOT3DHUGGFACE/data_loaders/loader_masks.py +156 -0
- HOT3DHUGGFACE/data_loaders/loader_object_library.py +91 -0
- HOT3DHUGGFACE/data_loaders/loader_poses_utils.py +27 -0
- HOT3DHUGGFACE/data_loaders/mano_layer.py +314 -0
- HOT3DHUGGFACE/data_loaders/pose_utils.py +101 -0
- HOT3DHUGGFACE/data_loaders/pytorch3d_rotation/rotation_conversions.py +171 -0
- HOT3DHUGGFACE/data_loaders/umetrack_layer.py +229 -0
- HOT3DHUGGFACE/dataset/P0002_2f137f83/.download_status.json +5 -0
- HOT3DHUGGFACE/dataset/P0002_2f137f83/box2d_hands.csv +0 -0
- HOT3DHUGGFACE/dataset/P0002_2f137f83/box2d_objects.csv +0 -0
- HOT3DHUGGFACE/dataset/P0002_2f137f83/camera_models.json +82 -0
- HOT3DHUGGFACE/dataset/P0002_2f137f83/dynamic_objects.csv +0 -0
- HOT3DHUGGFACE/dataset/P0002_2f137f83/headset_trajectory.csv +0 -0
- HOT3DHUGGFACE/dataset/P0002_2f137f83/license.txt +15 -0
- HOT3DHUGGFACE/dataset/P0002_2f137f83/mano_hand_pose_trajectory.jsonl +0 -0
- HOT3DHUGGFACE/dataset/P0002_2f137f83/masks/mask_good_exposure.csv +0 -0
- HOT3DHUGGFACE/dataset/P0002_2f137f83/masks/mask_hand_pose_available.csv +0 -0
- HOT3DHUGGFACE/dataset/P0002_2f137f83/masks/mask_hand_visible.csv +0 -0
- HOT3DHUGGFACE/dataset/P0002_2f137f83/masks/mask_headset_pose_available.csv +0 -0
- HOT3DHUGGFACE/dataset/P0002_2f137f83/masks/mask_object_pose_available.csv +0 -0
- HOT3DHUGGFACE/dataset/P0002_2f137f83/masks/mask_object_visible.csv +0 -0
- HOT3DHUGGFACE/dataset/P0002_2f137f83/masks/mask_qa_pass.csv +0 -0
- HOT3DHUGGFACE/dataset/P0002_2f137f83/metadata.json +31 -0
- HOT3DHUGGFACE/dataset/P0002_2f137f83/recording.vrs +3 -0
- HOT3DHUGGFACE/dataset/P0002_2f137f83/umetrack_hand_pose_trajectory.jsonl +0 -0
- HOT3DHUGGFACE/dataset/P0002_2f137f83/umetrack_hand_user_profile.json +0 -0
- HOT3DHUGGFACE/dataset_api.py +244 -0
.gitattributes
CHANGED
|
@@ -58,3 +58,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 58 |
# Video files - compressed
|
| 59 |
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 60 |
*.webm filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 58 |
# Video files - compressed
|
| 59 |
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 60 |
*.webm filter=lfs diff=lfs merge=lfs -text
|
| 61 |
+
HOT3DHUGGFACE/dataset/P0002_2f137f83/recording.vrs filter=lfs diff=lfs merge=lfs -text
|
HOT3DHUGGFACE/.gitattributes
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# GitHub syntax highlighting
|
| 2 |
+
pixi.lock linguist-language=YAML
|
HOT3DHUGGFACE/.gitignore
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# pixi environments
|
| 2 |
+
.pixi
|
| 3 |
+
# dataset download instruction
|
| 4 |
+
/dataset/**
|
HOT3DHUGGFACE/Data_Reader.ipynb
ADDED
|
@@ -0,0 +1,675 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "markdown",
|
| 5 |
+
"id": "ee215408-e60b-4209-a09a-f84a8fd5ffa1",
|
| 6 |
+
"metadata": {},
|
| 7 |
+
"source": [
|
| 8 |
+
"# HOT3D Data Reader\n",
|
| 9 |
+
"\n",
|
| 10 |
+
"This notebook is adapted from the HOT3D official tutorial. It supports both **Aria** and **Quest3** devices and uses only the **MANO** hand model (no UmeTrack or object assets required).\n",
|
| 11 |
+
"\n",
|
| 12 |
+
"## Sections\n",
|
| 13 |
+
"- **Section 0**: Initialization (update the two paths, then run)\n",
|
| 14 |
+
"- **Section 1**: Image streams + camera calibration\n",
|
| 15 |
+
"- **Section 2.a**: Device / headset pose trajectory\n",
|
| 16 |
+
"- **Section 2.b**: Hand wrist trajectory\n",
|
| 17 |
+
"- **Section 2.b.a**: Hand landmarks (skeleton) + mesh\n",
|
| 18 |
+
"- **Section 2.c**: Object poses (requires assets folder, skipped automatically otherwise)\n",
|
| 19 |
+
"- **Section 3.b**: Hand 2D bounding boxes\n",
|
| 20 |
+
"- **Section 4**: Eye gaze (Aria only, skipped automatically on Quest3)\n",
|
| 21 |
+
"- **Section 5**: Hand keypoint reprojection onto image\n",
|
| 22 |
+
"\n",
|
| 23 |
+
"```\n",
|
| 24 |
+
"Hot3dDataProvider\n",
|
| 25 |
+
"|- device_data_provider -> image data + camera calibration\n",
|
| 26 |
+
"|- device_pose_data_provider -> device pose\n",
|
| 27 |
+
"|- mano_hand_data_provider -> hand pose (MANO)\n",
|
| 28 |
+
"|- object_pose_data_provider -> object pose\n",
|
| 29 |
+
"|- hand_box2d_data_provider -> hand 2D bounding boxes\n",
|
| 30 |
+
"|- object_box2d_data_provider -> object 2D bounding boxes\n",
|
| 31 |
+
"```\n",
|
| 32 |
+
"\n",
|
| 33 |
+
"> All pose data is in **world coordinates** (meters)."
|
| 34 |
+
]
|
| 35 |
+
},
|
| 36 |
+
{
|
| 37 |
+
"cell_type": "code",
|
| 38 |
+
"execution_count": null,
|
| 39 |
+
"id": "97bcb96c-4910-4a60-9a41-c3b34ee7ac7b",
|
| 40 |
+
"metadata": {},
|
| 41 |
+
"outputs": [],
|
| 42 |
+
"source": [
|
| 43 |
+
"# Section 0: DataProvider initialization\n",
|
| 44 |
+
"#\n",
|
| 45 |
+
"# Only the two paths below need to be updated; everything else adapts automatically\n",
|
| 46 |
+
"# to Aria or Quest3.\n",
|
| 47 |
+
"\n",
|
| 48 |
+
"import os\n",
|
| 49 |
+
"import sys\n",
|
| 50 |
+
"\n",
|
| 51 |
+
"# Make sure the hot3d package is importable from this notebook\n",
|
| 52 |
+
"notebook_dir = os.path.abspath('')\n",
|
| 53 |
+
"if notebook_dir not in sys.path:\n",
|
| 54 |
+
" sys.path.insert(0, notebook_dir)\n",
|
| 55 |
+
"\n",
|
| 56 |
+
"from dataset_api import Hot3dDataProvider\n",
|
| 57 |
+
"from data_loaders.mano_layer import MANOHandModel\n",
|
| 58 |
+
"from data_loaders.headsets import Headset\n",
|
| 59 |
+
"from projectaria_tools.core.stream_id import StreamId\n",
|
| 60 |
+
"\n",
|
| 61 |
+
"# ── Update these two paths ───────────────────────────────────────\n",
|
| 62 |
+
"sequence_path = \"/home/zhang/3D_Reconstruct/HOT3D/hot3d/hot3d/dataset/P0002_2f137f83\"\n",
|
| 63 |
+
"mano_model_path = \"/home/zhang/Downloads/mano_v1_2/models\"\n",
|
| 64 |
+
"# ────────────────────────────────────────────────────────────────\n",
|
| 65 |
+
"\n",
|
| 66 |
+
"# Load MANO hand model (requires smplx: pip install smplx)\n",
|
| 67 |
+
"mano_hand_model = MANOHandModel(mano_model_path)\n",
|
| 68 |
+
"\n",
|
| 69 |
+
"# Initialize the data provider.\n",
|
| 70 |
+
"# object_library=None: no assets folder needed when only reading hand data.\n",
|
| 71 |
+
"hot3d_data_provider = Hot3dDataProvider(\n",
|
| 72 |
+
" sequence_folder=sequence_path,\n",
|
| 73 |
+
" object_library=None,\n",
|
| 74 |
+
" mano_hand_model=mano_hand_model,\n",
|
| 75 |
+
")\n",
|
| 76 |
+
"\n",
|
| 77 |
+
"# Auto-detect device type and pick the corresponding primary camera stream_id\n",
|
| 78 |
+
"device_type = hot3d_data_provider.get_device_type()\n",
|
| 79 |
+
"print(f\"Device type: {device_type}\")\n",
|
| 80 |
+
"\n",
|
| 81 |
+
"if device_type == Headset.Aria:\n",
|
| 82 |
+
" main_stream_id = StreamId(\"214-1\") # Aria: RGB camera\n",
|
| 83 |
+
"else:\n",
|
| 84 |
+
" main_stream_id = StreamId(\"1201-1\") # Quest3: SLAM Left camera\n",
|
| 85 |
+
"\n",
|
| 86 |
+
"print(f\"Primary stream_id: {main_stream_id}\")\n",
|
| 87 |
+
"print(f\"Data statistics: {hot3d_data_provider.get_data_statistics()}\")"
|
| 88 |
+
]
|
| 89 |
+
},
|
| 90 |
+
{
|
| 91 |
+
"cell_type": "code",
|
| 92 |
+
"execution_count": null,
|
| 93 |
+
"id": "24dae021-1cfe-440a-a5c8-6f44851219e7",
|
| 94 |
+
"metadata": {},
|
| 95 |
+
"outputs": [],
|
| 96 |
+
"source": [
|
| 97 |
+
"# Utility functions for Rerun visualization\n",
|
| 98 |
+
"\n",
|
| 99 |
+
"import rerun as rr\n",
|
| 100 |
+
"import numpy as np\n",
|
| 101 |
+
"from projectaria_tools.core.sophus import SE3\n",
|
| 102 |
+
"from projectaria_tools.utils.rerun_helpers import ToTransform3D\n",
|
| 103 |
+
"\n",
|
| 104 |
+
"\n",
|
| 105 |
+
"def log_image(image: np.array, label: str, static=False) -> None:\n",
|
| 106 |
+
" rr.log(label, rr.Image(image), static=static)\n",
|
| 107 |
+
"\n",
|
| 108 |
+
"\n",
|
| 109 |
+
"def log_pose(pose: SE3, label: str, static=False) -> None:\n",
|
| 110 |
+
" rr.log(label, ToTransform3D(pose, False), static=static)"
|
| 111 |
+
]
|
| 112 |
+
},
|
| 113 |
+
{
|
| 114 |
+
"cell_type": "code",
|
| 115 |
+
"execution_count": null,
|
| 116 |
+
"id": "c7447d83-bf07-4bfb-8e4f-9d548617cde7",
|
| 117 |
+
"metadata": {},
|
| 118 |
+
"outputs": [],
|
| 119 |
+
"source": [
|
| 120 |
+
"# Section 1: Image streams + camera calibration\n",
|
| 121 |
+
"\n",
|
| 122 |
+
"from tqdm import tqdm\n",
|
| 123 |
+
"from projectaria_tools.core.sensor_data import TimeDomain, TimeQueryOptions\n",
|
| 124 |
+
"\n",
|
| 125 |
+
"device_data_provider = hot3d_data_provider.device_data_provider\n",
|
| 126 |
+
"image_stream_ids = device_data_provider.get_image_stream_ids()\n",
|
| 127 |
+
"\n",
|
| 128 |
+
"# Timestamp retrieval differs between Aria and Quest3\n",
|
| 129 |
+
"if device_type == Headset.Aria:\n",
|
| 130 |
+
" timestamps = device_data_provider.get_sequence_timestamps(\n",
|
| 131 |
+
" stream_id=main_stream_id,\n",
|
| 132 |
+
" time_domain=TimeDomain.TIME_CODE,\n",
|
| 133 |
+
" )\n",
|
| 134 |
+
"else:\n",
|
| 135 |
+
" timestamps = device_data_provider.get_sequence_timestamps()\n",
|
| 136 |
+
"\n",
|
| 137 |
+
"print(f\"Sequence : {os.path.basename(os.path.normpath(sequence_path))}\")\n",
|
| 138 |
+
"print(f\"Streams : {image_stream_ids}\")\n",
|
| 139 |
+
"print(f\"Frames : {len(timestamps)}\")\n",
|
| 140 |
+
"\n",
|
| 141 |
+
"rr.init(\"Device images\")\n",
|
| 142 |
+
"rec = rr.memory_recording()\n",
|
| 143 |
+
"\n",
|
| 144 |
+
"# Sample one frame every 200 timestamps to keep the visualization fast\n",
|
| 145 |
+
"for timestamp_ns in tqdm(timestamps[::200]):\n",
|
| 146 |
+
" for stream_id in image_stream_ids:\n",
|
| 147 |
+
" image_stream_label = device_data_provider.get_image_stream_label(stream_id)\n",
|
| 148 |
+
" image_data = device_data_provider.get_image(timestamp_ns, stream_id)\n",
|
| 149 |
+
" if image_data is not None:\n",
|
| 150 |
+
" log_image(label=f\"img/{image_stream_label}\", image=image_data)\n",
|
| 151 |
+
"\n",
|
| 152 |
+
"# Print calibration parameters for each camera stream\n",
|
| 153 |
+
"for stream_id in image_stream_ids:\n",
|
| 154 |
+
" [extrinsics, intrinsics] = device_data_provider.get_camera_calibration(stream_id)\n",
|
| 155 |
+
" label = device_data_provider.get_image_stream_label(stream_id)\n",
|
| 156 |
+
" print(f\"\\n[{label}] intrinsics: {intrinsics}\")\n",
|
| 157 |
+
"\n",
|
| 158 |
+
"rr.notebook_show()"
|
| 159 |
+
]
|
| 160 |
+
},
|
| 161 |
+
{
|
| 162 |
+
"cell_type": "markdown",
|
| 163 |
+
"id": "1d199e9c-7359-43b2-8ecd-807db548def0",
|
| 164 |
+
"metadata": {},
|
| 165 |
+
"source": [
|
| 166 |
+
"# GT Data Provider API\n",
|
| 167 |
+
"\n",
|
| 168 |
+
"All GT data providers share the same query interface:\n",
|
| 169 |
+
"```python\n",
|
| 170 |
+
"result = provider.get_X_at_timestamp(\n",
|
| 171 |
+
" timestamp_ns=timestamp_ns,\n",
|
| 172 |
+
" time_query_options=TimeQueryOptions.CLOSEST,\n",
|
| 173 |
+
" time_domain=TimeDomain.TIME_CODE,\n",
|
| 174 |
+
")\n",
|
| 175 |
+
"```\n",
|
| 176 |
+
"- If the exact timestamp is not found, the **closest** sample is returned.\n",
|
| 177 |
+
"- The delta time (`dt`) between the queried and returned timestamp is also available.\n",
|
| 178 |
+
"\n",
|
| 179 |
+
"Available providers:\n",
|
| 180 |
+
"```\n",
|
| 181 |
+
"|- device_pose_data_provider -> device/headset pose\n",
|
| 182 |
+
"|- mano_hand_data_provider -> hand pose (MANO)\n",
|
| 183 |
+
"|- object_pose_data_provider -> object pose\n",
|
| 184 |
+
"|- hand_box2d_data_provider -> hand 2D bbox + visibility\n",
|
| 185 |
+
"|- object_box2d_data_provider -> object 2D bbox + visibility\n",
|
| 186 |
+
"```"
|
| 187 |
+
]
|
| 188 |
+
},
|
| 189 |
+
{
|
| 190 |
+
"cell_type": "code",
|
| 191 |
+
"execution_count": null,
|
| 192 |
+
"id": "a7c473c3-174f-4cff-9d58-0650b580da72",
|
| 193 |
+
"metadata": {},
|
| 194 |
+
"outputs": [],
|
| 195 |
+
"source": [
|
| 196 |
+
"# Section 2.a: Device / headset pose trajectory\n",
|
| 197 |
+
"\n",
|
| 198 |
+
"device_pose_provider = hot3d_data_provider.device_pose_data_provider\n",
|
| 199 |
+
"\n",
|
| 200 |
+
"rr.init(\"Device/Headset trajectory\")\n",
|
| 201 |
+
"rec = rr.memory_recording()\n",
|
| 202 |
+
"\n",
|
| 203 |
+
"pose_translations = []\n",
|
| 204 |
+
"for timestamp_ns in tqdm(timestamps):\n",
|
| 205 |
+
" rr.set_time_nanos(\"synchronization_time\", int(timestamp_ns))\n",
|
| 206 |
+
" rr.set_time_sequence(\"timestamp\", timestamp_ns)\n",
|
| 207 |
+
"\n",
|
| 208 |
+
" if device_pose_provider is None:\n",
|
| 209 |
+
" continue\n",
|
| 210 |
+
" result = device_pose_provider.get_pose_at_timestamp(\n",
|
| 211 |
+
" timestamp_ns=timestamp_ns,\n",
|
| 212 |
+
" time_query_options=TimeQueryOptions.CLOSEST,\n",
|
| 213 |
+
" time_domain=TimeDomain.TIME_CODE,\n",
|
| 214 |
+
" )\n",
|
| 215 |
+
" if result is None:\n",
|
| 216 |
+
" continue\n",
|
| 217 |
+
"\n",
|
| 218 |
+
" T_world_device = result.pose3d.T_world_device\n",
|
| 219 |
+
" log_pose(pose=T_world_device, label=\"world/device\")\n",
|
| 220 |
+
" pose_translations.append(T_world_device.translation()[0])\n",
|
| 221 |
+
"\n",
|
| 222 |
+
"rr.log(\"world/device_trajectory\", rr.LineStrips3D([pose_translations]), static=True)\n",
|
| 223 |
+
"rr.notebook_show()"
|
| 224 |
+
]
|
| 225 |
+
},
|
| 226 |
+
{
|
| 227 |
+
"cell_type": "code",
|
| 228 |
+
"execution_count": null,
|
| 229 |
+
"id": "d5253618-2ca2-4d11-a605-aa5aa19c54eb",
|
| 230 |
+
"metadata": {},
|
| 231 |
+
"outputs": [],
|
| 232 |
+
"source": [
|
| 233 |
+
"# Section 2.b: Hand wrist trajectory (MANO only)\n",
|
| 234 |
+
"\n",
|
| 235 |
+
"hand_data_provider = hot3d_data_provider.mano_hand_data_provider\n",
|
| 236 |
+
"if hand_data_provider is None:\n",
|
| 237 |
+
" print(\"MANO hand data provider not initialized. Check mano_model_path and smplx installation.\")\n",
|
| 238 |
+
"\n",
|
| 239 |
+
"rr.init(\"Hand wrist trajectory\")\n",
|
| 240 |
+
"rec = rr.memory_recording()\n",
|
| 241 |
+
"\n",
|
| 242 |
+
"left_traj, right_traj = [], []\n",
|
| 243 |
+
"for timestamp_ns in tqdm(timestamps):\n",
|
| 244 |
+
" rr.set_time_nanos(\"synchronization_time\", int(timestamp_ns))\n",
|
| 245 |
+
" rr.set_time_sequence(\"timestamp\", timestamp_ns)\n",
|
| 246 |
+
"\n",
|
| 247 |
+
" if hand_data_provider is None:\n",
|
| 248 |
+
" continue\n",
|
| 249 |
+
" result = hand_data_provider.get_pose_at_timestamp(\n",
|
| 250 |
+
" timestamp_ns=timestamp_ns,\n",
|
| 251 |
+
" time_query_options=TimeQueryOptions.CLOSEST,\n",
|
| 252 |
+
" time_domain=TimeDomain.TIME_CODE,\n",
|
| 253 |
+
" )\n",
|
| 254 |
+
" if result is None:\n",
|
| 255 |
+
" continue\n",
|
| 256 |
+
"\n",
|
| 257 |
+
" for hand_pose in result.pose3d_collection.poses.values():\n",
|
| 258 |
+
" label = hand_pose.handedness_label()\n",
|
| 259 |
+
" T_world_wrist = hand_pose.wrist_pose\n",
|
| 260 |
+
" log_pose(pose=T_world_wrist, label=f\"world/hand/{label}\")\n",
|
| 261 |
+
" if hand_pose.is_left_hand():\n",
|
| 262 |
+
" left_traj.append(T_world_wrist.translation()[0])\n",
|
| 263 |
+
" else:\n",
|
| 264 |
+
" right_traj.append(T_world_wrist.translation()[0])\n",
|
| 265 |
+
"\n",
|
| 266 |
+
"if left_traj:\n",
|
| 267 |
+
" rr.log(\"world/left_hand_traj\", rr.LineStrips3D([left_traj]), static=True)\n",
|
| 268 |
+
"if right_traj:\n",
|
| 269 |
+
" rr.log(\"world/right_hand_traj\", rr.LineStrips3D([right_traj]), static=True)\n",
|
| 270 |
+
"rr.notebook_show()"
|
| 271 |
+
]
|
| 272 |
+
},
|
| 273 |
+
{
|
| 274 |
+
"cell_type": "code",
|
| 275 |
+
"execution_count": null,
|
| 276 |
+
"id": "0a013c63-65e6-4c38-b378-141c8c7ae3ae",
|
| 277 |
+
"metadata": {},
|
| 278 |
+
"outputs": [],
|
| 279 |
+
"source": [
|
| 280 |
+
"# Section 2.b.a: Hand landmarks (skeleton) and mesh\n",
|
| 281 |
+
"#\n",
|
| 282 |
+
"# Left hand -> landmark line strips (skeleton)\n",
|
| 283 |
+
"# Right hand -> triangular mesh\n",
|
| 284 |
+
"\n",
|
| 285 |
+
"from data_loaders.hand_common import LANDMARK_CONNECTIVITY\n",
|
| 286 |
+
"\n",
|
| 287 |
+
"hand_data_provider = hot3d_data_provider.mano_hand_data_provider\n",
|
| 288 |
+
"\n",
|
| 289 |
+
"rr.init(\"Hand Landmark / Mesh\")\n",
|
| 290 |
+
"rec = rr.memory_recording()\n",
|
| 291 |
+
"\n",
|
| 292 |
+
"for timestamp_ns in tqdm(timestamps[:300]):\n",
|
| 293 |
+
" rr.set_time_nanos(\"synchronization_time\", int(timestamp_ns))\n",
|
| 294 |
+
" rr.set_time_sequence(\"timestamp\", timestamp_ns)\n",
|
| 295 |
+
"\n",
|
| 296 |
+
" if hand_data_provider is None:\n",
|
| 297 |
+
" continue\n",
|
| 298 |
+
" result = hand_data_provider.get_pose_at_timestamp(\n",
|
| 299 |
+
" timestamp_ns=timestamp_ns,\n",
|
| 300 |
+
" time_query_options=TimeQueryOptions.CLOSEST,\n",
|
| 301 |
+
" time_domain=TimeDomain.TIME_CODE,\n",
|
| 302 |
+
" )\n",
|
| 303 |
+
" if result is None:\n",
|
| 304 |
+
" continue\n",
|
| 305 |
+
"\n",
|
| 306 |
+
" for hand_pose in result.pose3d_collection.poses.values():\n",
|
| 307 |
+
" label = hand_pose.handedness_label()\n",
|
| 308 |
+
"\n",
|
| 309 |
+
" if hand_pose.is_left_hand():\n",
|
| 310 |
+
" # Skeleton: connected landmark line strips\n",
|
| 311 |
+
" landmarks = hand_data_provider.get_hand_landmarks(hand_pose)\n",
|
| 312 |
+
" points = [\n",
|
| 313 |
+
" [landmarks[i].numpy().tolist() for i in conn]\n",
|
| 314 |
+
" for conn in LANDMARK_CONNECTIVITY\n",
|
| 315 |
+
" ]\n",
|
| 316 |
+
" rr.log(f\"world/{label}/joints\", rr.LineStrips3D(points, radii=0.002))\n",
|
| 317 |
+
"\n",
|
| 318 |
+
" else:\n",
|
| 319 |
+
" # Mesh: vertices, triangle indices, and vertex normals\n",
|
| 320 |
+
" verts = hand_data_provider.get_hand_mesh_vertices(hand_pose)\n",
|
| 321 |
+
" triangles, normals = hand_data_provider.get_hand_mesh_faces_and_normals(hand_pose)\n",
|
| 322 |
+
" rr.log(\n",
|
| 323 |
+
" f\"world/{label}/mesh\",\n",
|
| 324 |
+
" rr.Mesh3D(\n",
|
| 325 |
+
" vertex_positions=verts,\n",
|
| 326 |
+
" vertex_normals=normals,\n",
|
| 327 |
+
" triangle_indices=triangles,\n",
|
| 328 |
+
" ),\n",
|
| 329 |
+
" )\n",
|
| 330 |
+
"\n",
|
| 331 |
+
"rr.notebook_show()"
|
| 332 |
+
]
|
| 333 |
+
},
|
| 334 |
+
{
|
| 335 |
+
"cell_type": "code",
|
| 336 |
+
"execution_count": null,
|
| 337 |
+
"id": "a909427f-d8c5-40a7-8eba-8702de2a313b",
|
| 338 |
+
"metadata": {},
|
| 339 |
+
"outputs": [],
|
| 340 |
+
"source": [
|
| 341 |
+
"# Section 2.c: Object poses\n",
|
| 342 |
+
"# Requires object_library (assets folder). Skipped automatically if not available.\n",
|
| 343 |
+
"\n",
|
| 344 |
+
"if hot3d_data_provider._object_library is None:\n",
|
| 345 |
+
" print(\"Skipping Section 2.c: object_library=None (no assets folder loaded)\")\n",
|
| 346 |
+
"else:\n",
|
| 347 |
+
" from data_loaders.loader_object_library import ObjectLibrary\n",
|
| 348 |
+
" object_library = hot3d_data_provider._object_library\n",
|
| 349 |
+
" object_pose_data_provider = hot3d_data_provider.object_pose_data_provider\n",
|
| 350 |
+
" object_cache_status = {}\n",
|
| 351 |
+
"\n",
|
| 352 |
+
" rr.init(\"Object pose\")\n",
|
| 353 |
+
" rec = rr.memory_recording()\n",
|
| 354 |
+
"\n",
|
| 355 |
+
" for timestamp_ns in tqdm(timestamps[100:300]):\n",
|
| 356 |
+
" rr.set_time_nanos(\"synchronization_time\", int(timestamp_ns))\n",
|
| 357 |
+
" rr.set_time_sequence(\"timestamp\", timestamp_ns)\n",
|
| 358 |
+
"\n",
|
| 359 |
+
" result = object_pose_data_provider.get_pose_at_timestamp(\n",
|
| 360 |
+
" timestamp_ns=timestamp_ns,\n",
|
| 361 |
+
" time_query_options=TimeQueryOptions.CLOSEST,\n",
|
| 362 |
+
" time_domain=TimeDomain.TIME_CODE,\n",
|
| 363 |
+
" )\n",
|
| 364 |
+
" if result is None:\n",
|
| 365 |
+
" continue\n",
|
| 366 |
+
"\n",
|
| 367 |
+
" object_uids = object_pose_data_provider.object_uids_with_poses\n",
|
| 368 |
+
" logging_status = {x: False for x in object_uids}\n",
|
| 369 |
+
"\n",
|
| 370 |
+
" for object_uid, object_pose3d in result.pose3d_collection.poses.items():\n",
|
| 371 |
+
" object_name = object_library.object_id_to_name_dict[object_uid] + \"_\" + str(object_uid)\n",
|
| 372 |
+
" log_pose(pose=object_pose3d.T_world_object, label=f\"world/objects/{object_name}\")\n",
|
| 373 |
+
" logging_status[object_uid] = True\n",
|
| 374 |
+
" if object_uid not in object_cache_status:\n",
|
| 375 |
+
" object_cache_status[object_uid] = True\n",
|
| 376 |
+
" asset_path = ObjectLibrary.get_cad_asset_path(\n",
|
| 377 |
+
" object_library_folderpath=object_library.asset_folder_name,\n",
|
| 378 |
+
" object_id=object_uid,\n",
|
| 379 |
+
" )\n",
|
| 380 |
+
" rr.log(f\"world/objects/{object_name}\", rr.Asset3D(path=asset_path))\n",
|
| 381 |
+
"\n",
|
| 382 |
+
" for object_uid, displayed in logging_status.items():\n",
|
| 383 |
+
" if not displayed:\n",
|
| 384 |
+
" object_name = object_library.object_id_to_name_dict[object_uid] + \"_\" + str(object_uid)\n",
|
| 385 |
+
" rr.log(f\"world/objects/{object_name}\", rr.Clear.recursive())\n",
|
| 386 |
+
" object_cache_status.pop(object_uid, None)\n",
|
| 387 |
+
"\n",
|
| 388 |
+
" rr.notebook_show()"
|
| 389 |
+
]
|
| 390 |
+
},
|
| 391 |
+
{
|
| 392 |
+
"cell_type": "code",
|
| 393 |
+
"execution_count": null,
|
| 394 |
+
"id": "f31214ce-108e-403e-b66f-2c224ab450f1",
|
| 395 |
+
"metadata": {},
|
| 396 |
+
"outputs": [],
|
| 397 |
+
"source": [
|
| 398 |
+
"# Section 3: 2D Bounding Boxes\n",
|
| 399 |
+
"# Bbox data is queried by TIMESTAMP + STREAM_ID and contains an amodal bbox and a visibility ratio."
|
| 400 |
+
]
|
| 401 |
+
},
|
| 402 |
+
{
|
| 403 |
+
"cell_type": "code",
|
| 404 |
+
"execution_count": null,
|
| 405 |
+
"id": "b841145d-a114-4693-a0d4-492f9629bbbe",
|
| 406 |
+
"metadata": {},
|
| 407 |
+
"outputs": [],
|
| 408 |
+
"source": [
|
| 409 |
+
"# Section 3.a: Object 2D bounding boxes\n",
|
| 410 |
+
"# Requires object_library. Skipped automatically if not available.\n",
|
| 411 |
+
"\n",
|
| 412 |
+
"if hot3d_data_provider._object_library is None:\n",
|
| 413 |
+
" print(\"Skipping Section 3.a: object_library=None\")\n",
|
| 414 |
+
"else:\n",
|
| 415 |
+
" import matplotlib.pyplot as plt\n",
|
| 416 |
+
" object_library = hot3d_data_provider._object_library\n",
|
| 417 |
+
" object_box2d_data_provider = hot3d_data_provider.object_box2d_data_provider\n",
|
| 418 |
+
" object_uids = list(object_box2d_data_provider.object_uids)\n",
|
| 419 |
+
" color_map = plt.get_cmap(\"viridis\")\n",
|
| 420 |
+
" object_box2d_colors = color_map(np.linspace(0, 1, len(object_uids)))\n",
|
| 421 |
+
"\n",
|
| 422 |
+
" rr.init(\"Object bounding boxes\")\n",
|
| 423 |
+
" rec = rr.memory_recording()\n",
|
| 424 |
+
"\n",
|
| 425 |
+
" stream_id = main_stream_id\n",
|
| 426 |
+
" for timestamp_ns in tqdm(timestamps[100:200]):\n",
|
| 427 |
+
" rr.set_time_nanos(\"synchronization_time\", int(timestamp_ns))\n",
|
| 428 |
+
" rr.set_time_sequence(\"timestamp\", timestamp_ns)\n",
|
| 429 |
+
"\n",
|
| 430 |
+
" result = object_box2d_data_provider.get_bbox_at_timestamp(\n",
|
| 431 |
+
" stream_id=stream_id,\n",
|
| 432 |
+
" timestamp_ns=timestamp_ns,\n",
|
| 433 |
+
" time_query_options=TimeQueryOptions.CLOSEST,\n",
|
| 434 |
+
" time_domain=TimeDomain.TIME_CODE,\n",
|
| 435 |
+
" )\n",
|
| 436 |
+
" if result is None or result.box2d_collection is None:\n",
|
| 437 |
+
" continue\n",
|
| 438 |
+
"\n",
|
| 439 |
+
" for object_uid in result.box2d_collection.object_uid_list:\n",
|
| 440 |
+
" object_name = object_library.object_id_to_name_dict[object_uid]\n",
|
| 441 |
+
" ab = result.box2d_collection.box2ds[object_uid]\n",
|
| 442 |
+
" bbox = ab.box2d\n",
|
| 443 |
+
" if bbox is None:\n",
|
| 444 |
+
" continue\n",
|
| 445 |
+
" rr.log(\n",
|
| 446 |
+
" f\"{stream_id}_raw/bbox/{object_name}\",\n",
|
| 447 |
+
" rr.Boxes2D(mins=[bbox.left, bbox.top], sizes=[bbox.width, bbox.height],\n",
|
| 448 |
+
" colors=object_box2d_colors[object_uids.index(object_uid)]),\n",
|
| 449 |
+
" )\n",
|
| 450 |
+
" rr.log(f\"visibility/{object_name}\", rr.Scalar(ab.visibility_ratio))\n",
|
| 451 |
+
" image_data = device_data_provider.get_image(timestamp_ns, stream_id)\n",
|
| 452 |
+
" if image_data is not None:\n",
|
| 453 |
+
" log_image(label=f\"{stream_id}_raw\", image=image_data)\n",
|
| 454 |
+
"\n",
|
| 455 |
+
" rr.notebook_show()"
|
| 456 |
+
]
|
| 457 |
+
},
|
| 458 |
+
{
|
| 459 |
+
"cell_type": "code",
|
| 460 |
+
"execution_count": null,
|
| 461 |
+
"id": "0d1daf98-2df6-4d0a-ae38-331060353b99",
|
| 462 |
+
"metadata": {},
|
| 463 |
+
"outputs": [],
|
| 464 |
+
"source": [
|
| 465 |
+
"# Section 3.b: Hand 2D bounding boxes\n",
|
| 466 |
+
"\n",
|
| 467 |
+
"import matplotlib.pyplot as plt\n",
|
| 468 |
+
"from data_loaders.loader_hand_poses import LEFT_HAND_INDEX, RIGHT_HAND_INDEX\n",
|
| 469 |
+
"\n",
|
| 470 |
+
"hand_box2d_data_provider = hot3d_data_provider.hand_box2d_data_provider\n",
|
| 471 |
+
"hand_uids = [LEFT_HAND_INDEX, RIGHT_HAND_INDEX]\n",
|
| 472 |
+
"hand_names = {LEFT_HAND_INDEX: \"left\", RIGHT_HAND_INDEX: \"right\"}\n",
|
| 473 |
+
"color_map = plt.get_cmap(\"viridis\")\n",
|
| 474 |
+
"hand_box2d_colors = color_map(np.linspace(0, 1, 2))\n",
|
| 475 |
+
"\n",
|
| 476 |
+
"rr.init(\"Hand bounding boxes\")\n",
|
| 477 |
+
"rec = rr.memory_recording()\n",
|
| 478 |
+
"\n",
|
| 479 |
+
"stream_id = main_stream_id\n",
|
| 480 |
+
"if stream_id not in hand_box2d_data_provider.stream_ids:\n",
|
| 481 |
+
" print(f\"stream_id {stream_id} has no hand bbox data. Available: {hand_box2d_data_provider.stream_ids}\")\n",
|
| 482 |
+
"\n",
|
| 483 |
+
"for timestamp_ns in tqdm(timestamps[100:200]):\n",
|
| 484 |
+
" rr.set_time_nanos(\"synchronization_time\", int(timestamp_ns))\n",
|
| 485 |
+
" rr.set_time_sequence(\"timestamp\", timestamp_ns)\n",
|
| 486 |
+
"\n",
|
| 487 |
+
" result = hand_box2d_data_provider.get_bbox_at_timestamp(\n",
|
| 488 |
+
" stream_id=stream_id,\n",
|
| 489 |
+
" timestamp_ns=timestamp_ns,\n",
|
| 490 |
+
" time_query_options=TimeQueryOptions.CLOSEST,\n",
|
| 491 |
+
" time_domain=TimeDomain.TIME_CODE,\n",
|
| 492 |
+
" )\n",
|
| 493 |
+
" if result is None or result.box2d_collection is None:\n",
|
| 494 |
+
" continue\n",
|
| 495 |
+
"\n",
|
| 496 |
+
" for i, hand_uid in enumerate(hand_uids):\n",
|
| 497 |
+
" ab = result.box2d_collection.box2ds[hand_uid]\n",
|
| 498 |
+
" bbox = ab.box2d\n",
|
| 499 |
+
" if bbox is None:\n",
|
| 500 |
+
" continue\n",
|
| 501 |
+
" hand_name = hand_names[hand_uid]\n",
|
| 502 |
+
" rr.log(\n",
|
| 503 |
+
" f\"{stream_id}_raw/bbox/{hand_name}\",\n",
|
| 504 |
+
" rr.Boxes2D(mins=[bbox.left, bbox.top], sizes=[bbox.width, bbox.height],\n",
|
| 505 |
+
" colors=hand_box2d_colors[i]),\n",
|
| 506 |
+
" )\n",
|
| 507 |
+
" rr.log(f\"visibility/{hand_name}\", rr.Scalar(ab.visibility_ratio))\n",
|
| 508 |
+
" image_data = device_data_provider.get_image(timestamp_ns, stream_id)\n",
|
| 509 |
+
" if image_data is not None:\n",
|
| 510 |
+
" log_image(label=f\"{stream_id}_raw\", image=image_data)\n",
|
| 511 |
+
"\n",
|
| 512 |
+
"rr.notebook_show()"
|
| 513 |
+
]
|
| 514 |
+
},
|
| 515 |
+
{
|
| 516 |
+
"cell_type": "code",
|
| 517 |
+
"execution_count": null,
|
| 518 |
+
"id": "d8bad34e-a8ab-437d-84ff-1c046ca35d51",
|
| 519 |
+
"metadata": {},
|
| 520 |
+
"outputs": [],
|
| 521 |
+
"source": [
|
| 522 |
+
"# Section 4: Eye gaze (Aria only, skipped automatically on Quest3)\n",
|
| 523 |
+
"\n",
|
| 524 |
+
"if device_type != Headset.Aria:\n",
|
| 525 |
+
" print(f\"Skipping Section 4: eye gaze is Aria-only (current device: {device_type})\")\n",
|
| 526 |
+
"else:\n",
|
| 527 |
+
" from projectaria_tools.core.calibration import FISHEYE624\n",
|
| 528 |
+
"\n",
|
| 529 |
+
" rr.init(\"Eye Gaze reprojection\")\n",
|
| 530 |
+
" rec = rr.memory_recording()\n",
|
| 531 |
+
"\n",
|
| 532 |
+
" stream_id = StreamId(\"214-1\")\n",
|
| 533 |
+
" for timestamp_ns in tqdm(timestamps[100:120]):\n",
|
| 534 |
+
" rr.set_time_nanos(\"synchronization_time\", int(timestamp_ns))\n",
|
| 535 |
+
" rr.set_time_sequence(\"timestamp\", timestamp_ns)\n",
|
| 536 |
+
"\n",
|
| 537 |
+
" eye_gaze = device_data_provider.get_eye_gaze(timestamp_ns)\n",
|
| 538 |
+
" if eye_gaze is None:\n",
|
| 539 |
+
" continue\n",
|
| 540 |
+
"\n",
|
| 541 |
+
" proj = device_data_provider.get_eye_gaze_in_camera(\n",
|
| 542 |
+
" stream_id, timestamp_ns, camera_model=FISHEYE624\n",
|
| 543 |
+
" )\n",
|
| 544 |
+
" if proj is None or not proj.any():\n",
|
| 545 |
+
" continue\n",
|
| 546 |
+
"\n",
|
| 547 |
+
" rr.log(f\"{stream_id}/eye-gaze\", rr.Points2D(proj, radii=20))\n",
|
| 548 |
+
" image_data = device_data_provider.get_image(timestamp_ns, stream_id)\n",
|
| 549 |
+
" if image_data is not None:\n",
|
| 550 |
+
" log_image(label=str(stream_id), image=image_data)\n",
|
| 551 |
+
"\n",
|
| 552 |
+
" rr.notebook_show()"
|
| 553 |
+
]
|
| 554 |
+
},
|
| 555 |
+
{
|
| 556 |
+
"cell_type": "code",
|
| 557 |
+
"execution_count": null,
|
| 558 |
+
"id": "b4d6ac37-e3b3-401a-83b7-e09a42a183a3",
|
| 559 |
+
"metadata": {},
|
| 560 |
+
"outputs": [],
|
| 561 |
+
"source": [
|
| 562 |
+
"# Section 5: Hand keypoint reprojection onto image\n",
|
| 563 |
+
"#\n",
|
| 564 |
+
"# Projects 3D world-space hand landmarks through the camera extrinsics + intrinsics\n",
|
| 565 |
+
"# to obtain 2D pixel coordinates, then overlays them on the image.\n",
|
| 566 |
+
"\n",
|
| 567 |
+
"%matplotlib inline\n",
|
| 568 |
+
"from matplotlib import pyplot as plt\n",
|
| 569 |
+
"from typing import Any, Optional\n",
|
| 570 |
+
"from data_loaders.HeadsetPose3dProvider import HeadsetPose3dProvider\n",
|
| 571 |
+
"from data_loaders.loader_hand_poses import Handedness, HandPose3dCollection\n",
|
| 572 |
+
"from projectaria_tools.core.calibration import CameraCalibration\n",
|
| 573 |
+
"from projectaria_tools.core.sophus import SE3\n",
|
| 574 |
+
"\n",
|
| 575 |
+
"# Use a mid-sequence frame; clamp so the index is always valid\n",
|
| 576 |
+
"frame_idx = min(420, len(timestamps) - 1)\n",
|
| 577 |
+
"timestamp_ns = timestamps[frame_idx]\n",
|
| 578 |
+
"image_streamid = main_stream_id # Aria -> 214-1, Quest3 -> 1201-1\n",
|
| 579 |
+
"\n",
|
| 580 |
+
"image_stream_label = device_data_provider.get_image_stream_label(image_streamid)\n",
|
| 581 |
+
"image_data = device_data_provider.get_image(timestamp_ns, image_streamid)\n",
|
| 582 |
+
"\n",
|
| 583 |
+
"\n",
|
| 584 |
+
"def get_hand_poses(ts):\n",
|
| 585 |
+
" if hand_data_provider is None:\n",
|
| 586 |
+
" return None\n",
|
| 587 |
+
" result = hand_data_provider.get_pose_at_timestamp(\n",
|
| 588 |
+
" timestamp_ns=ts,\n",
|
| 589 |
+
" time_query_options=TimeQueryOptions.CLOSEST,\n",
|
| 590 |
+
" time_domain=TimeDomain.TIME_CODE,\n",
|
| 591 |
+
" )\n",
|
| 592 |
+
" return result.pose3d_collection if result else None\n",
|
| 593 |
+
"\n",
|
| 594 |
+
"\n",
|
| 595 |
+
"def get_camera_pose(ts, stream_id):\n",
|
| 596 |
+
" \"\"\"Returns (T_world_camera, intrinsics) or None.\"\"\"\n",
|
| 597 |
+
" if device_pose_provider is None:\n",
|
| 598 |
+
" return None\n",
|
| 599 |
+
" result = device_pose_provider.get_pose_at_timestamp(\n",
|
| 600 |
+
" timestamp_ns=ts,\n",
|
| 601 |
+
" time_query_options=TimeQueryOptions.CLOSEST,\n",
|
| 602 |
+
" time_domain=TimeDomain.TIME_CODE,\n",
|
| 603 |
+
" )\n",
|
| 604 |
+
" if result is None:\n",
|
| 605 |
+
" return None\n",
|
| 606 |
+
" [T_device_camera, intrinsics] = device_data_provider.get_camera_calibration(stream_id)\n",
|
| 607 |
+
" T_world_camera = result.pose3d.T_world_device @ T_device_camera\n",
|
| 608 |
+
" return T_world_camera, intrinsics\n",
|
| 609 |
+
"\n",
|
| 610 |
+
"\n",
|
| 611 |
+
"hand_data = get_hand_poses(timestamp_ns)\n",
|
| 612 |
+
"camera_pose = get_camera_pose(timestamp_ns, image_streamid)\n",
|
| 613 |
+
"\n",
|
| 614 |
+
"if hand_data is None or camera_pose is None or image_data is None:\n",
|
| 615 |
+
" print(\"Missing hand data, camera pose, or image — cannot project.\")\n",
|
| 616 |
+
"else:\n",
|
| 617 |
+
" T_world_camera, intrinsics = camera_pose\n",
|
| 618 |
+
" plt.figure(figsize=(10, 8))\n",
|
| 619 |
+
" plt.imshow(image_data, interpolation=\"nearest\")\n",
|
| 620 |
+
" plt.title(f\"{image_stream_label} frame={frame_idx}\")\n",
|
| 621 |
+
"\n",
|
| 622 |
+
" for hand_pose in hand_data.poses.values():\n",
|
| 623 |
+
" label = hand_pose.handedness_label()\n",
|
| 624 |
+
" landmarks = hand_data_provider.get_hand_landmarks(hand_pose)\n",
|
| 625 |
+
"\n",
|
| 626 |
+
" # Gather all 3D points along the skeleton connectivity\n",
|
| 627 |
+
" all_pts_3d = [\n",
|
| 628 |
+
" landmarks[idx].numpy()\n",
|
| 629 |
+
" for conn in LANDMARK_CONNECTIVITY\n",
|
| 630 |
+
" for idx in conn\n",
|
| 631 |
+
" ]\n",
|
| 632 |
+
"\n",
|
| 633 |
+
" # Project each 3D world point into the camera image plane\n",
|
| 634 |
+
" projected = []\n",
|
| 635 |
+
" for pt_world in all_pts_3d:\n",
|
| 636 |
+
" pt_cam = T_world_camera.inverse() @ pt_world\n",
|
| 637 |
+
" pt_2d = intrinsics.project(pt_cam)\n",
|
| 638 |
+
" if pt_2d is not None:\n",
|
| 639 |
+
" projected.append(pt_2d)\n",
|
| 640 |
+
"\n",
|
| 641 |
+
" color = 'r' if hand_pose.handedness == Handedness.Right else 'b'\n",
|
| 642 |
+
" print(f\"{label} hand: {len(projected)} keypoints visible in image\")\n",
|
| 643 |
+
" if projected:\n",
|
| 644 |
+
" plt.scatter([p[0] for p in projected], [p[1] for p in projected],\n",
|
| 645 |
+
" s=3, c=color, label=label)\n",
|
| 646 |
+
"\n",
|
| 647 |
+
" plt.legend()\n",
|
| 648 |
+
" plt.axis('off')\n",
|
| 649 |
+
" plt.tight_layout()\n",
|
| 650 |
+
" plt.show()"
|
| 651 |
+
]
|
| 652 |
+
}
|
| 653 |
+
],
|
| 654 |
+
"metadata": {
|
| 655 |
+
"kernelspec": {
|
| 656 |
+
"display_name": "Python 3 (ipykernel)",
|
| 657 |
+
"language": "python",
|
| 658 |
+
"name": "python3"
|
| 659 |
+
},
|
| 660 |
+
"language_info": {
|
| 661 |
+
"codemirror_mode": {
|
| 662 |
+
"name": "ipython",
|
| 663 |
+
"version": 3
|
| 664 |
+
},
|
| 665 |
+
"file_extension": ".py",
|
| 666 |
+
"mimetype": "text/x-python",
|
| 667 |
+
"name": "python",
|
| 668 |
+
"nbconvert_exporter": "python",
|
| 669 |
+
"pygments_lexer": "ipython3",
|
| 670 |
+
"version": "3.10.0"
|
| 671 |
+
}
|
| 672 |
+
},
|
| 673 |
+
"nbformat": 4,
|
| 674 |
+
"nbformat_minor": 5
|
| 675 |
+
}
|
HOT3DHUGGFACE/HOT3D_Tutorial.ipynb
ADDED
|
@@ -0,0 +1,1045 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "markdown",
|
| 5 |
+
"id": "ee215408-e60b-4209-a09a-f84a8fd5ffa1",
|
| 6 |
+
"metadata": {},
|
| 7 |
+
"source": [
|
| 8 |
+
"\n",
|
| 9 |
+
"# Hot3D Data Provider Tutorial\n",
|
| 10 |
+
"\n",
|
| 11 |
+
"In order to use sequences from the HOT3D dataset, you will need ot use the Hot3dDataProvider object.\n",
|
| 12 |
+
"\n",
|
| 13 |
+
"This notebook is explaining how to use the various \"DataProvider\" in order to retrieve:\n",
|
| 14 |
+
"- Section 0: DataProvider initialization\n",
|
| 15 |
+
"- Section 1: Device calibration and Image data\n",
|
| 16 |
+
"- Section 2: Pose data\n",
|
| 17 |
+
" - Section 2.a: Device/Headset pose data\n",
|
| 18 |
+
" - Section 2.b: Hand pose data\n",
|
| 19 |
+
" - Section 2.b.a: Hand pose data and MESH hands\n",
|
| 20 |
+
" - Section 2.c: Object pose data\n",
|
| 21 |
+
"- Section 3:\n",
|
| 22 |
+
" - Section 3.a: Object bounding boxes (amodal bounding boxes)\n",
|
| 23 |
+
" - Section 3.b: Hand bounding boxes (amodal bounding boxes)\n",
|
| 24 |
+
"- Section 4: Eye Gaze data (only for Aria data)\n",
|
| 25 |
+
"- Section 5: Camera reprojection (reprojection hand vertices to raw fish images)\n",
|
| 26 |
+
"\n",
|
| 27 |
+
"Hot3dDataProvider API is organized as follow:\n",
|
| 28 |
+
"```\n",
|
| 29 |
+
"|- device_data_provider -> provides device calibration and image data\n",
|
| 30 |
+
"|- device_pose_data_provider -> provides device pose data\n",
|
| 31 |
+
"|- mano_hand_data_provider -> provides hand pose data (MANO representation)\n",
|
| 32 |
+
"|- umetrack_hand_data_provider -> provides hand pose data (UmeTrack representation)\n",
|
| 33 |
+
"|- object_pose_data_provider -> provides object pose data\n",
|
| 34 |
+
"|- object_library -> provides information about the HOT3D 3D objects/assets\n",
|
| 35 |
+
"|- hand_box2d_data_provider -> provides hands bbox information\n",
|
| 36 |
+
"|- object_box2d_data_provider -> provides objects bbox information\n",
|
| 37 |
+
"```\n",
|
| 38 |
+
"\n",
|
| 39 |
+
"## Notes\n",
|
| 40 |
+
"- All Device/Headset, Hand, Object poses data are shared in world coordinates (meters)\n",
|
| 41 |
+
"\n",
|
| 42 |
+
"In this tutorial you will learn that:\n",
|
| 43 |
+
"- Device data, such as Image data stream is indexed with a stream_id\n",
|
| 44 |
+
"- Headset use camera rig coordinates relative to the DEVICE pose (world_camera_stream_id = world_device @ device_camera_stream_id)"
|
| 45 |
+
]
|
| 46 |
+
},
|
| 47 |
+
{
|
| 48 |
+
"cell_type": "code",
|
| 49 |
+
"execution_count": null,
|
| 50 |
+
"id": "97bcb96c-4910-4a60-9a41-c3b34ee7ac7b",
|
| 51 |
+
"metadata": {},
|
| 52 |
+
"outputs": [],
|
| 53 |
+
"source": [
|
| 54 |
+
"#\n",
|
| 55 |
+
"# Section 0: DataProvider initialization\n",
|
| 56 |
+
"#\n",
|
| 57 |
+
"# Take home message:\n",
|
| 58 |
+
"# - Device data, such as Image data stream is indexed with a stream_id\n",
|
| 59 |
+
"# - Intrinsics and Extrinsics calibration relative to the device coordinates is available for each CAMERA/stream_id\n",
|
| 60 |
+
"#\n",
|
| 61 |
+
"# Data Requirements:\n",
|
| 62 |
+
"# - a sequence\n",
|
| 63 |
+
"# - the object library\n",
|
| 64 |
+
"# Optional:\n",
|
| 65 |
+
"# - To use the Mano hand you need to have the LEFT/RIGHT *.pkl hand models (available)\n",
|
| 66 |
+
"\n",
|
| 67 |
+
"import os\n",
|
| 68 |
+
"from dataset_api import Hot3dDataProvider\n",
|
| 69 |
+
"from data_loaders.loader_object_library import load_object_library\n",
|
| 70 |
+
"from data_loaders.mano_layer import MANOHandModel\n",
|
| 71 |
+
"\n",
|
| 72 |
+
"home = os.path.expanduser(\"~\")\n",
|
| 73 |
+
"hot3d_dataset_path = home + \"/Downloads/hot3d_dataset\"\n",
|
| 74 |
+
"sequence_path = os.path.join(hot3d_dataset_path, \"P0003_c701bd11\")\n",
|
| 75 |
+
"object_library_path = os.path.join(hot3d_dataset_path, \"assets\")\n",
|
| 76 |
+
"mano_hand_model_path = os.path.join(home, \"Downloads\")\n",
|
| 77 |
+
"\n",
|
| 78 |
+
"if not os.path.exists(sequence_path) or not os.path.exists(object_library_path):\n",
|
| 79 |
+
" print(\"Invalid input sequence or library path.\")\n",
|
| 80 |
+
" print(\"Please do update the path to VALID values for your system.\")\n",
|
| 81 |
+
" raise\n",
|
| 82 |
+
"#\n",
|
| 83 |
+
"# Init the object library\n",
|
| 84 |
+
"#\n",
|
| 85 |
+
"object_library = load_object_library(object_library_folderpath=object_library_path)\n",
|
| 86 |
+
"\n",
|
| 87 |
+
"#\n",
|
| 88 |
+
"# Init the HANDs model\n",
|
| 89 |
+
"# If None, the UmeTrack HANDs model will be used\n",
|
| 90 |
+
"#\n",
|
| 91 |
+
"mano_hand_model = None\n",
|
| 92 |
+
"if mano_hand_model_path is not None:\n",
|
| 93 |
+
" mano_hand_model = MANOHandModel(mano_hand_model_path)\n",
|
| 94 |
+
"\n",
|
| 95 |
+
"#\n",
|
| 96 |
+
"# Initialize hot3d data provider\n",
|
| 97 |
+
"#\n",
|
| 98 |
+
"hot3d_data_provider = Hot3dDataProvider(\n",
|
| 99 |
+
" sequence_folder=sequence_path,\n",
|
| 100 |
+
" object_library=object_library,\n",
|
| 101 |
+
" mano_hand_model=mano_hand_model,\n",
|
| 102 |
+
")\n",
|
| 103 |
+
"print(f\"data_provider statistics: {hot3d_data_provider.get_data_statistics()}\")"
|
| 104 |
+
]
|
| 105 |
+
},
|
| 106 |
+
{
|
| 107 |
+
"cell_type": "code",
|
| 108 |
+
"execution_count": null,
|
| 109 |
+
"id": "24dae021-1cfe-440a-a5c8-6f44851219e7",
|
| 110 |
+
"metadata": {},
|
| 111 |
+
"outputs": [],
|
| 112 |
+
"source": [
|
| 113 |
+
"#\n",
|
| 114 |
+
"# Utility functions\n",
|
| 115 |
+
"# Used for interactive display in the following sections\n",
|
| 116 |
+
"#\n",
|
| 117 |
+
"import rerun as rr\n",
|
| 118 |
+
"import numpy as np\n",
|
| 119 |
+
"\n",
|
| 120 |
+
"from projectaria_tools.core.sophus import SE3\n",
|
| 121 |
+
"from projectaria_tools.utils.rerun_helpers import ToTransform3D\n",
|
| 122 |
+
"\n",
|
| 123 |
+
"\n",
|
| 124 |
+
"def log_image(\n",
|
| 125 |
+
" image: np.array,\n",
|
| 126 |
+
" label: str,\n",
|
| 127 |
+
" static=False\n",
|
| 128 |
+
") -> None:\n",
|
| 129 |
+
" rr.log(label, rr.Image(image), static=static)\n",
|
| 130 |
+
"\n",
|
| 131 |
+
"\n",
|
| 132 |
+
"def log_pose(\n",
|
| 133 |
+
" pose: SE3,\n",
|
| 134 |
+
" label: str,\n",
|
| 135 |
+
" static=False\n",
|
| 136 |
+
") -> None:\n",
|
| 137 |
+
" rr.log(label, ToTransform3D(pose, False), static=static)"
|
| 138 |
+
]
|
| 139 |
+
},
|
| 140 |
+
{
|
| 141 |
+
"cell_type": "code",
|
| 142 |
+
"execution_count": null,
|
| 143 |
+
"id": "c7447d83-bf07-4bfb-8e4f-9d548617cde7",
|
| 144 |
+
"metadata": {},
|
| 145 |
+
"outputs": [],
|
| 146 |
+
"source": [
|
| 147 |
+
"# Section 1: Device calibration and Image data\n",
|
| 148 |
+
"\n",
|
| 149 |
+
"from tqdm import tqdm\n",
|
| 150 |
+
"\n",
|
| 151 |
+
"#\n",
|
| 152 |
+
"# Retrieve some statistics about the \"IMAGE\" VRS recording\n",
|
| 153 |
+
"#\n",
|
| 154 |
+
"\n",
|
| 155 |
+
"# Getting the device data provider (alias)\n",
|
| 156 |
+
"device_data_provider = hot3d_data_provider.device_data_provider\n",
|
| 157 |
+
"\n",
|
| 158 |
+
"# Retrieve the list of image stream supported by this sequence\n",
|
| 159 |
+
"# It will return the RGB and SLAM Left/Right image streams\n",
|
| 160 |
+
"image_stream_ids = device_data_provider.get_image_stream_ids()\n",
|
| 161 |
+
"# Retrieve a list of timestamps for the sequence (in nanoseconds)\n",
|
| 162 |
+
"timestamps = device_data_provider.get_sequence_timestamps()\n",
|
| 163 |
+
"\n",
|
| 164 |
+
"print(f\"Sequence: {os.path.basename(os.path.normpath(sequence_path))}\")\n",
|
| 165 |
+
"print(f\"Device type is {hot3d_data_provider.get_device_type()}\")\n",
|
| 166 |
+
"print(f\"Image stream ids: {image_stream_ids}\")\n",
|
| 167 |
+
"print(f\"Number of timestamp for this sequence: {len(timestamps)}\")\n",
|
| 168 |
+
"print(\n",
|
| 169 |
+
" f\"Duration of the sequence: {(timestamps[-1] - timestamps[0]) / 1e9} (seconds)\"\n",
|
| 170 |
+
") # Timestamps are in nanoseconds\n",
|
| 171 |
+
"\n",
|
| 172 |
+
"\n",
|
| 173 |
+
"# Init a rerun context to visualize the sequence file images\n",
|
| 174 |
+
"rr.init(\"Device images\")\n",
|
| 175 |
+
"rec = rr.memory_recording()\n",
|
| 176 |
+
"\n",
|
| 177 |
+
"# How to iterate over timestamps using a slice to show one timestamp every 200\n",
|
| 178 |
+
"timestamps_slice = slice(None, None, 200)\n",
|
| 179 |
+
"# Loop over the timestamps of the sequence and visualize corresponding data\n",
|
| 180 |
+
"for timestamp_ns in tqdm(timestamps[timestamps_slice]):\n",
|
| 181 |
+
"\n",
|
| 182 |
+
" for stream_id in image_stream_ids:\n",
|
| 183 |
+
" # Retrieve the image stream label as string\n",
|
| 184 |
+
" image_stream_label = device_data_provider.get_image_stream_label(stream_id)\n",
|
| 185 |
+
" # Retrieve the image data for a given timestamp\n",
|
| 186 |
+
" image_data = device_data_provider.get_image(timestamp_ns, stream_id)\n",
|
| 187 |
+
" # Visualize the image data (it's a numpy array)\n",
|
| 188 |
+
" log_image(label=f\"img/{image_stream_label}\", image=image_data)\n",
|
| 189 |
+
"\n",
|
| 190 |
+
"\n",
|
| 191 |
+
"#\n",
|
| 192 |
+
"# Retrieve Camera calibration (intrinsics and extrinsics) for a given stream_id\n",
|
| 193 |
+
"#\n",
|
| 194 |
+
"for stream_id in image_stream_ids:\n",
|
| 195 |
+
" # Retrieve the camera calibration (intrinsics and extrinsics) for a given stream_id\n",
|
| 196 |
+
" [extrinsics, intrinsics] = device_data_provider.get_camera_calibration(stream_id)\n",
|
| 197 |
+
" print(intrinsics)\n",
|
| 198 |
+
" # We will show in next section how to visualize the position of the camera in the world frame\n",
|
| 199 |
+
"\n",
|
| 200 |
+
"# Showing the rerun window\n",
|
| 201 |
+
"rr.notebook_show()"
|
| 202 |
+
]
|
| 203 |
+
},
|
| 204 |
+
{
|
| 205 |
+
"cell_type": "markdown",
|
| 206 |
+
"id": "1d199e9c-7359-43b2-8ecd-807db548def0",
|
| 207 |
+
"metadata": {},
|
| 208 |
+
"source": [
|
| 209 |
+
"# A gentle introduction to the \"GT Data\" Provider API\n",
|
| 210 |
+
"\n",
|
| 211 |
+
"Take home message:\n",
|
| 212 |
+
"- All \"GT data provider\" are using a similar API interface to query data at a given timestamp and/or StreamID.\n",
|
| 213 |
+
"- If the requested timestamp does not exists, the closest one can be retrieve along its delta time (dt).\n",
|
| 214 |
+
"\n",
|
| 215 |
+
"All the following \"GT data providers\" are accessible from Hot3dDataProvider and using a similar API interface.\n",
|
| 216 |
+
"```\n",
|
| 217 |
+
"|- device_pose_data_provider -> device/headset pose data\n",
|
| 218 |
+
"|- mano_hand_data_provider -> hand pose data (MANO hand model)\n",
|
| 219 |
+
"|- umetrack_hand_data_provider -> hand pose data (UmeTrack hand model)\n",
|
| 220 |
+
"|- object_pose_data_provider -> object pose data\n",
|
| 221 |
+
"|- hand_box2d_data_provider -> hand information such as amodal BBox and visibility ratio\n",
|
| 222 |
+
"|- object_box2d_data_provider -> object information such as amodal BBox and visibility ratio\n",
|
| 223 |
+
"```\n",
|
| 224 |
+
"\n",
|
| 225 |
+
"We are here shortly introducing the retrieval concept used, and then will showcase how to use each data_provider.\n",
|
| 226 |
+
"GT data providers enable retrieving information at a given TIMESTAMP\n",
|
| 227 |
+
"- If the timestamp is not exact, the closest one can will be returned,\n",
|
| 228 |
+
"- Delta Time (dt) between the found sample and the query timestamp is returned\n",
|
| 229 |
+
" Meaning that you known if you have a perfect match to the GT time sample or retrieved a close sample.\n",
|
| 230 |
+
" \n",
|
| 231 |
+
"Note: Some GT data providers are STREAM_ID specific and enable retrieve information for a given image stream.\n",
|
| 232 |
+
"```\n",
|
| 233 |
+
"data_with_dt = device_pose_provider.get_pose_at_timestamp(\n",
|
| 234 |
+
" timestamp_ns: int, -> Timestamp\n",
|
| 235 |
+
" stream_id: StreamID, -> If used, specify for which VRS image stream you query the data\n",
|
| 236 |
+
" time_query_options: TimeQueryOptions, -> Retrieval configuration, i.e TimeQueryOptions.CLOSEST\n",
|
| 237 |
+
" time_domain: TimeDomain, -> TimeDomain (always use TimeDomain.TIME_CODE)\n",
|
| 238 |
+
" acceptable_time_delta: Optional[int] = None, -> Threshold to reject delta dt that would be too large (using 0 or None is recommended)\n",
|
| 239 |
+
"```\n",
|
| 240 |
+
"\n",
|
| 241 |
+
"Here is how most of the interface will be used in the following sections:\n",
|
| 242 |
+
"```\n",
|
| 243 |
+
"data_with_dt = X_provider.get_X_at_timestamp(\n",
|
| 244 |
+
" timestamp_ns=timestamp_ns,\n",
|
| 245 |
+
" time_query_options=TimeQueryOptions.CLOSEST,\n",
|
| 246 |
+
" time_domain=TimeDomain.TIME_CODE)\n",
|
| 247 |
+
"```"
|
| 248 |
+
]
|
| 249 |
+
},
|
| 250 |
+
{
|
| 251 |
+
"cell_type": "code",
|
| 252 |
+
"execution_count": null,
|
| 253 |
+
"id": "a7c473c3-174f-4cff-9d58-0650b580da72",
|
| 254 |
+
"metadata": {},
|
| 255 |
+
"outputs": [],
|
| 256 |
+
"source": [
|
| 257 |
+
"#\n",
|
| 258 |
+
"# Section 2: Pose data\n",
|
| 259 |
+
"#\n",
|
| 260 |
+
"# Take home message:\n",
|
| 261 |
+
"# - the device_pose_provider enables you to retrieve the Headset pose as (T_world_device)\n",
|
| 262 |
+
"# - moving to the device to a given camera can be done by using calibration data and combining SE3 poses\n",
|
| 263 |
+
"# - such as T_world_camera = T_world_device @ T_device_camera\n",
|
| 264 |
+
"#\n",
|
| 265 |
+
"\n",
|
| 266 |
+
"from projectaria_tools.core.sensor_data import TimeDomain, TimeQueryOptions\n",
|
| 267 |
+
"\n",
|
| 268 |
+
"# Alias over the HEADSET/Device pose data provider\n",
|
| 269 |
+
"device_pose_provider = hot3d_data_provider.device_pose_data_provider\n",
|
| 270 |
+
"\n",
|
| 271 |
+
"# Init a rerun context to visualize the device trajectory\n",
|
| 272 |
+
"rr.init(\"Device/Headset trajectory\")\n",
|
| 273 |
+
"rec = rr.memory_recording()\n",
|
| 274 |
+
"\n",
|
| 275 |
+
"pose_translations = []\n",
|
| 276 |
+
"# Retrieve the position of the device in the world frame at a given timestamp\n",
|
| 277 |
+
"for timestamp_ns in tqdm(timestamps):\n",
|
| 278 |
+
"\n",
|
| 279 |
+
" rr.set_time_nanos(\"synchronization_time\", int(timestamp_ns))\n",
|
| 280 |
+
" rr.set_time_sequence(\"timestamp\", timestamp_ns)\n",
|
| 281 |
+
"\n",
|
| 282 |
+
" headset_pose3d_with_dt = None\n",
|
| 283 |
+
" if device_pose_provider is None:\n",
|
| 284 |
+
" continue\n",
|
| 285 |
+
" headset_pose3d_with_dt = device_pose_provider.get_pose_at_timestamp(\n",
|
| 286 |
+
" timestamp_ns=timestamp_ns,\n",
|
| 287 |
+
" time_query_options=TimeQueryOptions.CLOSEST,\n",
|
| 288 |
+
" time_domain=TimeDomain.TIME_CODE,\n",
|
| 289 |
+
" )\n",
|
| 290 |
+
"\n",
|
| 291 |
+
" if headset_pose3d_with_dt is None:\n",
|
| 292 |
+
" continue\n",
|
| 293 |
+
"\n",
|
| 294 |
+
" headset_pose3d = headset_pose3d_with_dt.pose3d\n",
|
| 295 |
+
" T_world_device = headset_pose3d.T_world_device\n",
|
| 296 |
+
" \n",
|
| 297 |
+
" log_pose(pose=T_world_device, label=\"world/device\")\n",
|
| 298 |
+
" pose_translations.append(T_world_device.translation()[0])\n",
|
| 299 |
+
" # This is the pose of the device, to move to a given camera, you need to apply the device_camera transformation\n",
|
| 300 |
+
" #for stream_id in image_stream_ids:\n",
|
| 301 |
+
" # # Retrieve the camera calibration (intrinsics and extrinsics) for a given stream_id\n",
|
| 302 |
+
" # [T_device_camera, intrinsics] = device_data_provider.get_camera_calibration(stream_id)\n",
|
| 303 |
+
" # # The pose of the given camera at this timestamp is (world_camera = world_device @ device_camera):\n",
|
| 304 |
+
" # T_world_camera = headset_pose3d.T_world_device @ T_device_camera\n",
|
| 305 |
+
" # camera_stream_label = device_data_provider.get_image_stream_label(stream_id)\n",
|
| 306 |
+
" # print(f\"Image stream label: {camera_stream_label} -> world_camera translation: {T_world_camera.translation()[0]}\")\n",
|
| 307 |
+
"\n",
|
| 308 |
+
"rr.log(\"world/device_trajectory\", rr.LineStrips3D([pose_translations]), static=True)\n",
|
| 309 |
+
"\n",
|
| 310 |
+
"# Showing the rerun window\n",
|
| 311 |
+
"rr.notebook_show()"
|
| 312 |
+
]
|
| 313 |
+
},
|
| 314 |
+
{
|
| 315 |
+
"cell_type": "code",
|
| 316 |
+
"execution_count": null,
|
| 317 |
+
"id": "d5253618-2ca2-4d11-a605-aa5aa19c54eb",
|
| 318 |
+
"metadata": {},
|
| 319 |
+
"outputs": [],
|
| 320 |
+
"source": [
|
| 321 |
+
"#\n",
|
| 322 |
+
"# Section 2.b: Hand pose data\n",
|
| 323 |
+
"#\n",
|
| 324 |
+
"# Take home message:\n",
|
| 325 |
+
"# - Hands are labelled as LEFT or RIGHT hands\n",
|
| 326 |
+
"# - \"Hands pose\" are representing the WRIST pose on which a MESH or LANDMARKS can be attached (see next section)\n",
|
| 327 |
+
"#\n",
|
| 328 |
+
"\n",
|
| 329 |
+
"# Alias over the HAND pose data provider\n",
|
| 330 |
+
"hand_data_provider = hot3d_data_provider.mano_hand_data_provider if hot3d_data_provider.mano_hand_data_provider is not None else hot3d_data_provider.umetrack_hand_data_provider\n",
|
| 331 |
+
"\n",
|
| 332 |
+
"# Init a rerun context to visualize the hand pose data trajectory\n",
|
| 333 |
+
"rr.init(\"Hand pose trajectory (wrist)\")\n",
|
| 334 |
+
"rec = rr.memory_recording()\n",
|
| 335 |
+
"\n",
|
| 336 |
+
"# Accumulate HAND poses translations as list, to show a LINE strip HAND trajectory\n",
|
| 337 |
+
"left_hand_pose_translations = []\n",
|
| 338 |
+
"right_hand_pose_translations = []\n",
|
| 339 |
+
"\n",
|
| 340 |
+
"# Retrieve the position of the device in the world frame at a given timestamp\n",
|
| 341 |
+
"for timestamp_ns in tqdm(timestamps):\n",
|
| 342 |
+
"\n",
|
| 343 |
+
" rr.set_time_nanos(\"synchronization_time\", int(timestamp_ns))\n",
|
| 344 |
+
" rr.set_time_sequence(\"timestamp\", timestamp_ns)\n",
|
| 345 |
+
"\n",
|
| 346 |
+
" hand_poses_with_dt = None\n",
|
| 347 |
+
" if hand_data_provider is None:\n",
|
| 348 |
+
" continue\n",
|
| 349 |
+
" \n",
|
| 350 |
+
" hand_poses_with_dt = hand_data_provider.get_pose_at_timestamp(\n",
|
| 351 |
+
" timestamp_ns=timestamp_ns,\n",
|
| 352 |
+
" time_query_options=TimeQueryOptions.CLOSEST,\n",
|
| 353 |
+
" time_domain=TimeDomain.TIME_CODE,\n",
|
| 354 |
+
" )\n",
|
| 355 |
+
"\n",
|
| 356 |
+
" if hand_poses_with_dt is None:\n",
|
| 357 |
+
" continue\n",
|
| 358 |
+
" \n",
|
| 359 |
+
" hand_pose_collection = hand_poses_with_dt.pose3d_collection\n",
|
| 360 |
+
"\n",
|
| 361 |
+
" for hand_pose_data in hand_pose_collection.poses.values():\n",
|
| 362 |
+
" # Retrieve the handedness of the hand (i.e Left or Right)\n",
|
| 363 |
+
" handedness_label = hand_pose_data.handedness_label()\n",
|
| 364 |
+
"\n",
|
| 365 |
+
" T_world_wrist = hand_pose_data.wrist_pose\n",
|
| 366 |
+
" log_pose(pose=T_world_wrist, label=f\"world/hand/{handedness_label}\")\n",
|
| 367 |
+
"\n",
|
| 368 |
+
" # Accumulate HAND poses translations as list, to show a LINE strip HAND trajectory\n",
|
| 369 |
+
" if hand_pose_data.is_left_hand():\n",
|
| 370 |
+
" left_hand_pose_translations.append(T_world_wrist.translation()[0])\n",
|
| 371 |
+
" elif hand_pose_data.is_right_hand():\n",
|
| 372 |
+
" right_hand_pose_translations.append(T_world_wrist.translation()[0])\n",
|
| 373 |
+
"\n",
|
| 374 |
+
"rr.log(\"world/left_hand\", rr.LineStrips3D([left_hand_pose_translations]), static=True)\n",
|
| 375 |
+
"rr.log(\"world/right_hand\", rr.LineStrips3D([right_hand_pose_translations]), static=True)\n",
|
| 376 |
+
"\n",
|
| 377 |
+
"# Showing the rerun window\n",
|
| 378 |
+
"rr.notebook_show()"
|
| 379 |
+
]
|
| 380 |
+
},
|
| 381 |
+
{
|
| 382 |
+
"cell_type": "code",
|
| 383 |
+
"execution_count": null,
|
| 384 |
+
"id": "0a013c63-65e6-4c38-b378-141c8c7ae3ae",
|
| 385 |
+
"metadata": {},
|
| 386 |
+
"outputs": [],
|
| 387 |
+
"source": [
|
| 388 |
+
"#\n",
|
| 389 |
+
"# Section 2.b.a: Hand pose data\n",
|
| 390 |
+
"#\n",
|
| 391 |
+
"# Take home message:\n",
|
| 392 |
+
"# - Hands are labelled as LEFT or RIGHT hands\n",
|
| 393 |
+
"# - Hands can be retrieved as:\n",
|
| 394 |
+
"# - Landmarks and displayed as line\n",
|
| 395 |
+
"# - Vertices\n",
|
| 396 |
+
"# - Mesh (using vertices, faces index and normals)\n",
|
| 397 |
+
"#\n",
|
| 398 |
+
"\n",
|
| 399 |
+
"from data_loaders.hand_common import LANDMARK_CONNECTIVITY\n",
|
| 400 |
+
"\n",
|
| 401 |
+
"\n",
|
| 402 |
+
"# Alias over the HAND pose data provider\n",
|
| 403 |
+
"hand_data_provider = hot3d_data_provider.mano_hand_data_provider if hot3d_data_provider.mano_hand_data_provider is not None else hot3d_data_provider.umetrack_hand_data_provider\n",
|
| 404 |
+
"\n",
|
| 405 |
+
"# Init a rerun context\n",
|
| 406 |
+
"rr.init(\"Hand pose LANDMARK/MESH\")\n",
|
| 407 |
+
"rec = rr.memory_recording()\n",
|
| 408 |
+
"\n",
|
| 409 |
+
"left_hand_pose_translations = []\n",
|
| 410 |
+
"right_hand_pose_translations = []\n",
|
| 411 |
+
"\n",
|
| 412 |
+
"# Limit to the first 300 timestamps\n",
|
| 413 |
+
"for timestamp_ns in tqdm(timestamps[:300]):\n",
|
| 414 |
+
"\n",
|
| 415 |
+
" rr.set_time_nanos(\"synchronization_time\", int(timestamp_ns))\n",
|
| 416 |
+
" rr.set_time_sequence(\"timestamp\", timestamp_ns)\n",
|
| 417 |
+
"\n",
|
| 418 |
+
" hand_poses_with_dt = None\n",
|
| 419 |
+
" if hand_data_provider is None:\n",
|
| 420 |
+
" continue\n",
|
| 421 |
+
" \n",
|
| 422 |
+
" hand_poses_with_dt = hand_data_provider.get_pose_at_timestamp(\n",
|
| 423 |
+
" timestamp_ns=timestamp_ns,\n",
|
| 424 |
+
" time_query_options=TimeQueryOptions.CLOSEST,\n",
|
| 425 |
+
" time_domain=TimeDomain.TIME_CODE,\n",
|
| 426 |
+
" )\n",
|
| 427 |
+
"\n",
|
| 428 |
+
" if hand_poses_with_dt is None:\n",
|
| 429 |
+
" continue\n",
|
| 430 |
+
" \n",
|
| 431 |
+
" hand_pose_collection = hand_poses_with_dt.pose3d_collection\n",
|
| 432 |
+
"\n",
|
| 433 |
+
" for hand_pose_data in hand_pose_collection.poses.values():\n",
|
| 434 |
+
" # Retrieve the handedness of the hand (i.e Left or Right)\n",
|
| 435 |
+
" handedness_label = hand_pose_data.handedness_label()\n",
|
| 436 |
+
"\n",
|
| 437 |
+
" # Skeleton/Joints landmark representation (for LEFT hand)\n",
|
| 438 |
+
" if hand_pose_data.is_left_hand():\n",
|
| 439 |
+
" hand_landmarks = hand_data_provider.get_hand_landmarks(\n",
|
| 440 |
+
" hand_pose_data\n",
|
| 441 |
+
" )\n",
|
| 442 |
+
" # convert landmarks to connected lines for display\n",
|
| 443 |
+
" # (i.e retrieve points along the HAND LANDMARK_CONNECTIVITY as a list)\n",
|
| 444 |
+
" points = [connections\n",
|
| 445 |
+
" for connectivity in LANDMARK_CONNECTIVITY\n",
|
| 446 |
+
" for connections in [[hand_landmarks[it].numpy().tolist() for it in connectivity]]]\n",
|
| 447 |
+
" rr.log(\n",
|
| 448 |
+
" f\"world/{handedness_label}/joints\",\n",
|
| 449 |
+
" rr.LineStrips3D(points, radii=0.002),\n",
|
| 450 |
+
" )\n",
|
| 451 |
+
"\n",
|
| 452 |
+
" #\n",
|
| 453 |
+
" # Plot RIGHT hand as a Triangular Mesh representation\n",
|
| 454 |
+
" #\n",
|
| 455 |
+
" if hand_pose_data.is_right_hand():\n",
|
| 456 |
+
" hand_mesh_vertices = hand_data_provider.get_hand_mesh_vertices(hand_pose_data)\n",
|
| 457 |
+
" hand_triangles, hand_vertex_normals = hand_data_provider.get_hand_mesh_faces_and_normals(hand_pose_data)\n",
|
| 458 |
+
" \n",
|
| 459 |
+
" rr.log(\n",
|
| 460 |
+
" f\"world/{handedness_label}/mesh_faces\",\n",
|
| 461 |
+
" rr.Mesh3D(\n",
|
| 462 |
+
" vertex_positions=hand_mesh_vertices,\n",
|
| 463 |
+
" vertex_normals=hand_vertex_normals,\n",
|
| 464 |
+
" triangle_indices=hand_triangles,\n",
|
| 465 |
+
" ),\n",
|
| 466 |
+
" )\n",
|
| 467 |
+
"\n",
|
| 468 |
+
"# Showing the rerun window\n",
|
| 469 |
+
"rr.notebook_show()"
|
| 470 |
+
]
|
| 471 |
+
},
|
| 472 |
+
{
|
| 473 |
+
"cell_type": "code",
|
| 474 |
+
"execution_count": null,
|
| 475 |
+
"id": "a909427f-d8c5-40a7-8eba-8702de2a313b",
|
| 476 |
+
"metadata": {},
|
| 477 |
+
"outputs": [],
|
| 478 |
+
"source": [
|
| 479 |
+
"#\n",
|
| 480 |
+
"# Section 2.c: Object pose data\n",
|
| 481 |
+
"#\n",
|
| 482 |
+
"# Take home message:\n",
|
| 483 |
+
"# - Each object is associated with a Unique Identified (uid)\n",
|
| 484 |
+
"# - The object library enables to retrieve the 3D asset linked to this UID (a glb file)\n",
|
| 485 |
+
"#\n",
|
| 486 |
+
"\n",
|
| 487 |
+
"from data_loaders.loader_object_library import ObjectLibrary\n",
|
| 488 |
+
"\n",
|
| 489 |
+
"# Alias over the Object pose data provider\n",
|
| 490 |
+
"object_pose_data_provider = hot3d_data_provider.object_pose_data_provider\n",
|
| 491 |
+
"\n",
|
| 492 |
+
"# Keep track of what 3D assets has been loaded/unloaded so we will load them only when needed\n",
|
| 493 |
+
"# So we will load them only when required for Rerun\n",
|
| 494 |
+
"object_cache_status = {}\n",
|
| 495 |
+
"\n",
|
| 496 |
+
"# Init a rerun context\n",
|
| 497 |
+
"rr.init(\"Object pose\")\n",
|
| 498 |
+
"rec = rr.memory_recording()\n",
|
| 499 |
+
"\n",
|
| 500 |
+
"# Limit to the some timestamps\n",
|
| 501 |
+
"for timestamp_ns in tqdm(timestamps[100:300]):\n",
|
| 502 |
+
"\n",
|
| 503 |
+
" rr.set_time_nanos(\"synchronization_time\", int(timestamp_ns))\n",
|
| 504 |
+
" rr.set_time_sequence(\"timestamp\", timestamp_ns)\n",
|
| 505 |
+
"\n",
|
| 506 |
+
" object_poses_with_dt = (\n",
|
| 507 |
+
" object_pose_data_provider.get_pose_at_timestamp(\n",
|
| 508 |
+
" timestamp_ns=timestamp_ns,\n",
|
| 509 |
+
" time_query_options=TimeQueryOptions.CLOSEST,\n",
|
| 510 |
+
" time_domain=TimeDomain.TIME_CODE,\n",
|
| 511 |
+
" )\n",
|
| 512 |
+
" )\n",
|
| 513 |
+
" if object_poses_with_dt is None:\n",
|
| 514 |
+
" continue\n",
|
| 515 |
+
"\n",
|
| 516 |
+
" objects_pose3d_collection = object_poses_with_dt.pose3d_collection\n",
|
| 517 |
+
"\n",
|
| 518 |
+
" # Keep a mapping to know what object has been seen, and which one has not\n",
|
| 519 |
+
" object_uids = object_pose_data_provider.object_uids_with_poses\n",
|
| 520 |
+
" logging_status = {x: False for x in object_uids}\n",
|
| 521 |
+
"\n",
|
| 522 |
+
" for (\n",
|
| 523 |
+
" object_uid,\n",
|
| 524 |
+
" object_pose3d,\n",
|
| 525 |
+
" ) in objects_pose3d_collection.poses.items():\n",
|
| 526 |
+
"\n",
|
| 527 |
+
" object_name = object_library.object_id_to_name_dict[object_uid]\n",
|
| 528 |
+
" object_name = object_name + \"_\" + str(object_uid)\n",
|
| 529 |
+
" object_cad_asset_filepath = ObjectLibrary.get_cad_asset_path(\n",
|
| 530 |
+
" object_library_folderpath=object_library.asset_folder_name,\n",
|
| 531 |
+
" object_id=object_uid,\n",
|
| 532 |
+
" )\n",
|
| 533 |
+
"\n",
|
| 534 |
+
" log_pose(pose=object_pose3d.T_world_object, label=f\"world/objects/{object_name}\")\n",
|
| 535 |
+
" \n",
|
| 536 |
+
" # Mark object has been seen (enable to know which object has been logged or not)\n",
|
| 537 |
+
" # I.E and object not logged, has not been seen and will have its entity cleared for rerun\n",
|
| 538 |
+
" logging_status[object_uid] = True\n",
|
| 539 |
+
"\n",
|
| 540 |
+
" # Link the corresponding 3D object to the pose\n",
|
| 541 |
+
" if object_uid not in object_cache_status.keys():\n",
|
| 542 |
+
" object_cache_status[object_uid] = True\n",
|
| 543 |
+
" rr.log(\n",
|
| 544 |
+
" f\"world/objects/{object_name}\",\n",
|
| 545 |
+
" rr.Asset3D(\n",
|
| 546 |
+
" path=object_cad_asset_filepath,\n",
|
| 547 |
+
" ),\n",
|
| 548 |
+
" )\n",
|
| 549 |
+
"\n",
|
| 550 |
+
" # Rerun specifics (if an entity is disapearing, the last status is shown)\n",
|
| 551 |
+
" # To compensate that , if some objects are not visible, we clear the entity\n",
|
| 552 |
+
" for object_uid, displayed in logging_status.items():\n",
|
| 553 |
+
" if not displayed:\n",
|
| 554 |
+
" object_name = object_library.object_id_to_name_dict[object_uid]\n",
|
| 555 |
+
" object_name = object_name + \"_\" + str(object_uid)\n",
|
| 556 |
+
" rr.log(\n",
|
| 557 |
+
" f\"world/objects/{object_name}\",\n",
|
| 558 |
+
" rr.Clear.recursive(),\n",
|
| 559 |
+
" )\n",
|
| 560 |
+
" if object_uid in object_cache_status.keys():\n",
|
| 561 |
+
" del object_cache_status[object_uid] # We will log the mesh again\n",
|
| 562 |
+
"\n",
|
| 563 |
+
"# Showing the rerun window\n",
|
| 564 |
+
"rr.notebook_show()"
|
| 565 |
+
]
|
| 566 |
+
},
|
| 567 |
+
{
|
| 568 |
+
"cell_type": "code",
|
| 569 |
+
"execution_count": null,
|
| 570 |
+
"id": "f31214ce-108e-403e-b66f-2c224ab450f1",
|
| 571 |
+
"metadata": {},
|
| 572 |
+
"outputs": [],
|
| 573 |
+
"source": [
|
| 574 |
+
"#\n",
|
| 575 |
+
"# Section 3: Object/Hand bounding boxes\n",
|
| 576 |
+
"#\n",
|
| 577 |
+
"# Take home message\n",
|
| 578 |
+
"# - Bounding box data is queried by TIMESTAMP and STREAM_ID and contains amodal bbox and visibility ratio\n",
|
| 579 |
+
"# - Unique Identifiers are used to label objects (uid) -> they can be mapped to literal name by using the object_library\n",
|
| 580 |
+
"#"
|
| 581 |
+
]
|
| 582 |
+
},
|
| 583 |
+
{
|
| 584 |
+
"cell_type": "code",
|
| 585 |
+
"execution_count": null,
|
| 586 |
+
"id": "b841145d-a114-4693-a0d4-492f9629bbbe",
|
| 587 |
+
"metadata": {},
|
| 588 |
+
"outputs": [],
|
| 589 |
+
"source": [
|
| 590 |
+
"#\n",
|
| 591 |
+
"# Section 3.a: Object bounding boxes\n",
|
| 592 |
+
"#\n",
|
| 593 |
+
"#\n",
|
| 594 |
+
"from projectaria_tools.core.stream_id import StreamId\n",
|
| 595 |
+
"\n",
|
| 596 |
+
"import matplotlib.pyplot as plt # Used to display consistent colored Bounding Boxes contours\n",
|
| 597 |
+
"\n",
|
| 598 |
+
"# Alias over the Object box2d data provider and Device data provider (to get image data)\n",
|
| 599 |
+
"object_box2d_data_provider = hot3d_data_provider.object_box2d_data_provider\n",
|
| 600 |
+
"device_data_provider = hot3d_data_provider.device_data_provider\n",
|
| 601 |
+
"\n",
|
| 602 |
+
"# Retrieve a distinct color mapping for object bounding box\n",
|
| 603 |
+
"# by using a colormap (i.e associate a object_uid to a specific color)\n",
|
| 604 |
+
"object_uids = list(object_box2d_data_provider.object_uids) # list of available object_uid used to map them to [0, 1, 2, ...] indices\n",
|
| 605 |
+
"object_box2d_colors = None\n",
|
| 606 |
+
"if object_box2d_data_provider is not None:\n",
|
| 607 |
+
" color_map = plt.get_cmap(\"viridis\")\n",
|
| 608 |
+
" object_box2d_colors = color_map(\n",
|
| 609 |
+
" np.linspace(0, 1, len(object_uids))\n",
|
| 610 |
+
" )\n",
|
| 611 |
+
"else:\n",
|
| 612 |
+
" print(\"This section expect to have valid bounding box data\")\n",
|
| 613 |
+
"\n",
|
| 614 |
+
"\n",
|
| 615 |
+
"# Init a rerun context\n",
|
| 616 |
+
"rr.init(\"Object bounding boxed and visibility ratio\")\n",
|
| 617 |
+
"rec = rr.memory_recording()\n",
|
| 618 |
+
"\n",
|
| 619 |
+
"# Use SLAM-LEFT image (exists for both Aria and Quest files)\n",
|
| 620 |
+
"stream_id = StreamId(\"1201-1\")\n",
|
| 621 |
+
"if stream_id not in object_box2d_data_provider.stream_ids:\n",
|
| 622 |
+
" print(f\"The object_box2d_data_provider does not have data for this StreamId: {stream_id}\")\n",
|
| 623 |
+
"\n",
|
| 624 |
+
"\n",
|
| 625 |
+
"# Limit to the some timestamps\n",
|
| 626 |
+
"for timestamp_ns in tqdm(timestamps[100:200]):\n",
|
| 627 |
+
"\n",
|
| 628 |
+
" rr.set_time_nanos(\"synchronization_time\", int(timestamp_ns))\n",
|
| 629 |
+
" rr.set_time_sequence(\"timestamp\", timestamp_ns)\n",
|
| 630 |
+
"\n",
|
| 631 |
+
" # Retrieve data for this timestamp and specific stream_id\n",
|
| 632 |
+
" box2d_collection_with_dt = (\n",
|
| 633 |
+
" object_box2d_data_provider.get_bbox_at_timestamp(\n",
|
| 634 |
+
" stream_id=stream_id,\n",
|
| 635 |
+
" timestamp_ns=timestamp_ns,\n",
|
| 636 |
+
" time_query_options=TimeQueryOptions.CLOSEST,\n",
|
| 637 |
+
" time_domain=TimeDomain.TIME_CODE,\n",
|
| 638 |
+
" )\n",
|
| 639 |
+
" )\n",
|
| 640 |
+
" if box2d_collection_with_dt is None:\n",
|
| 641 |
+
" continue\n",
|
| 642 |
+
" if (\n",
|
| 643 |
+
" box2d_collection_with_dt is None\n",
|
| 644 |
+
" and box2d_collection_with_dt.box2d_collection or None\n",
|
| 645 |
+
" ):\n",
|
| 646 |
+
" continue\n",
|
| 647 |
+
" \n",
|
| 648 |
+
" # We have valid data, returned as a collection\n",
|
| 649 |
+
" # i.e for each object_uid, we retrieve its BBOX and visibility\n",
|
| 650 |
+
" object_uids_at_query_timestamp = (\n",
|
| 651 |
+
" box2d_collection_with_dt.box2d_collection.object_uid_list\n",
|
| 652 |
+
" )\n",
|
| 653 |
+
"\n",
|
| 654 |
+
" for object_uid in object_uids_at_query_timestamp:\n",
|
| 655 |
+
" object_name = object_library.object_id_to_name_dict[object_uid]\n",
|
| 656 |
+
" axis_aligned_box2d = box2d_collection_with_dt.box2d_collection.box2ds[object_uid]\n",
|
| 657 |
+
" bbox = axis_aligned_box2d.box2d\n",
|
| 658 |
+
" visibility_ratio = axis_aligned_box2d.visibility_ratio\n",
|
| 659 |
+
" if bbox is None:\n",
|
| 660 |
+
" continue\n",
|
| 661 |
+
"\n",
|
| 662 |
+
" rr.log(\n",
|
| 663 |
+
" f\"{stream_id}_raw/bbox/{object_name}\",\n",
|
| 664 |
+
" rr.Boxes2D(\n",
|
| 665 |
+
" mins=[bbox.left, bbox.top],\n",
|
| 666 |
+
" sizes=[bbox.width, bbox.height],\n",
|
| 667 |
+
" colors=object_box2d_colors[object_uids.index(object_uid)],\n",
|
| 668 |
+
" ),\n",
|
| 669 |
+
" )\n",
|
| 670 |
+
" rr.log(f\"visibility_ratio/{object_name}\", rr.Scalar(visibility_ratio))\n",
|
| 671 |
+
" \n",
|
| 672 |
+
" # Log the corresponding image\n",
|
| 673 |
+
" image_stream_label = device_data_provider.get_image_stream_label(stream_id)\n",
|
| 674 |
+
" # Retrieve the image data for a given timestamp\n",
|
| 675 |
+
" image_data = device_data_provider.get_image(timestamp_ns, stream_id)\n",
|
| 676 |
+
" # Visualize the image data (it's a numpy array)\n",
|
| 677 |
+
" log_image(label=f\"{stream_id}_raw\", image=image_data)\n",
|
| 678 |
+
"\n",
|
| 679 |
+
"# Showing the rerun window\n",
|
| 680 |
+
"rr.notebook_show()\n"
|
| 681 |
+
]
|
| 682 |
+
},
|
| 683 |
+
{
|
| 684 |
+
"cell_type": "code",
|
| 685 |
+
"execution_count": null,
|
| 686 |
+
"id": "0d1daf98-2df6-4d0a-ae38-331060353b99",
|
| 687 |
+
"metadata": {},
|
| 688 |
+
"outputs": [],
|
| 689 |
+
"source": [
|
| 690 |
+
"#\n",
|
| 691 |
+
"# Section 3.b: Hand bounding boxes\n",
|
| 692 |
+
"#\n",
|
| 693 |
+
"#\n",
|
| 694 |
+
"from projectaria_tools.core.stream_id import StreamId\n",
|
| 695 |
+
"\n",
|
| 696 |
+
"from data_loaders.loader_hand_poses import LEFT_HAND_INDEX, RIGHT_HAND_INDEX\n",
|
| 697 |
+
"import matplotlib.pyplot as plt # Used to display consistent colored Bounding Boxes contours\n",
|
| 698 |
+
"\n",
|
| 699 |
+
"# Alias over the Hand box2d data provider and Device data provider (to get image data)\n",
|
| 700 |
+
"hand_box2d_data_provider = hot3d_data_provider.hand_box2d_data_provider\n",
|
| 701 |
+
"device_data_provider = hot3d_data_provider.device_data_provider\n",
|
| 702 |
+
"\n",
|
| 703 |
+
"# Retrieve a distinct color mapping for hand bounding box\n",
|
| 704 |
+
"# by using a colormap (i.e associate a hand_uid to a specific color)\n",
|
| 705 |
+
"hand_uids = [LEFT_HAND_INDEX, RIGHT_HAND_INDEX]\n",
|
| 706 |
+
"hand_box2d_colors = None\n",
|
| 707 |
+
"if hand_box2d_data_provider is not None:\n",
|
| 708 |
+
" color_map = plt.get_cmap(\"viridis\")\n",
|
| 709 |
+
" hand_box2d_colors = color_map(\n",
|
| 710 |
+
" np.linspace(0, 1, len(hand_uids))\n",
|
| 711 |
+
" )\n",
|
| 712 |
+
"else:\n",
|
| 713 |
+
" print(\"This section expect to have valid bounding box data\")\n",
|
| 714 |
+
"\n",
|
| 715 |
+
"\n",
|
| 716 |
+
"# Init a rerun context\n",
|
| 717 |
+
"rr.init(\"Hand bounding boxed and visibility ratio\")\n",
|
| 718 |
+
"rec = rr.memory_recording()\n",
|
| 719 |
+
"\n",
|
| 720 |
+
"# Use SLAM-LEFT image (exists for both Aria and Quest files)\n",
|
| 721 |
+
"stream_id = StreamId(\"1201-1\")\n",
|
| 722 |
+
"if stream_id not in hand_box2d_data_provider.stream_ids:\n",
|
| 723 |
+
" print(f\"The hand_box2d_data_provider does not have data for this StreamId: {stream_id}\")\n",
|
| 724 |
+
"\n",
|
| 725 |
+
"\n",
|
| 726 |
+
"# Limit to the some timestamps\n",
|
| 727 |
+
"for timestamp_ns in tqdm(timestamps[100:200]):\n",
|
| 728 |
+
"\n",
|
| 729 |
+
" rr.set_time_nanos(\"synchronization_time\", int(timestamp_ns))\n",
|
| 730 |
+
" rr.set_time_sequence(\"timestamp\", timestamp_ns)\n",
|
| 731 |
+
"\n",
|
| 732 |
+
" # Retrieve data for this timestamp and specific stream_id\n",
|
| 733 |
+
" box2d_collection_with_dt = (\n",
|
| 734 |
+
" hand_box2d_data_provider.get_bbox_at_timestamp(\n",
|
| 735 |
+
" stream_id=stream_id,\n",
|
| 736 |
+
" timestamp_ns=timestamp_ns,\n",
|
| 737 |
+
" time_query_options=TimeQueryOptions.CLOSEST,\n",
|
| 738 |
+
" time_domain=TimeDomain.TIME_CODE,\n",
|
| 739 |
+
" )\n",
|
| 740 |
+
" )\n",
|
| 741 |
+
" \n",
|
| 742 |
+
" if box2d_collection_with_dt is None:\n",
|
| 743 |
+
" continue\n",
|
| 744 |
+
" if (\n",
|
| 745 |
+
" box2d_collection_with_dt is None\n",
|
| 746 |
+
" and box2d_collection_with_dt.box2d_collection or None\n",
|
| 747 |
+
" ):\n",
|
| 748 |
+
" continue\n",
|
| 749 |
+
"\n",
|
| 750 |
+
" \n",
|
| 751 |
+
" # We have valid data, returned as a collection\n",
|
| 752 |
+
" # i.e for each hand_uid, we retrieve its BBOX and visibility\n",
|
| 753 |
+
" for hand_uid in hand_uids:\n",
|
| 754 |
+
" hand_name = \"left\" if hand_uid == LEFT_HAND_INDEX else \"right\"\n",
|
| 755 |
+
" axis_aligned_box2d = box2d_collection_with_dt.box2d_collection.box2ds[hand_uid]\n",
|
| 756 |
+
" bbox = axis_aligned_box2d.box2d\n",
|
| 757 |
+
" visibility_ratio = axis_aligned_box2d.visibility_ratio\n",
|
| 758 |
+
" if bbox is None:\n",
|
| 759 |
+
" continue\n",
|
| 760 |
+
"\n",
|
| 761 |
+
" rr.log(\n",
|
| 762 |
+
" f\"{stream_id}_raw/bbox/{hand_name}\",\n",
|
| 763 |
+
" rr.Boxes2D(\n",
|
| 764 |
+
" mins=[bbox.left, bbox.top],\n",
|
| 765 |
+
" sizes=[bbox.width, bbox.height],\n",
|
| 766 |
+
" colors=object_box2d_colors[hand_uids.index(hand_uid)],\n",
|
| 767 |
+
" ),\n",
|
| 768 |
+
" )\n",
|
| 769 |
+
" rr.log(f\"visibility_ratio/{hand_name}\", rr.Scalar(visibility_ratio))\n",
|
| 770 |
+
" \n",
|
| 771 |
+
" # Log the corresponding image\n",
|
| 772 |
+
" image_stream_label = device_data_provider.get_image_stream_label(stream_id)\n",
|
| 773 |
+
" # Retrieve the image data for a given timestamp\n",
|
| 774 |
+
" image_data = device_data_provider.get_image(timestamp_ns, stream_id)\n",
|
| 775 |
+
" # Visualize the image data (it's a numpy array)\n",
|
| 776 |
+
" log_image(label=f\"{stream_id}_raw\", image=image_data)\n",
|
| 777 |
+
"\n",
|
| 778 |
+
"# Showing the rerun window\n",
|
| 779 |
+
"rr.notebook_show()\n"
|
| 780 |
+
]
|
| 781 |
+
},
|
| 782 |
+
{
|
| 783 |
+
"cell_type": "code",
|
| 784 |
+
"execution_count": null,
|
| 785 |
+
"id": "d8bad34e-a8ab-437d-84ff-1c046ca35d51",
|
| 786 |
+
"metadata": {},
|
| 787 |
+
"outputs": [],
|
| 788 |
+
"source": [
|
| 789 |
+
"#\n",
|
| 790 |
+
"# Section 4: Eye Gaze data (only for Aria data)\n",
|
| 791 |
+
"#\n",
|
| 792 |
+
"# Take home message\n",
|
| 793 |
+
"# - Eye Gaze data is only available for Aria sequences\n",
|
| 794 |
+
"# - Eye Gaze data is retrieved via the device_data_provider\n",
|
| 795 |
+
"# - Eye Gaze data is a 3D ray that can be reprojected at any desired depth in a given image\n",
|
| 796 |
+
"#\n",
|
| 797 |
+
"\n",
|
| 798 |
+
"from data_loaders.headsets import Headset\n",
|
| 799 |
+
"from projectaria_tools.core.calibration import FISHEYE624\n",
|
| 800 |
+
"\n",
|
| 801 |
+
"if hot3d_data_provider.get_device_type() is not Headset.Aria:\n",
|
| 802 |
+
" pass\n",
|
| 803 |
+
"\n",
|
| 804 |
+
"device_data_provider = hot3d_data_provider.device_data_provider\n",
|
| 805 |
+
"\n",
|
| 806 |
+
"# Use RGB image\n",
|
| 807 |
+
"stream_id = StreamId(\"214-1\")\n",
|
| 808 |
+
"\n",
|
| 809 |
+
"# Init a rerun context\n",
|
| 810 |
+
"rr.init(\"Eye Gaze reprojection in RGB image\")\n",
|
| 811 |
+
"rec = rr.memory_recording()\n",
|
| 812 |
+
"\n",
|
| 813 |
+
"# Limit to the some timestamps\n",
|
| 814 |
+
"for timestamp_ns in tqdm(timestamps[100:120]):\n",
|
| 815 |
+
"\n",
|
| 816 |
+
" rr.set_time_nanos(\"synchronization_time\", int(timestamp_ns))\n",
|
| 817 |
+
" rr.set_time_sequence(\"timestamp\", timestamp_ns)\n",
|
| 818 |
+
" \n",
|
| 819 |
+
" aria_eye_gaze_data = (\n",
|
| 820 |
+
" device_data_provider.get_eye_gaze(timestamp_ns)\n",
|
| 821 |
+
" if hot3d_data_provider.get_device_type() is Headset.Aria\n",
|
| 822 |
+
" else None\n",
|
| 823 |
+
" )\n",
|
| 824 |
+
" #\n",
|
| 825 |
+
" ## Eye Gaze image reprojection\n",
|
| 826 |
+
" #\n",
|
| 827 |
+
" if aria_eye_gaze_data is not None:\n",
|
| 828 |
+
"\n",
|
| 829 |
+
" # We are showing EyeGaze reprojection only on the RGB image stream\n",
|
| 830 |
+
" if stream_id != StreamId(\"214-1\"):\n",
|
| 831 |
+
" continue\n",
|
| 832 |
+
"\n",
|
| 833 |
+
" # Reproject EyeGaze for raw images\n",
|
| 834 |
+
" camera_model = FISHEYE624\n",
|
| 835 |
+
" \n",
|
| 836 |
+
" eye_gaze_reprojection_data = (\n",
|
| 837 |
+
" device_data_provider.get_eye_gaze_in_camera(\n",
|
| 838 |
+
" stream_id, timestamp_ns, camera_model=camera_model\n",
|
| 839 |
+
" )\n",
|
| 840 |
+
" )\n",
|
| 841 |
+
" if (\n",
|
| 842 |
+
" eye_gaze_reprojection_data is None\n",
|
| 843 |
+
" or not eye_gaze_reprojection_data.any()\n",
|
| 844 |
+
" ):\n",
|
| 845 |
+
" continue\n",
|
| 846 |
+
"\n",
|
| 847 |
+
" rr.log(\n",
|
| 848 |
+
" f\"{stream_id}/eye-gaze_projection\",\n",
|
| 849 |
+
" rr.Points2D(eye_gaze_reprojection_data, radii=20),\n",
|
| 850 |
+
" )\n",
|
| 851 |
+
"\n",
|
| 852 |
+
" # Log the corresponding image\n",
|
| 853 |
+
" image_stream_label = device_data_provider.get_image_stream_label(stream_id)\n",
|
| 854 |
+
" # Retrieve the image data for a given timestamp\n",
|
| 855 |
+
" image_data = device_data_provider.get_image(timestamp_ns, stream_id)\n",
|
| 856 |
+
" # Visualize the image data (it's a numpy array)\n",
|
| 857 |
+
" log_image(label=f\"{stream_id}\", image=image_data)\n",
|
| 858 |
+
"\n",
|
| 859 |
+
"# Showing the rerun window\n",
|
| 860 |
+
"rr.notebook_show()"
|
| 861 |
+
]
|
| 862 |
+
},
|
| 863 |
+
{
|
| 864 |
+
"cell_type": "code",
|
| 865 |
+
"execution_count": null,
|
| 866 |
+
"id": "b4d6ac37-e3b3-401a-83b7-e09a42a183a3",
|
| 867 |
+
"metadata": {},
|
| 868 |
+
"outputs": [],
|
| 869 |
+
"source": [
|
| 870 |
+
"#\n",
|
| 871 |
+
"# - Section 5: Camera reprojection (reprojection hand vertices to raw fish images)\n",
|
| 872 |
+
"#\n",
|
| 873 |
+
"# Take home message\n",
|
| 874 |
+
"#\n",
|
| 875 |
+
"# - Each image/streamId is having its own calibration you can retrieve and use\n",
|
| 876 |
+
"# - Using project(X) enables you to project a 3D point to a 2D image\n",
|
| 877 |
+
"#\n",
|
| 878 |
+
"\n",
|
| 879 |
+
"%matplotlib inline\n",
|
| 880 |
+
"from matplotlib import pyplot as plt\n",
|
| 881 |
+
"\n",
|
| 882 |
+
"from typing import Any, Optional\n",
|
| 883 |
+
"\n",
|
| 884 |
+
"import numpy as np\n",
|
| 885 |
+
"from data_loaders.HeadsetPose3dProvider import HeadsetPose3dProvider\n",
|
| 886 |
+
"\n",
|
| 887 |
+
"from data_loaders.loader_hand_poses import Handedness, HandPose3dCollection\n",
|
| 888 |
+
"\n",
|
| 889 |
+
"# Todo move up later\n",
|
| 890 |
+
"%matplotlib inline\n",
|
| 891 |
+
"from matplotlib import pyplot as plt\n",
|
| 892 |
+
"from projectaria_tools.core.calibration import CameraCalibration\n",
|
| 893 |
+
"from projectaria_tools.core.sophus import SE3\n",
|
| 894 |
+
"from projectaria_tools.core.stream_id import StreamId\n",
|
| 895 |
+
"\n",
|
| 896 |
+
"\n",
|
| 897 |
+
"image_streamid = StreamId(\"214-1\")\n",
|
| 898 |
+
"# image_streamid = StreamId(\"1201-1\")\n",
|
| 899 |
+
"\n",
|
| 900 |
+
"# timestamp_ns = timestamps[len(timestamps) // 2]\n",
|
| 901 |
+
"timestamp_ns = timestamps[420]\n",
|
| 902 |
+
"\n",
|
| 903 |
+
"# Retrieve the image stream label as string\n",
|
| 904 |
+
"image_stream_label = device_data_provider.get_image_stream_label(image_streamid)\n",
|
| 905 |
+
"\n",
|
| 906 |
+
"# Retrieve the image data for a given timestamp\n",
|
| 907 |
+
"image_data = device_data_provider.get_image(timestamp_ns, image_streamid)\n",
|
| 908 |
+
"\n",
|
| 909 |
+
"# Retrieve the hand vertices and project them on the image at this timestamp\n",
|
| 910 |
+
"def retrieve_hand_data(timestamp_ns: int) -> Optional[HandPose3dCollection]:\n",
|
| 911 |
+
" \"\"\"\n",
|
| 912 |
+
" Retrieve the collection of Hand Pose at this timestamp (i.e. LEFT or RIGHT hand)\n",
|
| 913 |
+
" Note: They are 3D pose in world, and does not say if they are visible for a given camera or not (stream_id)\n",
|
| 914 |
+
" Visibility can either being determined by using camera visibility (are vertices visible), or using the 2d hands bounding box\n",
|
| 915 |
+
" \"\"\"\n",
|
| 916 |
+
" hand_poses_with_dt = None\n",
|
| 917 |
+
" if hand_data_provider is not None:\n",
|
| 918 |
+
" hand_poses_with_dt = hand_data_provider.get_pose_at_timestamp(\n",
|
| 919 |
+
" timestamp_ns=timestamp_ns,\n",
|
| 920 |
+
" time_query_options=TimeQueryOptions.CLOSEST,\n",
|
| 921 |
+
" time_domain=TimeDomain.TIME_CODE,\n",
|
| 922 |
+
" )\n",
|
| 923 |
+
"\n",
|
| 924 |
+
" if hand_poses_with_dt is not None:\n",
|
| 925 |
+
" return hand_poses_with_dt.pose3d_collection\n",
|
| 926 |
+
" return None\n",
|
| 927 |
+
"\n",
|
| 928 |
+
"\n",
|
| 929 |
+
"def retrieve_device_pose(\n",
|
| 930 |
+
" timestamp_ns: int,\n",
|
| 931 |
+
" stream_id: StreamId,\n",
|
| 932 |
+
" device_pose_provider: Optional[HeadsetPose3dProvider] = None,\n",
|
| 933 |
+
" device_data_provider: Optional[Any] = None,\n",
|
| 934 |
+
") -> Optional[tuple[SE3, CameraCalibration]]:\n",
|
| 935 |
+
" \"\"\"\n",
|
| 936 |
+
" Retrieve the pose of the device and apply the device_camera transformation on top of it for the provided stream_id\n",
|
| 937 |
+
" \"\"\"\n",
|
| 938 |
+
" headset_pose3d_with_dt = None\n",
|
| 939 |
+
" if device_pose_provider is not None:\n",
|
| 940 |
+
" headset_pose3d_with_dt = device_pose_provider.get_pose_at_timestamp(\n",
|
| 941 |
+
" timestamp_ns=timestamp_ns,\n",
|
| 942 |
+
" time_query_options=TimeQueryOptions.CLOSEST,\n",
|
| 943 |
+
" time_domain=TimeDomain.TIME_CODE,\n",
|
| 944 |
+
" )\n",
|
| 945 |
+
"\n",
|
| 946 |
+
" if headset_pose3d_with_dt is not None:\n",
|
| 947 |
+
" headset_pose3d = headset_pose3d_with_dt.pose3d\n",
|
| 948 |
+
"\n",
|
| 949 |
+
" # Retrieve the camera calibration (intrinsics and extrinsics) for a given stream_id\n",
|
| 950 |
+
" [extrinsics, intrinsics] = device_data_provider.get_camera_calibration(\n",
|
| 951 |
+
" stream_id\n",
|
| 952 |
+
" )\n",
|
| 953 |
+
" # The pose of the given camera at this timestamp is (world_camera = world_device @ device_camera):\n",
|
| 954 |
+
" world_camera_pose = headset_pose3d.T_world_device @ extrinsics\n",
|
| 955 |
+
" return [world_camera_pose, intrinsics]\n",
|
| 956 |
+
" return None\n",
|
| 957 |
+
"\n",
|
| 958 |
+
"\n",
|
| 959 |
+
"# Retrieve the data for this timestamp\n",
|
| 960 |
+
"hand_data = retrieve_hand_data(timestamp_ns)\n",
|
| 961 |
+
"device_pose = retrieve_device_pose(\n",
|
| 962 |
+
" timestamp_ns, image_streamid, device_pose_provider, device_data_provider\n",
|
| 963 |
+
")\n",
|
| 964 |
+
"\n",
|
| 965 |
+
"if hand_data is not None and device_pose is not None:\n",
|
| 966 |
+
"\n",
|
| 967 |
+
" device_pose_extrinsic = device_pose[0]\n",
|
| 968 |
+
" device_pose_intrinsic = device_pose[1]\n",
|
| 969 |
+
"\n",
|
| 970 |
+
" # Visualize the image\n",
|
| 971 |
+
" plt.imshow(image_data, interpolation=\"nearest\")\n",
|
| 972 |
+
"\n",
|
| 973 |
+
" # For each possible hand pose (Left or Right)\n",
|
| 974 |
+
" # Project the vertices in the camera and plot the visible one\n",
|
| 975 |
+
" for hand_pose_data in hand_data.poses.values():\n",
|
| 976 |
+
" # Retrieve the hand vertices and project them on the image at this timestamp\n",
|
| 977 |
+
" # hand_mesh_vertices = hand_data_provider.get_hand_mesh_vertices(\n",
|
| 978 |
+
" # hand_pose_data\n",
|
| 979 |
+
" # ).tolist()\n",
|
| 980 |
+
"\n",
|
| 981 |
+
" # Use Landmarks\n",
|
| 982 |
+
" hand_landmarks = hand_data_provider.get_hand_landmarks(hand_pose_data)\n",
|
| 983 |
+
" # convert landmarks to connected lines for display\n",
|
| 984 |
+
" hand_mesh_vertices = np.array([])\n",
|
| 985 |
+
" for connectivity in LANDMARK_CONNECTIVITY:\n",
|
| 986 |
+
" connections = np.array([])\n",
|
| 987 |
+
" for it in connectivity:\n",
|
| 988 |
+
" if len(connections) == 0:\n",
|
| 989 |
+
" connections = [hand_landmarks[it].numpy()]\n",
|
| 990 |
+
" else:\n",
|
| 991 |
+
" connections = np.vstack((connections, hand_landmarks[it].numpy()))\n",
|
| 992 |
+
" if len(hand_mesh_vertices) == 0:\n",
|
| 993 |
+
" hand_mesh_vertices = connections\n",
|
| 994 |
+
" else:\n",
|
| 995 |
+
" hand_mesh_vertices = np.vstack((hand_mesh_vertices, connections))\n",
|
| 996 |
+
"\n",
|
| 997 |
+
" hand_vertices_in_camera = []\n",
|
| 998 |
+
" for vertex_in_world in hand_mesh_vertices:\n",
|
| 999 |
+
" vertice_3d_camera_coordinates = (\n",
|
| 1000 |
+
" device_pose_extrinsic.inverse() @ vertex_in_world\n",
|
| 1001 |
+
" )\n",
|
| 1002 |
+
" vertice_2d_camera_coordinates = device_pose_intrinsic.project(\n",
|
| 1003 |
+
" vertice_3d_camera_coordinates\n",
|
| 1004 |
+
" )\n",
|
| 1005 |
+
" if vertice_2d_camera_coordinates is not None:\n",
|
| 1006 |
+
" hand_vertices_in_camera.append(vertice_2d_camera_coordinates)\n",
|
| 1007 |
+
" handedness_label = hand_pose_data.handedness_label()\n",
|
| 1008 |
+
" print(\n",
|
| 1009 |
+
" f\"{handedness_label} hand -> visible vertices: {len(hand_vertices_in_camera)}\"\n",
|
| 1010 |
+
" )\n",
|
| 1011 |
+
"\n",
|
| 1012 |
+
" # Plot the hand vertices\n",
|
| 1013 |
+
" plt.scatter(\n",
|
| 1014 |
+
" x=[x[0] for x in hand_vertices_in_camera],\n",
|
| 1015 |
+
" y=[x[1] for x in hand_vertices_in_camera],\n",
|
| 1016 |
+
" s=1,\n",
|
| 1017 |
+
" c=\"r\" if hand_pose_data.handedness == Handedness.Right else \"b\",\n",
|
| 1018 |
+
" )\n",
|
| 1019 |
+
"\n",
|
| 1020 |
+
"plt.show()"
|
| 1021 |
+
]
|
| 1022 |
+
}
|
| 1023 |
+
],
|
| 1024 |
+
"metadata": {
|
| 1025 |
+
"kernelspec": {
|
| 1026 |
+
"display_name": "Python 3 (ipykernel)",
|
| 1027 |
+
"language": "python",
|
| 1028 |
+
"name": "python3"
|
| 1029 |
+
},
|
| 1030 |
+
"language_info": {
|
| 1031 |
+
"codemirror_mode": {
|
| 1032 |
+
"name": "ipython",
|
| 1033 |
+
"version": 3
|
| 1034 |
+
},
|
| 1035 |
+
"file_extension": ".py",
|
| 1036 |
+
"mimetype": "text/x-python",
|
| 1037 |
+
"name": "python",
|
| 1038 |
+
"nbconvert_exporter": "python",
|
| 1039 |
+
"pygments_lexer": "ipython3",
|
| 1040 |
+
"version": "3.10.0"
|
| 1041 |
+
}
|
| 1042 |
+
},
|
| 1043 |
+
"nbformat": 4,
|
| 1044 |
+
"nbformat_minor": 5
|
| 1045 |
+
}
|
HOT3DHUGGFACE/Hot3DVisualizer.py
ADDED
|
@@ -0,0 +1,593 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
from typing import Dict, List, Optional
|
| 16 |
+
|
| 17 |
+
import matplotlib.pyplot as plt
|
| 18 |
+
import numpy as np
|
| 19 |
+
import rerun as rr # @manual
|
| 20 |
+
from data_loaders.hand_common import LANDMARK_CONNECTIVITY
|
| 21 |
+
from data_loaders.headsets import Headset
|
| 22 |
+
from data_loaders.loader_hand_poses import HandType
|
| 23 |
+
from data_loaders.loader_object_library import ObjectLibrary
|
| 24 |
+
from projectaria_tools.core.stream_id import StreamId # @manual
|
| 25 |
+
|
| 26 |
+
try:
|
| 27 |
+
from dataset_api import Hot3dDataProvider # @manual
|
| 28 |
+
except ImportError:
|
| 29 |
+
from hot3d.dataset_api import Hot3dDataProvider
|
| 30 |
+
|
| 31 |
+
from data_loaders.HandDataProviderBase import ( # @manual
|
| 32 |
+
HandDataProviderBase,
|
| 33 |
+
HandPose3dCollectionWithDt,
|
| 34 |
+
)
|
| 35 |
+
from data_loaders.ObjectBox2dDataProvider import ( # @manual
|
| 36 |
+
ObjectBox2dCollectionWithDt,
|
| 37 |
+
ObjectBox2dProvider,
|
| 38 |
+
)
|
| 39 |
+
from data_loaders.ObjectPose3dProvider import ( # @manual
|
| 40 |
+
ObjectPose3dCollectionWithDt,
|
| 41 |
+
ObjectPose3dProvider,
|
| 42 |
+
)
|
| 43 |
+
from projectaria_tools.core.calibration import (
|
| 44 |
+
CameraCalibration,
|
| 45 |
+
DeviceCalibration,
|
| 46 |
+
FISHEYE624,
|
| 47 |
+
LINEAR,
|
| 48 |
+
)
|
| 49 |
+
from projectaria_tools.core.mps import get_eyegaze_point_at_depth # @manual
|
| 50 |
+
from projectaria_tools.core.mps.utils import ( # @manual
|
| 51 |
+
filter_points_from_confidence,
|
| 52 |
+
filter_points_from_count,
|
| 53 |
+
)
|
| 54 |
+
from projectaria_tools.core.sensor_data import TimeDomain, TimeQueryOptions # @manual
|
| 55 |
+
from projectaria_tools.core.sophus import SE3 # @manual
|
| 56 |
+
from projectaria_tools.utils.rerun_helpers import ( # @manual
|
| 57 |
+
AriaGlassesOutline,
|
| 58 |
+
ToTransform3D,
|
| 59 |
+
)
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
class Hot3DVisualizer:
|
| 63 |
+
def __init__(
|
| 64 |
+
self,
|
| 65 |
+
hot3d_data_provider: Hot3dDataProvider,
|
| 66 |
+
hand_type: HandType = HandType.Umetrack,
|
| 67 |
+
) -> None:
|
| 68 |
+
self._hot3d_data_provider = hot3d_data_provider
|
| 69 |
+
# Device calibration and Image stream data
|
| 70 |
+
self._device_data_provider = hot3d_data_provider.device_data_provider
|
| 71 |
+
# Data provider at time T (for device & objects & hand poses)
|
| 72 |
+
self._device_pose_provider = hot3d_data_provider.device_pose_data_provider
|
| 73 |
+
self._hand_data_provider = (
|
| 74 |
+
hot3d_data_provider.umetrack_hand_data_provider
|
| 75 |
+
if hand_type == HandType.Umetrack
|
| 76 |
+
else hot3d_data_provider.mano_hand_data_provider
|
| 77 |
+
)
|
| 78 |
+
if hand_type is HandType.Umetrack:
|
| 79 |
+
print("Hot3DVisualizer is using UMETRACK hand model")
|
| 80 |
+
elif hand_type is HandType.Mano:
|
| 81 |
+
print("Hot3DVisualizer is using MANO hand model")
|
| 82 |
+
self._object_pose_data_provider = hot3d_data_provider.object_pose_data_provider
|
| 83 |
+
self._object_box2d_data_provider = (
|
| 84 |
+
hot3d_data_provider.object_box2d_data_provider
|
| 85 |
+
)
|
| 86 |
+
# Object library
|
| 87 |
+
self._object_library = hot3d_data_provider.object_library
|
| 88 |
+
|
| 89 |
+
# If required
|
| 90 |
+
# Retrieve a distinct color mapping for object bounding box to show consistent color across stream_ids
|
| 91 |
+
# - Use a Colormap for visualizing object bounding box
|
| 92 |
+
self._object_box2d_colors = None
|
| 93 |
+
if self._object_box2d_data_provider is not None:
|
| 94 |
+
color_map = plt.get_cmap("viridis")
|
| 95 |
+
self._object_box2d_colors = color_map(
|
| 96 |
+
np.linspace(0, 1, len(self._object_box2d_data_provider.object_uids))
|
| 97 |
+
)
|
| 98 |
+
|
| 99 |
+
# Keep track of what 3D assets has been loaded/unloaded so we will load them only when needed
|
| 100 |
+
self._object_cache_status = {}
|
| 101 |
+
|
| 102 |
+
# To be parametrized later
|
| 103 |
+
self._jpeg_quality = 75
|
| 104 |
+
|
| 105 |
+
def log_static_assets(
|
| 106 |
+
self,
|
| 107 |
+
image_stream_ids: List[StreamId],
|
| 108 |
+
) -> None:
|
| 109 |
+
"""
|
| 110 |
+
Log all static assets (aka Timeless assets)
|
| 111 |
+
- assets that are immutable (but can still move if attached to a 3D Pose)
|
| 112 |
+
"""
|
| 113 |
+
|
| 114 |
+
# Configure the world coordinate system to ease navigation
|
| 115 |
+
if self._hot3d_data_provider.get_device_type() is Headset.Aria:
|
| 116 |
+
rr.log("world", rr.ViewCoordinates.RIGHT_HAND_Z_UP, static=True)
|
| 117 |
+
else:
|
| 118 |
+
rr.log("world", rr.ViewCoordinates.RIGHT_HAND_Y_UP, static=True)
|
| 119 |
+
|
| 120 |
+
if self._hot3d_data_provider.get_device_type() is Headset.Aria:
|
| 121 |
+
## for Aria devices, we use online calibration which is a dynamic asset
|
| 122 |
+
pass
|
| 123 |
+
elif self._hot3d_data_provider.get_device_type() is Headset.Quest3:
|
| 124 |
+
# For each of the stream ids we want to use, export the camera calibration (intrinsics and extrinsics)
|
| 125 |
+
for stream_id in image_stream_ids:
|
| 126 |
+
#
|
| 127 |
+
# Plot the camera configuration
|
| 128 |
+
[extrinsics, intrinsics] = (
|
| 129 |
+
self._device_data_provider.get_camera_calibration(stream_id)
|
| 130 |
+
)
|
| 131 |
+
Hot3DVisualizer.log_pose(
|
| 132 |
+
f"world/device/{stream_id}", extrinsics, static=True
|
| 133 |
+
)
|
| 134 |
+
Hot3DVisualizer.log_calibration(f"world/device/{stream_id}", intrinsics)
|
| 135 |
+
|
| 136 |
+
# Deal with Aria specifics
|
| 137 |
+
# - Glasses outline
|
| 138 |
+
# - Point cloud
|
| 139 |
+
if self._hot3d_data_provider.get_device_type() is Headset.Aria:
|
| 140 |
+
Hot3DVisualizer.log_aria_glasses(
|
| 141 |
+
"world/device/glasses_outline",
|
| 142 |
+
self._device_data_provider.get_device_calibration(),
|
| 143 |
+
)
|
| 144 |
+
|
| 145 |
+
# Point cloud (downsampled for visualization)
|
| 146 |
+
point_cloud = self._device_data_provider.get_point_cloud()
|
| 147 |
+
if point_cloud:
|
| 148 |
+
# Filter out low confidence points
|
| 149 |
+
threshold_invdep = 5e-4
|
| 150 |
+
threshold_dep = 5e-4
|
| 151 |
+
point_cloud = filter_points_from_confidence(
|
| 152 |
+
point_cloud, threshold_invdep, threshold_dep
|
| 153 |
+
)
|
| 154 |
+
# Down sample points
|
| 155 |
+
points_data_down_sampled = filter_points_from_count(
|
| 156 |
+
point_cloud, 500_000
|
| 157 |
+
)
|
| 158 |
+
# Retrieve point position
|
| 159 |
+
point_positions = [it.position_world for it in points_data_down_sampled]
|
| 160 |
+
POINT_COLOR = [200, 200, 200]
|
| 161 |
+
rr.log(
|
| 162 |
+
"world/points",
|
| 163 |
+
rr.Points3D(point_positions, colors=POINT_COLOR, radii=0.002),
|
| 164 |
+
static=True,
|
| 165 |
+
)
|
| 166 |
+
|
| 167 |
+
def log_dynamic_assets(
|
| 168 |
+
self,
|
| 169 |
+
stream_ids: List[StreamId],
|
| 170 |
+
timestamp_ns: int,
|
| 171 |
+
) -> None:
|
| 172 |
+
"""
|
| 173 |
+
Log dynamic assets:
|
| 174 |
+
I.e assets that are moving, such as:
|
| 175 |
+
- 3D assets
|
| 176 |
+
- Device pose
|
| 177 |
+
- Hands
|
| 178 |
+
- Object poses
|
| 179 |
+
- Image related specifics assets
|
| 180 |
+
- images (stream_ids)
|
| 181 |
+
- Object Bounding boxes
|
| 182 |
+
- Aria Eye Gaze
|
| 183 |
+
"""
|
| 184 |
+
|
| 185 |
+
#
|
| 186 |
+
## Retrieve and log data that is not stream_id dependent (pure 3D data)
|
| 187 |
+
#
|
| 188 |
+
acceptable_time_delta = 0
|
| 189 |
+
|
| 190 |
+
if self._hot3d_data_provider.get_device_type() is Headset.Aria:
|
| 191 |
+
# For each of the stream ids we want to use, export the camera calibration (intrinsics and extrinsics)
|
| 192 |
+
for stream_id in stream_ids:
|
| 193 |
+
#
|
| 194 |
+
# Plot the camera configuration
|
| 195 |
+
[extrinsics, intrinsics] = (
|
| 196 |
+
self._device_data_provider.get_online_camera_calibration(
|
| 197 |
+
stream_id=stream_id, timestamp_ns=timestamp_ns
|
| 198 |
+
)
|
| 199 |
+
)
|
| 200 |
+
Hot3DVisualizer.log_pose(f"world/device/{stream_id}", extrinsics)
|
| 201 |
+
Hot3DVisualizer.log_calibration(f"world/device/{stream_id}", intrinsics)
|
| 202 |
+
|
| 203 |
+
elif self._hot3d_data_provider.get_device_type() is Headset.Quest3:
|
| 204 |
+
## for Quest devices we will use factory calibration which is a static asset
|
| 205 |
+
pass
|
| 206 |
+
|
| 207 |
+
headset_pose3d_with_dt = None
|
| 208 |
+
if self._device_data_provider is not None:
|
| 209 |
+
headset_pose3d_with_dt = self._device_pose_provider.get_pose_at_timestamp(
|
| 210 |
+
timestamp_ns=timestamp_ns,
|
| 211 |
+
time_query_options=TimeQueryOptions.CLOSEST,
|
| 212 |
+
time_domain=TimeDomain.TIME_CODE,
|
| 213 |
+
acceptable_time_delta=acceptable_time_delta,
|
| 214 |
+
)
|
| 215 |
+
|
| 216 |
+
hand_poses_with_dt = None
|
| 217 |
+
if self._hand_data_provider is not None:
|
| 218 |
+
hand_poses_with_dt = self._hand_data_provider.get_pose_at_timestamp(
|
| 219 |
+
timestamp_ns=timestamp_ns,
|
| 220 |
+
time_query_options=TimeQueryOptions.CLOSEST,
|
| 221 |
+
time_domain=TimeDomain.TIME_CODE,
|
| 222 |
+
acceptable_time_delta=acceptable_time_delta,
|
| 223 |
+
)
|
| 224 |
+
|
| 225 |
+
object_poses_with_dt = None
|
| 226 |
+
if self._object_pose_data_provider is not None:
|
| 227 |
+
object_poses_with_dt = (
|
| 228 |
+
self._object_pose_data_provider.get_pose_at_timestamp(
|
| 229 |
+
timestamp_ns=timestamp_ns,
|
| 230 |
+
time_query_options=TimeQueryOptions.CLOSEST,
|
| 231 |
+
time_domain=TimeDomain.TIME_CODE,
|
| 232 |
+
acceptable_time_delta=acceptable_time_delta,
|
| 233 |
+
)
|
| 234 |
+
)
|
| 235 |
+
|
| 236 |
+
aria_eye_gaze_data = (
|
| 237 |
+
self._device_data_provider.get_eye_gaze(timestamp_ns)
|
| 238 |
+
if self._hot3d_data_provider.get_device_type() is Headset.Aria
|
| 239 |
+
else None
|
| 240 |
+
)
|
| 241 |
+
|
| 242 |
+
#
|
| 243 |
+
## Log Device pose
|
| 244 |
+
#
|
| 245 |
+
if headset_pose3d_with_dt is not None:
|
| 246 |
+
headset_pose3d = headset_pose3d_with_dt.pose3d
|
| 247 |
+
Hot3DVisualizer.log_pose(
|
| 248 |
+
"world/device", headset_pose3d.T_world_device, static=False
|
| 249 |
+
)
|
| 250 |
+
|
| 251 |
+
#
|
| 252 |
+
## Log Hand poses
|
| 253 |
+
#
|
| 254 |
+
Hot3DVisualizer.log_hands(
|
| 255 |
+
"world/hands", # /{handedness_label}/... will be added as necessary
|
| 256 |
+
self._hand_data_provider,
|
| 257 |
+
hand_poses_with_dt,
|
| 258 |
+
show_hand_mesh=True,
|
| 259 |
+
show_hand_vertices=False,
|
| 260 |
+
show_hand_landmarks=False,
|
| 261 |
+
)
|
| 262 |
+
|
| 263 |
+
#
|
| 264 |
+
## Log Object poses
|
| 265 |
+
#
|
| 266 |
+
Hot3DVisualizer.log_object_poses(
|
| 267 |
+
"world/objects",
|
| 268 |
+
object_poses_with_dt,
|
| 269 |
+
self._object_pose_data_provider,
|
| 270 |
+
self._object_library,
|
| 271 |
+
self._object_cache_status,
|
| 272 |
+
)
|
| 273 |
+
|
| 274 |
+
#
|
| 275 |
+
## Log stream dependent data
|
| 276 |
+
#
|
| 277 |
+
for stream_id in stream_ids:
|
| 278 |
+
#
|
| 279 |
+
## Log Image data
|
| 280 |
+
#
|
| 281 |
+
|
| 282 |
+
# Undistorted image (required if you want see reprojected 3D mesh on the images)
|
| 283 |
+
image_data = self._device_data_provider.get_undistorted_image(
|
| 284 |
+
timestamp_ns, stream_id
|
| 285 |
+
)
|
| 286 |
+
if image_data is not None:
|
| 287 |
+
rr.log(
|
| 288 |
+
f"world/device/{stream_id}",
|
| 289 |
+
rr.Image(image_data).compress(jpeg_quality=self._jpeg_quality),
|
| 290 |
+
)
|
| 291 |
+
|
| 292 |
+
# Raw device images (required for object bounding box visualization)
|
| 293 |
+
image_data = self._device_data_provider.get_image(timestamp_ns, stream_id)
|
| 294 |
+
if image_data is not None:
|
| 295 |
+
rr.log(
|
| 296 |
+
f"world/device/{stream_id}_raw",
|
| 297 |
+
rr.Image(image_data).compress(jpeg_quality=self._jpeg_quality),
|
| 298 |
+
)
|
| 299 |
+
|
| 300 |
+
if (
|
| 301 |
+
self._object_box2d_data_provider is not None
|
| 302 |
+
and stream_id in self._object_box2d_data_provider.stream_ids
|
| 303 |
+
):
|
| 304 |
+
box2d_collection_with_dt = (
|
| 305 |
+
self._object_box2d_data_provider.get_bbox_at_timestamp(
|
| 306 |
+
stream_id=stream_id,
|
| 307 |
+
timestamp_ns=timestamp_ns,
|
| 308 |
+
time_query_options=TimeQueryOptions.CLOSEST,
|
| 309 |
+
time_domain=TimeDomain.TIME_CODE,
|
| 310 |
+
)
|
| 311 |
+
)
|
| 312 |
+
Hot3DVisualizer.log_object_bounding_boxes(
|
| 313 |
+
stream_id,
|
| 314 |
+
box2d_collection_with_dt,
|
| 315 |
+
self._object_box2d_data_provider,
|
| 316 |
+
self._object_library,
|
| 317 |
+
self._object_box2d_colors,
|
| 318 |
+
)
|
| 319 |
+
|
| 320 |
+
#
|
| 321 |
+
## Eye Gaze image reprojection
|
| 322 |
+
#
|
| 323 |
+
if self._hot3d_data_provider.get_device_type() is Headset.Aria:
|
| 324 |
+
# We are showing EyeGaze reprojection only on the RGB image stream
|
| 325 |
+
if stream_id != StreamId("214-1"):
|
| 326 |
+
continue
|
| 327 |
+
|
| 328 |
+
# Reproject EyeGaze for raw and pinhole images
|
| 329 |
+
camera_configurations = [FISHEYE624, LINEAR]
|
| 330 |
+
for camera_model in camera_configurations:
|
| 331 |
+
eye_gaze_reprojection_data = (
|
| 332 |
+
self._device_data_provider.get_eye_gaze_in_camera(
|
| 333 |
+
stream_id, timestamp_ns, camera_model=camera_model
|
| 334 |
+
)
|
| 335 |
+
)
|
| 336 |
+
if (
|
| 337 |
+
eye_gaze_reprojection_data is None
|
| 338 |
+
or not eye_gaze_reprojection_data.any()
|
| 339 |
+
):
|
| 340 |
+
continue
|
| 341 |
+
|
| 342 |
+
label = (
|
| 343 |
+
f"world/device/{stream_id}/eye-gaze_projection"
|
| 344 |
+
if camera_model == LINEAR
|
| 345 |
+
else f"world/device/{stream_id}_raw/eye-gaze_projection_raw"
|
| 346 |
+
)
|
| 347 |
+
rr.log(
|
| 348 |
+
label,
|
| 349 |
+
rr.Points2D(eye_gaze_reprojection_data, radii=20),
|
| 350 |
+
# TODO consistent color and size depending of camera resolution
|
| 351 |
+
)
|
| 352 |
+
#
|
| 353 |
+
## Log device dependent remaining 3D data
|
| 354 |
+
#
|
| 355 |
+
|
| 356 |
+
# Log 3D eye gaze
|
| 357 |
+
if aria_eye_gaze_data is not None:
|
| 358 |
+
T_device_CPF = self._device_data_provider.get_device_calibration().get_transform_device_cpf()
|
| 359 |
+
# Compute eye_gaze vector at depth_m (30cm for a proxy 3D vector to display)
|
| 360 |
+
gaze_vector_in_cpf = get_eyegaze_point_at_depth(
|
| 361 |
+
aria_eye_gaze_data.yaw, aria_eye_gaze_data.pitch, depth_m=0.3
|
| 362 |
+
)
|
| 363 |
+
# Draw EyeGaze vector
|
| 364 |
+
rr.log(
|
| 365 |
+
"world/device/eye-gaze",
|
| 366 |
+
rr.Arrows3D(
|
| 367 |
+
origins=[T_device_CPF @ [0, 0, 0]],
|
| 368 |
+
vectors=[
|
| 369 |
+
T_device_CPF @ gaze_vector_in_cpf - T_device_CPF @ [0, 0, 0]
|
| 370 |
+
],
|
| 371 |
+
),
|
| 372 |
+
)
|
| 373 |
+
|
| 374 |
+
@staticmethod
|
| 375 |
+
def log_aria_glasses(
|
| 376 |
+
label: str,
|
| 377 |
+
device_calibration: DeviceCalibration,
|
| 378 |
+
use_cad_calibration: bool = True,
|
| 379 |
+
) -> None:
|
| 380 |
+
## Plot Project Aria Glasses outline (as lines)
|
| 381 |
+
aria_glasses_point_outline = AriaGlassesOutline(
|
| 382 |
+
device_calibration, use_cad_calibration
|
| 383 |
+
)
|
| 384 |
+
rr.log(label, rr.LineStrips3D([aria_glasses_point_outline]), static=True)
|
| 385 |
+
|
| 386 |
+
@staticmethod
|
| 387 |
+
def log_calibration(
|
| 388 |
+
label: str,
|
| 389 |
+
camera_calibration: CameraCalibration,
|
| 390 |
+
) -> None:
|
| 391 |
+
rr.log(
|
| 392 |
+
label,
|
| 393 |
+
rr.Pinhole(
|
| 394 |
+
resolution=[
|
| 395 |
+
camera_calibration.get_image_size()[0],
|
| 396 |
+
camera_calibration.get_image_size()[1],
|
| 397 |
+
],
|
| 398 |
+
focal_length=float(camera_calibration.get_focal_lengths()[0]),
|
| 399 |
+
),
|
| 400 |
+
static=True,
|
| 401 |
+
)
|
| 402 |
+
|
| 403 |
+
@staticmethod
|
| 404 |
+
def log_pose(label: str, pose: SE3, static=False) -> None:
|
| 405 |
+
rr.log(label, ToTransform3D(pose, False), static=static)
|
| 406 |
+
|
| 407 |
+
@staticmethod
|
| 408 |
+
def log_hands(
|
| 409 |
+
label: str,
|
| 410 |
+
hand_data_provider: HandDataProviderBase,
|
| 411 |
+
hand_poses_with_dt: HandPose3dCollectionWithDt,
|
| 412 |
+
show_hand_mesh=True,
|
| 413 |
+
show_hand_vertices=True,
|
| 414 |
+
show_hand_landmarks=True,
|
| 415 |
+
):
|
| 416 |
+
logged_right_hand_data = False
|
| 417 |
+
logged_left_hand_data = False
|
| 418 |
+
if hand_poses_with_dt is None:
|
| 419 |
+
return
|
| 420 |
+
|
| 421 |
+
hand_pose_collection = hand_poses_with_dt.pose3d_collection
|
| 422 |
+
|
| 423 |
+
for hand_pose_data in hand_pose_collection.poses.values():
|
| 424 |
+
if hand_pose_data.is_left_hand():
|
| 425 |
+
logged_left_hand_data = True
|
| 426 |
+
elif hand_pose_data.is_right_hand():
|
| 427 |
+
logged_right_hand_data = True
|
| 428 |
+
|
| 429 |
+
handedness_label = hand_pose_data.handedness_label()
|
| 430 |
+
|
| 431 |
+
# Skeleton/Joints landmark representation
|
| 432 |
+
if show_hand_landmarks:
|
| 433 |
+
hand_landmarks = hand_data_provider.get_hand_landmarks(hand_pose_data)
|
| 434 |
+
# convert landmarks to connected lines for display
|
| 435 |
+
# (i.e retrieve points along the HAND LANDMARK_CONNECTIVITY as a list)
|
| 436 |
+
points = [
|
| 437 |
+
connections
|
| 438 |
+
for connectivity in LANDMARK_CONNECTIVITY
|
| 439 |
+
for connections in [
|
| 440 |
+
[hand_landmarks[it].numpy().tolist() for it in connectivity]
|
| 441 |
+
]
|
| 442 |
+
]
|
| 443 |
+
rr.log(
|
| 444 |
+
f"{label}/{handedness_label}/joints",
|
| 445 |
+
rr.LineStrips3D(points, radii=0.002),
|
| 446 |
+
)
|
| 447 |
+
|
| 448 |
+
# Update mesh vertices if required
|
| 449 |
+
hand_mesh_vertices = (
|
| 450 |
+
hand_data_provider.get_hand_mesh_vertices(hand_pose_data)
|
| 451 |
+
if show_hand_vertices or show_hand_mesh
|
| 452 |
+
else None
|
| 453 |
+
)
|
| 454 |
+
|
| 455 |
+
# Vertices representation
|
| 456 |
+
if show_hand_vertices:
|
| 457 |
+
rr.log(
|
| 458 |
+
f"{label}/{handedness_label}/mesh",
|
| 459 |
+
rr.Points3D(hand_mesh_vertices),
|
| 460 |
+
)
|
| 461 |
+
|
| 462 |
+
# Triangular Mesh representation
|
| 463 |
+
if show_hand_mesh:
|
| 464 |
+
[hand_triangles, hand_vertex_normals] = (
|
| 465 |
+
hand_data_provider.get_hand_mesh_faces_and_normals(hand_pose_data)
|
| 466 |
+
)
|
| 467 |
+
rr.log(
|
| 468 |
+
f"{label}/{handedness_label}/mesh_faces",
|
| 469 |
+
rr.Mesh3D(
|
| 470 |
+
vertex_positions=hand_mesh_vertices,
|
| 471 |
+
vertex_normals=hand_vertex_normals,
|
| 472 |
+
triangle_indices=hand_triangles, # TODO: we could avoid sending this list if we want to save memory
|
| 473 |
+
),
|
| 474 |
+
)
|
| 475 |
+
# If some hand data has not been logged, do not show it in the visualizer
|
| 476 |
+
if logged_left_hand_data is False:
|
| 477 |
+
rr.log(f"{label}/left", rr.Clear.recursive())
|
| 478 |
+
if logged_right_hand_data is False:
|
| 479 |
+
rr.log(f"{label}/right", rr.Clear.recursive())
|
| 480 |
+
|
| 481 |
+
@staticmethod
|
| 482 |
+
def log_object_poses(
|
| 483 |
+
label: str, # "world/objects",
|
| 484 |
+
object_poses_with_dt: ObjectPose3dCollectionWithDt,
|
| 485 |
+
object_pose_data_provider: ObjectPose3dProvider,
|
| 486 |
+
object_library: ObjectLibrary,
|
| 487 |
+
object_cache_status: Dict[int, bool],
|
| 488 |
+
):
|
| 489 |
+
if object_poses_with_dt is None:
|
| 490 |
+
return
|
| 491 |
+
|
| 492 |
+
objects_pose3d_collection = object_poses_with_dt.pose3d_collection
|
| 493 |
+
|
| 494 |
+
# Keep a mapping to know what object has been seen, and which one has not
|
| 495 |
+
object_uids = object_pose_data_provider.object_uids_with_poses
|
| 496 |
+
logging_status = {x: False for x in object_uids}
|
| 497 |
+
|
| 498 |
+
for (
|
| 499 |
+
object_uid,
|
| 500 |
+
object_pose3d,
|
| 501 |
+
) in objects_pose3d_collection.poses.items():
|
| 502 |
+
object_name = object_library.object_id_to_name_dict[object_uid]
|
| 503 |
+
object_name = object_name + "_" + str(object_uid)
|
| 504 |
+
object_cad_asset_filepath = ObjectLibrary.get_cad_asset_path(
|
| 505 |
+
object_library_folderpath=object_library.asset_folder_name,
|
| 506 |
+
object_id=object_uid,
|
| 507 |
+
)
|
| 508 |
+
|
| 509 |
+
Hot3DVisualizer.log_pose(
|
| 510 |
+
f"world/objects/{object_name}",
|
| 511 |
+
object_pose3d.T_world_object,
|
| 512 |
+
False,
|
| 513 |
+
)
|
| 514 |
+
# Mark object has been seen
|
| 515 |
+
logging_status[object_uid] = True
|
| 516 |
+
|
| 517 |
+
# Link the corresponding 3D object
|
| 518 |
+
if object_uid not in object_cache_status.keys():
|
| 519 |
+
object_cache_status[object_uid] = True
|
| 520 |
+
rr.log(
|
| 521 |
+
f"world/objects/{object_name}",
|
| 522 |
+
rr.Asset3D(
|
| 523 |
+
path=object_cad_asset_filepath,
|
| 524 |
+
),
|
| 525 |
+
)
|
| 526 |
+
|
| 527 |
+
# If some object are not visible, we clear the entity (last known mesh and pose will not be displayed)
|
| 528 |
+
for object_uid, displayed in logging_status.items():
|
| 529 |
+
if not displayed:
|
| 530 |
+
object_name = object_library.object_id_to_name_dict[object_uid]
|
| 531 |
+
object_name = object_name + "_" + str(object_uid)
|
| 532 |
+
rr.log(
|
| 533 |
+
f"world/objects/{object_name}",
|
| 534 |
+
rr.Clear.recursive(),
|
| 535 |
+
)
|
| 536 |
+
if object_uid in object_cache_status.keys():
|
| 537 |
+
del object_cache_status[object_uid] # We will log the mesh again
|
| 538 |
+
|
| 539 |
+
@staticmethod
|
| 540 |
+
def log_object_bounding_boxes(
|
| 541 |
+
stream_id: StreamId,
|
| 542 |
+
box2d_collection_with_dt: Optional[ObjectBox2dCollectionWithDt],
|
| 543 |
+
object_box2d_data_provider: ObjectBox2dProvider,
|
| 544 |
+
object_library: ObjectLibrary,
|
| 545 |
+
bbox_colors: np.ndarray,
|
| 546 |
+
):
|
| 547 |
+
"""
|
| 548 |
+
Object bounding boxes (valid for native raw images).
|
| 549 |
+
- We assume that the image corresponding to the stream_id has been logged beforehand as 'world/device/{stream_id}_raw/'
|
| 550 |
+
"""
|
| 551 |
+
|
| 552 |
+
# Keep a mapping to know what object has been seen, and which one has not
|
| 553 |
+
object_uids = list(object_box2d_data_provider.object_uids)
|
| 554 |
+
logging_status = {x: False for x in object_uids}
|
| 555 |
+
|
| 556 |
+
if (
|
| 557 |
+
box2d_collection_with_dt is None
|
| 558 |
+
or box2d_collection_with_dt.box2d_collection is None
|
| 559 |
+
):
|
| 560 |
+
# No bounding box are retrieved, we clear all the bounding box visualization existing so far
|
| 561 |
+
rr.log(f"world/device/{stream_id}_raw/bbox", rr.Clear.recursive())
|
| 562 |
+
return
|
| 563 |
+
|
| 564 |
+
object_uids_at_query_timestamp = (
|
| 565 |
+
box2d_collection_with_dt.box2d_collection.object_uid_list
|
| 566 |
+
)
|
| 567 |
+
|
| 568 |
+
for object_uid in object_uids_at_query_timestamp:
|
| 569 |
+
object_name = object_library.object_id_to_name_dict[object_uid]
|
| 570 |
+
axis_aligned_box2d = box2d_collection_with_dt.box2d_collection.box2ds[
|
| 571 |
+
object_uid
|
| 572 |
+
]
|
| 573 |
+
box = axis_aligned_box2d.box2d
|
| 574 |
+
if box is None:
|
| 575 |
+
continue
|
| 576 |
+
|
| 577 |
+
logging_status[object_uid] = True
|
| 578 |
+
rr.log(
|
| 579 |
+
f"world/device/{stream_id}_raw/bbox/{object_name}",
|
| 580 |
+
rr.Boxes2D(
|
| 581 |
+
mins=[box.left, box.top],
|
| 582 |
+
sizes=[box.width, box.height],
|
| 583 |
+
colors=bbox_colors[object_uids.index(object_uid)],
|
| 584 |
+
),
|
| 585 |
+
)
|
| 586 |
+
# If some object are not visible, we clear the bounding box visualization
|
| 587 |
+
for key, value in logging_status.items():
|
| 588 |
+
if not value:
|
| 589 |
+
object_name = object_library.object_id_to_name_dict[key]
|
| 590 |
+
rr.log(
|
| 591 |
+
f"world/device/{stream_id}_raw/bbox/{object_name}",
|
| 592 |
+
rr.Clear.flat(),
|
| 593 |
+
)
|
HOT3DHUGGFACE/data_loaders/AlignedBox2d.py
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
from __future__ import annotations
|
| 16 |
+
|
| 17 |
+
import numpy as np
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
class AlignedBox2d:
|
| 21 |
+
"""
|
| 22 |
+
An 2D axis aligned box in floating point.
|
| 23 |
+
|
| 24 |
+
Assumptions:
|
| 25 |
+
* The origin is at top-left corner
|
| 26 |
+
* `right` and `bottom` are not inclusive in the region, i.e. the width and
|
| 27 |
+
height can be simply calculated by `right - left` and `bottom - top`.
|
| 28 |
+
"""
|
| 29 |
+
|
| 30 |
+
def __init__(self, left: float, top: float, right: float, bottom: float):
|
| 31 |
+
"""Initializes the bounding box given (left, top, right, bottom)"""
|
| 32 |
+
self._left: float = left
|
| 33 |
+
self._top: float = top
|
| 34 |
+
self._right: float = right
|
| 35 |
+
self._bottom: float = bottom
|
| 36 |
+
|
| 37 |
+
def __repr__(self):
|
| 38 |
+
return f"AlignedBox2d(left: {self._left}, top: {self._top}, right: {self._right}, bottom: {self._bottom})"
|
| 39 |
+
|
| 40 |
+
@property
|
| 41 |
+
def left(self) -> float:
|
| 42 |
+
"""Left of the aligned box on x-axis."""
|
| 43 |
+
return self._left
|
| 44 |
+
|
| 45 |
+
@property
|
| 46 |
+
def top(self) -> float:
|
| 47 |
+
"""Top of the aligned box on y-axis."""
|
| 48 |
+
return self._top
|
| 49 |
+
|
| 50 |
+
@property
|
| 51 |
+
def right(self) -> float:
|
| 52 |
+
"""Right of the aligned box on x-axis."""
|
| 53 |
+
return self._right
|
| 54 |
+
|
| 55 |
+
@property
|
| 56 |
+
def bottom(self) -> float:
|
| 57 |
+
"""Bottom of the aligned box on y-axis."""
|
| 58 |
+
return self._bottom
|
| 59 |
+
|
| 60 |
+
@property
|
| 61 |
+
def width(self) -> float:
|
| 62 |
+
"""Width of the aligned box.
|
| 63 |
+
|
| 64 |
+
Returns:
|
| 65 |
+
Width computed by right - left
|
| 66 |
+
"""
|
| 67 |
+
return self.right - self.left
|
| 68 |
+
|
| 69 |
+
@property
|
| 70 |
+
def height(self) -> float:
|
| 71 |
+
"""Height of the aligned box.
|
| 72 |
+
|
| 73 |
+
Returns:
|
| 74 |
+
Height computed by bottom - top
|
| 75 |
+
"""
|
| 76 |
+
return self.bottom - self.top
|
| 77 |
+
|
| 78 |
+
def pad(self, width: float, height: float) -> AlignedBox2d:
|
| 79 |
+
"""Pads the region by extending `width` and `height` on four sides.
|
| 80 |
+
|
| 81 |
+
Args:
|
| 82 |
+
width (float): length to pad on left and right sides
|
| 83 |
+
height (float): length to pad on top and bottom sides
|
| 84 |
+
Returns:
|
| 85 |
+
a new AlignedBox2d object with padded region
|
| 86 |
+
"""
|
| 87 |
+
return AlignedBox2d(
|
| 88 |
+
self.left - width,
|
| 89 |
+
self.top - height,
|
| 90 |
+
self.right + width,
|
| 91 |
+
self.bottom + height,
|
| 92 |
+
)
|
| 93 |
+
|
| 94 |
+
def array_ltrb(self) -> np.ndarray:
|
| 95 |
+
"""Converts the box into a float np.ndarray of shape (4,): (left, top, right, bottom).
|
| 96 |
+
|
| 97 |
+
Returns:
|
| 98 |
+
a float np.ndarray of shape (4,) representing (left, top, right, bottom)
|
| 99 |
+
"""
|
| 100 |
+
return np.array([self.left, self.top, self.right, self.bottom])
|
| 101 |
+
|
| 102 |
+
def array_ltwh(self) -> np.ndarray:
|
| 103 |
+
"""Converts the box into a float np.ndarray of shape (4,): (left, top, width, height).
|
| 104 |
+
|
| 105 |
+
Returns:
|
| 106 |
+
a float np.ndarray of shape (4,) representing (left, top, width, height)
|
| 107 |
+
"""
|
| 108 |
+
return np.array([self.left, self.top, self.width, self.height])
|
| 109 |
+
|
| 110 |
+
def int_array_ltrb(self) -> np.ndarray:
|
| 111 |
+
"""Converts the box into an int np.ndarray of shape (4,): (left, top, width, height).
|
| 112 |
+
|
| 113 |
+
Returns:
|
| 114 |
+
an int np.ndarray of shape (4,) representing (left, top, right, bottom)
|
| 115 |
+
"""
|
| 116 |
+
return self.array_ltrb().astype(int)
|
| 117 |
+
|
| 118 |
+
def int_array_ltwh(self) -> np.ndarray:
|
| 119 |
+
"""Converts the box into an int np.ndarray of shape (4,): (left, top, width, height).
|
| 120 |
+
|
| 121 |
+
Returns:
|
| 122 |
+
an int np.ndarray of shape (4,) representing (left, top, width, height)
|
| 123 |
+
"""
|
| 124 |
+
return self.array_ltwh().astype(int)
|
| 125 |
+
|
| 126 |
+
def round(self) -> AlignedBox2d:
|
| 127 |
+
"""Rounds the float values to int.
|
| 128 |
+
|
| 129 |
+
Returns:
|
| 130 |
+
a new AlignedBox2d object with rounded values (still float)
|
| 131 |
+
"""
|
| 132 |
+
return AlignedBox2d(
|
| 133 |
+
np.round(self.left),
|
| 134 |
+
np.round(self.top),
|
| 135 |
+
np.round(self.right),
|
| 136 |
+
np.round(self.bottom),
|
| 137 |
+
)
|
| 138 |
+
|
| 139 |
+
def clip(self, boundary: AlignedBox2d) -> AlignedBox2d:
|
| 140 |
+
"""Clips the region by the boundary
|
| 141 |
+
|
| 142 |
+
Args:
|
| 143 |
+
boundary (AlignedBox2d): boundary of box to be clipped
|
| 144 |
+
(boundary.left: minimum left / right value,
|
| 145 |
+
boundary.top: minimum top / bottom value,
|
| 146 |
+
boundary.right: maximum left / right value,
|
| 147 |
+
boundary.bottom: maximum top / bottom value)
|
| 148 |
+
Returns:
|
| 149 |
+
a new clipped AlignedBox2d object
|
| 150 |
+
"""
|
| 151 |
+
return AlignedBox2d(
|
| 152 |
+
min(max(self.left, boundary.left), boundary.right),
|
| 153 |
+
min(max(self.top, boundary.top), boundary.bottom),
|
| 154 |
+
min(max(self.right, boundary.left), boundary.right),
|
| 155 |
+
min(max(self.bottom, boundary.top), boundary.bottom),
|
| 156 |
+
)
|
HOT3DHUGGFACE/data_loaders/AriaDataProvider.py
ADDED
|
@@ -0,0 +1,377 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
import os
|
| 16 |
+
from typing import Dict, List, Optional
|
| 17 |
+
|
| 18 |
+
import numpy as np
|
| 19 |
+
from data_loaders.frameset import compute_frameset_for_timestamp
|
| 20 |
+
from projectaria_tools.core import data_provider # @manual
|
| 21 |
+
from projectaria_tools.core.calibration import ( # @manual
|
| 22 |
+
CameraCalibration,
|
| 23 |
+
DeviceCalibration,
|
| 24 |
+
distort_by_calibration,
|
| 25 |
+
FISHEYE624,
|
| 26 |
+
get_linear_camera_calibration,
|
| 27 |
+
LINEAR,
|
| 28 |
+
)
|
| 29 |
+
from projectaria_tools.core.mps import ( # @manual
|
| 30 |
+
EyeGaze,
|
| 31 |
+
get_eyegaze_point_at_depth,
|
| 32 |
+
MpsDataPathsProvider,
|
| 33 |
+
MpsDataProvider,
|
| 34 |
+
)
|
| 35 |
+
from projectaria_tools.core.sensor_data import TimeDomain, TimeQueryOptions # @manual
|
| 36 |
+
from projectaria_tools.core.sophus import SE3 # @manual
|
| 37 |
+
from projectaria_tools.core.stream_id import StreamId # @manual
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
class AriaDataProvider:
|
| 41 |
+
def __init__(
|
| 42 |
+
self, vrs_filepath: str, mps_folder_path: Optional[str] = None
|
| 43 |
+
) -> None:
|
| 44 |
+
self._vrs_data_provider = data_provider.create_vrs_data_provider(vrs_filepath)
|
| 45 |
+
|
| 46 |
+
# MPS data provider
|
| 47 |
+
if mps_folder_path is not None and os.path.exists(mps_folder_path):
|
| 48 |
+
mps_data_paths_provider = MpsDataPathsProvider(mps_folder_path)
|
| 49 |
+
mps_data_paths = mps_data_paths_provider.get_data_paths()
|
| 50 |
+
self._mps_data_provider = MpsDataProvider(mps_data_paths)
|
| 51 |
+
print(mps_data_paths)
|
| 52 |
+
else:
|
| 53 |
+
self._mps_data_provider = None
|
| 54 |
+
|
| 55 |
+
# Pre-compute the sorted timestamps for each stream
|
| 56 |
+
self._stream_timestamps_sorted: Dict[str, List[int]] = {}
|
| 57 |
+
for stream_id in self.get_image_stream_ids():
|
| 58 |
+
self._stream_timestamps_sorted[str(stream_id)] = sorted(
|
| 59 |
+
self.get_sequence_timestamps(stream_id, TimeDomain.TIME_CODE)
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
+
def get_image_stream_ids(self) -> List[StreamId]:
|
| 63 |
+
# retrieve all streams ids and filter the one that are image based
|
| 64 |
+
stream_ids = self._vrs_data_provider.get_all_streams()
|
| 65 |
+
image_stream_ids = [
|
| 66 |
+
p
|
| 67 |
+
for p in stream_ids
|
| 68 |
+
if self._vrs_data_provider.get_label_from_stream_id(p).startswith("camera-")
|
| 69 |
+
]
|
| 70 |
+
return image_stream_ids
|
| 71 |
+
|
| 72 |
+
def get_sequence_timestamps(
|
| 73 |
+
self,
|
| 74 |
+
stream_id: StreamId = StreamId("214-1"),
|
| 75 |
+
time_domain: TimeDomain = TimeDomain.TIME_CODE,
|
| 76 |
+
) -> List[int]:
|
| 77 |
+
"""
|
| 78 |
+
Returns the list of "time code" timestamp for the sequence
|
| 79 |
+
"""
|
| 80 |
+
return self._vrs_data_provider.get_timestamps_ns(stream_id, time_domain)
|
| 81 |
+
|
| 82 |
+
def get_frameset_from_timestamp(
|
| 83 |
+
self,
|
| 84 |
+
timestamp_ns: int,
|
| 85 |
+
frameset_acceptable_time_diff_ns: int,
|
| 86 |
+
time_domain: TimeDomain = TimeDomain.TIME_CODE,
|
| 87 |
+
) -> Dict[str, Optional[int]]:
|
| 88 |
+
"""
|
| 89 |
+
Computes a frameset from a given timestamp within an acceptable time difference.
|
| 90 |
+
The frameset consists of the closest timestamps for each stream that are within the acceptable time difference.
|
| 91 |
+
For Aria, the recommended acceptable time difference is 1e6 ns (or 1ms).
|
| 92 |
+
Returns a dictionary mapping each str(StreamId) to its closest timestamp.
|
| 93 |
+
"""
|
| 94 |
+
if time_domain is not TimeDomain.TIME_CODE:
|
| 95 |
+
raise ValueError(
|
| 96 |
+
f"{time_domain} is not supported. Only TIME_CODE is supported"
|
| 97 |
+
)
|
| 98 |
+
out_frameset = compute_frameset_for_timestamp(
|
| 99 |
+
stream_timestamps_sorted=self._stream_timestamps_sorted,
|
| 100 |
+
target_timestamp=timestamp_ns,
|
| 101 |
+
frameset_acceptable_time_diff=frameset_acceptable_time_diff_ns,
|
| 102 |
+
)
|
| 103 |
+
return out_frameset
|
| 104 |
+
|
| 105 |
+
def get_image_stream_label(self, stream_id: StreamId) -> str:
|
| 106 |
+
return self._vrs_data_provider.get_label_from_stream_id(stream_id)
|
| 107 |
+
|
| 108 |
+
def get_image(self, timestamp_ns: int, stream_id: StreamId) -> np.ndarray:
|
| 109 |
+
image = self._vrs_data_provider.get_image_data_by_time_ns(
|
| 110 |
+
stream_id,
|
| 111 |
+
timestamp_ns,
|
| 112 |
+
TimeDomain.TIME_CODE,
|
| 113 |
+
TimeQueryOptions.CLOSEST,
|
| 114 |
+
)
|
| 115 |
+
return image[0].to_numpy_array() if image is not None else None
|
| 116 |
+
|
| 117 |
+
def get_undistorted_image(
|
| 118 |
+
self, timestamp_ns: int, stream_id: StreamId
|
| 119 |
+
) -> np.ndarray:
|
| 120 |
+
image = self.get_image(timestamp_ns, stream_id)
|
| 121 |
+
|
| 122 |
+
[T_device_camera, native_camera_online_calibration] = (
|
| 123 |
+
self.get_online_camera_calibration(
|
| 124 |
+
stream_id, timestamp_ns=timestamp_ns, camera_model=FISHEYE624
|
| 125 |
+
)
|
| 126 |
+
)
|
| 127 |
+
[T_device_camera, pinhole_camera_online_calibration] = (
|
| 128 |
+
self.get_online_camera_calibration(
|
| 129 |
+
stream_id, timestamp_ns=timestamp_ns, camera_model=LINEAR
|
| 130 |
+
)
|
| 131 |
+
)
|
| 132 |
+
|
| 133 |
+
# Compute the actual undistorted image
|
| 134 |
+
undistorted_image = distort_by_calibration(
|
| 135 |
+
image, pinhole_camera_online_calibration, native_camera_online_calibration
|
| 136 |
+
)
|
| 137 |
+
|
| 138 |
+
return undistorted_image
|
| 139 |
+
|
| 140 |
+
def get_device_calibration(self) -> DeviceCalibration:
|
| 141 |
+
"""
|
| 142 |
+
Return the device calibration (factory calibration of all sensors)
|
| 143 |
+
"""
|
| 144 |
+
return self._vrs_data_provider.get_device_calibration()
|
| 145 |
+
|
| 146 |
+
def get_camera_calibration(
|
| 147 |
+
self,
|
| 148 |
+
stream_id: StreamId,
|
| 149 |
+
camera_model=FISHEYE624,
|
| 150 |
+
) -> tuple[SE3, CameraCalibration]:
|
| 151 |
+
"""
|
| 152 |
+
Return the camera calibration of the device of the sequence as [Extrinsics, Intrinsics]
|
| 153 |
+
Note:
|
| 154 |
+
- A corresponding pinhole camera can be requested by using camera_model = LINEAR.
|
| 155 |
+
- This is the camera model used to generate the 'get_undistorted_image'.
|
| 156 |
+
"""
|
| 157 |
+
if not (camera_model is FISHEYE624 or camera_model is LINEAR):
|
| 158 |
+
raise ValueError(
|
| 159 |
+
"Invalid camera_model type, only FISHEYE624 and LINEAR are supported"
|
| 160 |
+
)
|
| 161 |
+
|
| 162 |
+
device_calibration = self.get_device_calibration()
|
| 163 |
+
stream_label = self._vrs_data_provider.get_label_from_stream_id(stream_id)
|
| 164 |
+
camera_calibration = device_calibration.get_camera_calib(stream_label)
|
| 165 |
+
|
| 166 |
+
# Store the relative transform from device to camera
|
| 167 |
+
T_device_camera = camera_calibration.get_transform_device_camera()
|
| 168 |
+
|
| 169 |
+
# If a corresponding pinhole camera is requested, we build one on the fly
|
| 170 |
+
if camera_model == LINEAR:
|
| 171 |
+
focal_lengths = camera_calibration.get_focal_lengths()
|
| 172 |
+
image_size = camera_calibration.get_image_size()
|
| 173 |
+
camera_calibration = get_linear_camera_calibration(
|
| 174 |
+
image_size[0], image_size[1], focal_lengths[0]
|
| 175 |
+
)
|
| 176 |
+
# else return the native FISHEYE624 camera model
|
| 177 |
+
|
| 178 |
+
return [T_device_camera, camera_calibration]
|
| 179 |
+
|
| 180 |
+
def get_online_camera_calibration(
|
| 181 |
+
self,
|
| 182 |
+
stream_id: StreamId,
|
| 183 |
+
timestamp_ns: Optional[int],
|
| 184 |
+
time_domain: TimeDomain = TimeDomain.TIME_CODE,
|
| 185 |
+
camera_model=FISHEYE624,
|
| 186 |
+
) -> tuple[SE3, CameraCalibration]:
|
| 187 |
+
"""
|
| 188 |
+
Return the camera calibration of the device of the sequence as [Extrinsics, Intrinsics]
|
| 189 |
+
Note:
|
| 190 |
+
- A corresponding pinhole camera can be requested by using camera_model = LINEAR.
|
| 191 |
+
- This is the camera model used to generate the 'get_undistorted_image'.
|
| 192 |
+
"""
|
| 193 |
+
if not (camera_model is FISHEYE624 or camera_model is LINEAR):
|
| 194 |
+
raise ValueError(
|
| 195 |
+
"Invalid camera_model type, only FISHEYE624 and LINEAR are supported"
|
| 196 |
+
)
|
| 197 |
+
if time_domain is not TimeDomain.TIME_CODE:
|
| 198 |
+
raise ValueError(
|
| 199 |
+
f"{time_domain} is not supported. Only TIME_CODE is supported"
|
| 200 |
+
)
|
| 201 |
+
|
| 202 |
+
device_timestamp_ns = (
|
| 203 |
+
self._vrs_data_provider.convert_from_timecode_to_device_time_ns(
|
| 204 |
+
timestamp_ns
|
| 205 |
+
)
|
| 206 |
+
)
|
| 207 |
+
online_calibration = self._mps_data_provider.get_online_calibration(
|
| 208 |
+
device_timestamp_ns=device_timestamp_ns,
|
| 209 |
+
time_query_options=TimeQueryOptions.CLOSEST,
|
| 210 |
+
)
|
| 211 |
+
camera_calibs = online_calibration.camera_calibs
|
| 212 |
+
|
| 213 |
+
stream_label = self._vrs_data_provider.get_label_from_stream_id(stream_id)
|
| 214 |
+
camera_calib = [c for c in camera_calibs if c.get_label() == stream_label]
|
| 215 |
+
if len(camera_calib) == 0:
|
| 216 |
+
raise ValueError(
|
| 217 |
+
f"camera_calib not found for stream_label: {stream_label} stream_id: {stream_id} at timestamp_ns: {timestamp_ns}"
|
| 218 |
+
)
|
| 219 |
+
camera_calibration = camera_calib[0]
|
| 220 |
+
|
| 221 |
+
## Fix the image size to correspond to the image saved in the vrs.
|
| 222 |
+
## The calibration returned by mps_data_provider has hardcoded image sizes which are incorrect.
|
| 223 |
+
[_, native_camera_calibration] = self.get_camera_calibration(
|
| 224 |
+
stream_id, camera_model=camera_model
|
| 225 |
+
)
|
| 226 |
+
camera_calibration = CameraCalibration(
|
| 227 |
+
camera_calibration.get_label(),
|
| 228 |
+
camera_model,
|
| 229 |
+
camera_calibration.projection_params(),
|
| 230 |
+
camera_calibration.get_transform_device_camera(),
|
| 231 |
+
native_camera_calibration.get_image_size()[0], ## correct the image size
|
| 232 |
+
native_camera_calibration.get_image_size()[1],
|
| 233 |
+
camera_calibration.get_valid_radius(),
|
| 234 |
+
camera_calibration.get_max_solid_angle(),
|
| 235 |
+
camera_calibration.get_serial_number(),
|
| 236 |
+
)
|
| 237 |
+
# Store the relative transform from device to camera
|
| 238 |
+
T_device_camera = camera_calibration.get_transform_device_camera()
|
| 239 |
+
|
| 240 |
+
# If a corresponding pinhole camera is requested, we build one on the fly
|
| 241 |
+
if camera_model == LINEAR:
|
| 242 |
+
focal_lengths = camera_calibration.get_focal_lengths()
|
| 243 |
+
image_size = camera_calibration.get_image_size()
|
| 244 |
+
camera_calibration = get_linear_camera_calibration(
|
| 245 |
+
image_size[0], image_size[1], focal_lengths[0]
|
| 246 |
+
)
|
| 247 |
+
# Info: transform_device_camera is set to ID in this path in the camera_calibration
|
| 248 |
+
# else return the native FISHEYE624 camera model
|
| 249 |
+
|
| 250 |
+
return [T_device_camera, camera_calibration]
|
| 251 |
+
|
| 252 |
+
def _timestamp_convert(
|
| 253 |
+
self, timestamp: int, time_domain_in: TimeDomain, time_domain_out: TimeDomain
|
| 254 |
+
) -> int:
|
| 255 |
+
"""
|
| 256 |
+
Returns the converted timestamp between two domains (TimeCode <-> Aria DeviceTime)
|
| 257 |
+
"""
|
| 258 |
+
if self._vrs_data_provider:
|
| 259 |
+
# Map to corresponding timestamp
|
| 260 |
+
if (
|
| 261 |
+
time_domain_in == TimeDomain.TIME_CODE
|
| 262 |
+
and time_domain_out == TimeDomain.DEVICE_TIME
|
| 263 |
+
):
|
| 264 |
+
out_timestamp = (
|
| 265 |
+
self._vrs_data_provider.convert_from_timecode_to_device_time_ns(
|
| 266 |
+
timestamp
|
| 267 |
+
)
|
| 268 |
+
)
|
| 269 |
+
if (
|
| 270 |
+
time_domain_in == TimeDomain.DEVICE_TIME
|
| 271 |
+
and time_domain_out == TimeDomain.TIME_CODE
|
| 272 |
+
):
|
| 273 |
+
out_timestamp = (
|
| 274 |
+
self._vrs_data_provider.convert_from_device_time_to_timecode_ns(
|
| 275 |
+
timestamp
|
| 276 |
+
)
|
| 277 |
+
)
|
| 278 |
+
return out_timestamp
|
| 279 |
+
return None
|
| 280 |
+
|
| 281 |
+
###
|
| 282 |
+
# Add MPS data specifics
|
| 283 |
+
###
|
| 284 |
+
|
| 285 |
+
def get_point_cloud(self) -> Optional[np.ndarray]:
|
| 286 |
+
"""
|
| 287 |
+
Return the point cloud of the scene
|
| 288 |
+
"""
|
| 289 |
+
if self._mps_data_provider is None:
|
| 290 |
+
return None
|
| 291 |
+
if self._mps_data_provider.has_semidense_point_cloud():
|
| 292 |
+
point_cloud_data = self._mps_data_provider.get_semidense_point_cloud()
|
| 293 |
+
# Point cloud filtering is left to the user
|
| 294 |
+
return point_cloud_data
|
| 295 |
+
|
| 296 |
+
return None
|
| 297 |
+
|
| 298 |
+
def _get_gaze_vector_reprojection(
|
| 299 |
+
self,
|
| 300 |
+
eye_gaze: EyeGaze,
|
| 301 |
+
stream_id_label: str,
|
| 302 |
+
device_calibration: DeviceCalibration,
|
| 303 |
+
camera_calibration: CameraCalibration,
|
| 304 |
+
) -> np.ndarray:
|
| 305 |
+
"""
|
| 306 |
+
Helper function to project a eye gaze output onto a given image and its calibration, assuming specified fixed depth
|
| 307 |
+
"""
|
| 308 |
+
gaze_center_in_cpf = get_eyegaze_point_at_depth(
|
| 309 |
+
eye_gaze.yaw, eye_gaze.pitch, depth_m=eye_gaze.depth or 1.0
|
| 310 |
+
)
|
| 311 |
+
transform_device_cpf = device_calibration.get_transform_device_cpf()
|
| 312 |
+
transform_device_camera = device_calibration.get_transform_device_sensor(
|
| 313 |
+
stream_id_label, True
|
| 314 |
+
)
|
| 315 |
+
# We use CAD value (this is the coordinate system used by the Eye Gaze model prediction)
|
| 316 |
+
# Using factory calibration (i.e CAD = False) would lead to less accurate EyeGaze reprojection.
|
| 317 |
+
transform_camera_cpf = transform_device_camera.inverse() @ transform_device_cpf
|
| 318 |
+
gaze_center_in_camera = transform_camera_cpf @ gaze_center_in_cpf
|
| 319 |
+
gaze_center_in_pixels = camera_calibration.project(gaze_center_in_camera)
|
| 320 |
+
return gaze_center_in_pixels
|
| 321 |
+
|
| 322 |
+
def get_eye_gaze_in_camera(
|
| 323 |
+
self,
|
| 324 |
+
stream_id: StreamId,
|
| 325 |
+
timestamp_ns: int,
|
| 326 |
+
time_domain: TimeDomain = TimeDomain.TIME_CODE,
|
| 327 |
+
camera_model=FISHEYE624,
|
| 328 |
+
):
|
| 329 |
+
"""
|
| 330 |
+
Return the eye_gaze at the given timestamp projected in the given stream for the given time_domain
|
| 331 |
+
"""
|
| 332 |
+
if not (camera_model is FISHEYE624 or camera_model is LINEAR):
|
| 333 |
+
raise ValueError(
|
| 334 |
+
"Invalid camera_model type, only FISHEYE624 and LINEAR are supported"
|
| 335 |
+
)
|
| 336 |
+
|
| 337 |
+
eye_gaze = self.get_eye_gaze(timestamp_ns, time_domain)
|
| 338 |
+
if eye_gaze:
|
| 339 |
+
[T_device_camera, camera_calibration] = self.get_camera_calibration(
|
| 340 |
+
stream_id, camera_model
|
| 341 |
+
)
|
| 342 |
+
# Compute eye_gaze vector at depth_m and project it in the image
|
| 343 |
+
gaze_projection = self._get_gaze_vector_reprojection(
|
| 344 |
+
eye_gaze,
|
| 345 |
+
self.get_image_stream_label(stream_id),
|
| 346 |
+
self.get_device_calibration(),
|
| 347 |
+
camera_calibration,
|
| 348 |
+
)
|
| 349 |
+
return gaze_projection
|
| 350 |
+
return None
|
| 351 |
+
|
| 352 |
+
def get_eye_gaze(
|
| 353 |
+
self,
|
| 354 |
+
timestamp_ns: int,
|
| 355 |
+
time_domain: TimeDomain = TimeDomain.TIME_CODE,
|
| 356 |
+
) -> Optional[EyeGaze]:
|
| 357 |
+
"""
|
| 358 |
+
Return the eye_gaze data at the given timestamp
|
| 359 |
+
"""
|
| 360 |
+
# Map to corresponding timestamp
|
| 361 |
+
if time_domain == TimeDomain.TIME_CODE:
|
| 362 |
+
device_timestamp_ns = self._timestamp_convert(
|
| 363 |
+
timestamp_ns, TimeDomain.TIME_CODE, TimeDomain.DEVICE_TIME
|
| 364 |
+
)
|
| 365 |
+
elif time_domain == TimeDomain.DEVICE_TIME:
|
| 366 |
+
device_timestamp_ns = timestamp_ns
|
| 367 |
+
else:
|
| 368 |
+
raise ValueError("Unsupported time domain")
|
| 369 |
+
|
| 370 |
+
if device_timestamp_ns:
|
| 371 |
+
if self._mps_data_provider.has_personalized_eyegaze():
|
| 372 |
+
return self._mps_data_provider.get_personalized_eyegaze(
|
| 373 |
+
device_timestamp_ns
|
| 374 |
+
)
|
| 375 |
+
elif self._mps_data_provider.has_general_eyegaze():
|
| 376 |
+
return self._mps_data_provider.get_general_eyegaze(device_timestamp_ns)
|
| 377 |
+
return None
|
HOT3DHUGGFACE/data_loaders/HandBox2dDataProvider.py
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
import csv
|
| 16 |
+
import logging
|
| 17 |
+
import os
|
| 18 |
+
from dataclasses import dataclass
|
| 19 |
+
from typing import Any, Dict, List, Optional
|
| 20 |
+
|
| 21 |
+
from projectaria_tools.core.sensor_data import TimeDomain, TimeQueryOptions # @manual
|
| 22 |
+
from projectaria_tools.core.stream_id import StreamId # @manual
|
| 23 |
+
|
| 24 |
+
from .AlignedBox2d import AlignedBox2d
|
| 25 |
+
from .constants import HAND_BOX2D_DATA_CSV_COLUMNS
|
| 26 |
+
from .io_utils import float_or_none, is_float
|
| 27 |
+
from .loader_poses_utils import check_csv_columns
|
| 28 |
+
from .pose_utils import lookup_timestamp
|
| 29 |
+
|
| 30 |
+
logger = logging.getLogger(__name__)
|
| 31 |
+
logging.basicConfig(
|
| 32 |
+
level=logging.INFO,
|
| 33 |
+
format="%(asctime)s - %(filename)s - %(lineno)d - %(levelname)s - %(message)s",
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
@dataclass
|
| 38 |
+
class HandBox2d:
|
| 39 |
+
box2d: AlignedBox2d
|
| 40 |
+
visibility_ratio: float
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
@dataclass
|
| 44 |
+
class HandBox2dCollection:
|
| 45 |
+
timestamp_ns: int
|
| 46 |
+
box2ds: Dict[int, HandBox2d]
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
HandBox2dTrajectory = Dict[int, HandBox2dCollection] # trajectory for a single stream
|
| 50 |
+
HandBox2dTrajectoryCollection = Dict[
|
| 51 |
+
str, HandBox2dTrajectory
|
| 52 |
+
] # trajectories for multiple streams
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
@dataclass
|
| 56 |
+
class HandBox2dCollectionWithDt:
|
| 57 |
+
box2d_collection: HandBox2dCollection
|
| 58 |
+
time_delta_ns: int
|
| 59 |
+
|
| 60 |
+
#box2ds: Dict[int, HandBox2d]
|
| 61 |
+
class HandBox2dProvider:
|
| 62 |
+
def __init__(
|
| 63 |
+
self, box2d_trajectory_collection: HandBox2dTrajectoryCollection
|
| 64 |
+
) -> None:
|
| 65 |
+
#真正存数据的,但没有进行排序
|
| 66 |
+
self._box2d_trajectory_collection = box2d_trajectory_collection
|
| 67 |
+
|
| 68 |
+
self._sorted_timestamp_ns_list: Dict[str, List[int]] = {}
|
| 69 |
+
for stream_id in self._box2d_trajectory_collection.keys():
|
| 70 |
+
self._sorted_timestamp_ns_list[stream_id] = sorted(
|
| 71 |
+
self._box2d_trajectory_collection[stream_id].keys()
|
| 72 |
+
)
|
| 73 |
+
|
| 74 |
+
def get_timestamp_ns_list(self, stream_id: StreamId) -> Optional[List[int]]:
|
| 75 |
+
return self._sorted_timestamp_ns_list.get(str(stream_id), None)
|
| 76 |
+
|
| 77 |
+
@property
|
| 78 |
+
def stream_ids(self) -> List[StreamId]:
|
| 79 |
+
return [StreamId(x) for x in self._box2d_trajectory_collection.keys()]
|
| 80 |
+
|
| 81 |
+
def get_data_statistics(self) -> Dict[str, Any]:
|
| 82 |
+
"""
|
| 83 |
+
Returns the stats for Hand 2D bounding boxes
|
| 84 |
+
"""
|
| 85 |
+
stats = {}
|
| 86 |
+
stats["num_frames"] = {
|
| 87 |
+
k: len(v) for k, v in self._sorted_timestamp_ns_list.items()
|
| 88 |
+
}
|
| 89 |
+
stats["stream_ids"] = [str(x) for x in self.stream_ids]
|
| 90 |
+
return stats
|
| 91 |
+
|
| 92 |
+
def get_bbox_at_timestamp(
|
| 93 |
+
self,
|
| 94 |
+
stream_id: StreamId,
|
| 95 |
+
timestamp_ns: int,
|
| 96 |
+
time_query_options: TimeQueryOptions,
|
| 97 |
+
time_domain: TimeDomain,
|
| 98 |
+
) -> Optional[HandBox2dCollectionWithDt]:
|
| 99 |
+
"""
|
| 100 |
+
Return the list of poses at the given timestamp
|
| 101 |
+
"""
|
| 102 |
+
if time_domain is not TimeDomain.TIME_CODE:
|
| 103 |
+
raise ValueError("Value other than TimeDomain.TIME_CODE not yet supported.")
|
| 104 |
+
|
| 105 |
+
if stream_id not in self.stream_ids:
|
| 106 |
+
raise ValueError(f"Box2d trajectory not available for stream {stream_id}.")
|
| 107 |
+
|
| 108 |
+
box2d_collection, time_delta_ns = lookup_timestamp(
|
| 109 |
+
time_indexed_dict=self._box2d_trajectory_collection[str(stream_id)],
|
| 110 |
+
sorted_timestamp_list=self.get_timestamp_ns_list(stream_id=stream_id),
|
| 111 |
+
query_timestamp=timestamp_ns,
|
| 112 |
+
time_query_options=time_query_options,
|
| 113 |
+
)
|
| 114 |
+
|
| 115 |
+
if box2d_collection is None or time_delta_ns is None:
|
| 116 |
+
return None
|
| 117 |
+
else:
|
| 118 |
+
return HandBox2dCollectionWithDt(
|
| 119 |
+
box2d_collection=box2d_collection, time_delta_ns=time_delta_ns
|
| 120 |
+
)
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
def parse_box2ds_from_csv_reader(csv_reader) -> HandBox2dTrajectoryCollection:
|
| 124 |
+
box2d_trajectory_collection: HandBox2dTrajectoryCollection = {}
|
| 125 |
+
|
| 126 |
+
# Read the header row
|
| 127 |
+
header = next(csv_reader)
|
| 128 |
+
|
| 129 |
+
# Ensure we have the desired columns
|
| 130 |
+
check_csv_columns(header, HAND_BOX2D_DATA_CSV_COLUMNS)
|
| 131 |
+
|
| 132 |
+
# Read the rest of the rows in the CSV file
|
| 133 |
+
for row in csv_reader:
|
| 134 |
+
stream_id = str(StreamId(row[header.index("stream_id")]))
|
| 135 |
+
timestamp_ns = int(row[header.index("timestamp[ns]")])
|
| 136 |
+
hand_index = int(row[header.index("hand_index")])
|
| 137 |
+
visibility_ratio = float_or_none(row[header.index("visibility_ratio[%]")])
|
| 138 |
+
|
| 139 |
+
if is_float(row[header.index("x_min[pixel]")]):
|
| 140 |
+
x_min_px = float(row[header.index("x_min[pixel]")])
|
| 141 |
+
x_max_px = float(row[header.index("x_max[pixel]")])
|
| 142 |
+
y_min_px = float(row[header.index("y_min[pixel]")])
|
| 143 |
+
y_max_px = float(row[header.index("y_max[pixel]")])
|
| 144 |
+
|
| 145 |
+
box2d = AlignedBox2d(
|
| 146 |
+
left=x_min_px, top=y_min_px, right=x_max_px, bottom=y_max_px
|
| 147 |
+
)
|
| 148 |
+
else:
|
| 149 |
+
box2d = None
|
| 150 |
+
|
| 151 |
+
object_box2d = HandBox2d(
|
| 152 |
+
box2d=box2d,
|
| 153 |
+
visibility_ratio=visibility_ratio,
|
| 154 |
+
)
|
| 155 |
+
|
| 156 |
+
if stream_id not in box2d_trajectory_collection:
|
| 157 |
+
box2d_trajectory_collection[stream_id] = {}
|
| 158 |
+
|
| 159 |
+
if timestamp_ns not in box2d_trajectory_collection[stream_id]:
|
| 160 |
+
box2d_trajectory_collection[stream_id][timestamp_ns] = HandBox2dCollection(
|
| 161 |
+
timestamp_ns=timestamp_ns, box2ds={}
|
| 162 |
+
)
|
| 163 |
+
|
| 164 |
+
box2d_trajectory_collection[stream_id][timestamp_ns].box2ds[hand_index] = (
|
| 165 |
+
object_box2d
|
| 166 |
+
)
|
| 167 |
+
return box2d_trajectory_collection
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
def load_box2d_trajectory_from_csv(filename: str) -> Optional[HandBox2dProvider]:
|
| 171 |
+
"""Load Hand 2D bounding box meta data from a CSV file.
|
| 172 |
+
|
| 173 |
+
Keyword arguments:
|
| 174 |
+
filename -- the csv file i.e. sequence_folder + "/box2d_hands.csv"
|
| 175 |
+
"""
|
| 176 |
+
if not os.path.exists(filename):
|
| 177 |
+
logger.warn(f"filename: {filename} does not exist.")
|
| 178 |
+
return None
|
| 179 |
+
|
| 180 |
+
# Open the CSV file for reading
|
| 181 |
+
with open(filename, "r") as f:
|
| 182 |
+
csv_reader = csv.reader(f)
|
| 183 |
+
box2d_trajectory_collection = parse_box2ds_from_csv_reader(
|
| 184 |
+
csv_reader=csv_reader
|
| 185 |
+
)
|
| 186 |
+
return HandBox2dProvider(
|
| 187 |
+
box2d_trajectory_collection=box2d_trajectory_collection
|
| 188 |
+
)
|
HOT3DHUGGFACE/data_loaders/HandDataProviderBase.py
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
from abc import abstractmethod
|
| 16 |
+
from dataclasses import dataclass
|
| 17 |
+
from typing import Any, Dict, List, Optional
|
| 18 |
+
|
| 19 |
+
import numpy as np
|
| 20 |
+
import torch
|
| 21 |
+
from data_loaders.loader_hand_poses import (
|
| 22 |
+
Handedness,
|
| 23 |
+
HandPose,
|
| 24 |
+
HandPose3dCollection,
|
| 25 |
+
load_hand_poses,
|
| 26 |
+
)
|
| 27 |
+
from projectaria_tools.core.sensor_data import TimeDomain, TimeQueryOptions # @manual
|
| 28 |
+
|
| 29 |
+
from .pose_utils import lookup_timestamp
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
@dataclass
|
| 33 |
+
class HandPose3dCollectionWithDt:
|
| 34 |
+
pose3d_collection: HandPose3dCollection
|
| 35 |
+
time_delta_ns: int
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
class HandDataProviderBase:
|
| 39 |
+
def __init__(
|
| 40 |
+
self,
|
| 41 |
+
) -> None:
|
| 42 |
+
self._hand_poses = None
|
| 43 |
+
self._sorted_timestamp_ns_list: List[int]
|
| 44 |
+
|
| 45 |
+
def _init_hand_poses(self, hand_pose_trajectory_filepath: str) -> None:
|
| 46 |
+
#self._hand_poses是一个字典,key是timestamp_ns,value是HandPose3dCollection对象,里面包含timestamp_ns和poses字典
|
| 47 |
+
# 取某一帧
|
| 48 |
+
# frame = hand_poses[1234567890]
|
| 49 |
+
|
| 50 |
+
# # 取右手
|
| 51 |
+
# right_hand = frame.poses[Handedness.Right]
|
| 52 |
+
|
| 53 |
+
# # 取右手手腕位置
|
| 54 |
+
# wrist_se3 = right_hand.wrist_pose
|
| 55 |
+
|
| 56 |
+
# # 取右手关节角度
|
| 57 |
+
# angles = right_hand.joint_angles
|
| 58 |
+
|
| 59 |
+
self._hand_poses = load_hand_poses(hand_pose_trajectory_filepath)
|
| 60 |
+
self._sorted_timestamp_ns_list: List[int] = sorted(self._hand_poses.keys())
|
| 61 |
+
|
| 62 |
+
@property
|
| 63 |
+
def timestamp_ns_list(self) -> List[int]:
|
| 64 |
+
return self._sorted_timestamp_ns_list
|
| 65 |
+
|
| 66 |
+
def get_data_statistics(self) -> Dict[str, Any]:
|
| 67 |
+
"""
|
| 68 |
+
Returns the stats of the Hand data
|
| 69 |
+
"""
|
| 70 |
+
assert self._hand_poses is not None
|
| 71 |
+
|
| 72 |
+
stats = {}
|
| 73 |
+
stats["num_frames"] = len(self._sorted_timestamp_ns_list)
|
| 74 |
+
stats["num_right_hands"] = sum(
|
| 75 |
+
[
|
| 76 |
+
1
|
| 77 |
+
for it in self._hand_poses.values()
|
| 78 |
+
if Handedness.Right in it.poses.keys()
|
| 79 |
+
]
|
| 80 |
+
)
|
| 81 |
+
stats["num_left_hands"] = sum(
|
| 82 |
+
[
|
| 83 |
+
1
|
| 84 |
+
for it in self._hand_poses.values()
|
| 85 |
+
if Handedness.Left in it.poses.keys()
|
| 86 |
+
]
|
| 87 |
+
)
|
| 88 |
+
return stats
|
| 89 |
+
|
| 90 |
+
def get_pose_at_timestamp(
|
| 91 |
+
self,
|
| 92 |
+
timestamp_ns: int,
|
| 93 |
+
time_query_options: TimeQueryOptions,
|
| 94 |
+
time_domain: TimeDomain,
|
| 95 |
+
acceptable_time_delta: Optional[int] = None,
|
| 96 |
+
) -> Optional[HandPose3dCollectionWithDt]:
|
| 97 |
+
"""
|
| 98 |
+
Return the list of hands available at a given timestamp
|
| 99 |
+
"""
|
| 100 |
+
if time_domain is not TimeDomain.TIME_CODE:
|
| 101 |
+
raise ValueError("Value other than TimeDomain.TIME_CODE not yet supported.")
|
| 102 |
+
|
| 103 |
+
hand_pose_collection, time_delta_ns = lookup_timestamp(
|
| 104 |
+
time_indexed_dict=self._hand_poses,
|
| 105 |
+
sorted_timestamp_list=self._sorted_timestamp_ns_list,
|
| 106 |
+
query_timestamp=timestamp_ns,
|
| 107 |
+
time_query_options=time_query_options,
|
| 108 |
+
)
|
| 109 |
+
|
| 110 |
+
if (
|
| 111 |
+
hand_pose_collection is None
|
| 112 |
+
or time_delta_ns is None
|
| 113 |
+
or (
|
| 114 |
+
acceptable_time_delta is not None
|
| 115 |
+
and abs(time_delta_ns) > acceptable_time_delta
|
| 116 |
+
)
|
| 117 |
+
):
|
| 118 |
+
return None
|
| 119 |
+
else:
|
| 120 |
+
return HandPose3dCollectionWithDt(
|
| 121 |
+
pose3d_collection=hand_pose_collection, time_delta_ns=time_delta_ns
|
| 122 |
+
)
|
| 123 |
+
|
| 124 |
+
@abstractmethod
|
| 125 |
+
def get_hand_mesh_vertices(
|
| 126 |
+
self, hand_wrist_data: HandPose
|
| 127 |
+
) -> Optional[torch.Tensor]:
|
| 128 |
+
"""
|
| 129 |
+
Return the hand mesh corresponding to given HandPose
|
| 130 |
+
"""
|
| 131 |
+
|
| 132 |
+
@abstractmethod
|
| 133 |
+
def get_hand_mesh_faces_and_normals(
|
| 134 |
+
self, hand_wrist_data: HandPose
|
| 135 |
+
) -> Optional[List[np.ndarray]]:
|
| 136 |
+
"""
|
| 137 |
+
Return the hand mesh faces and normals
|
| 138 |
+
"""
|
| 139 |
+
|
| 140 |
+
@abstractmethod
|
| 141 |
+
def get_hand_landmarks(self, hand_wrist_data: HandPose) -> Optional[torch.Tensor]:
|
| 142 |
+
"""
|
| 143 |
+
Return the hand joint landmarks corresponding to given HandPose
|
| 144 |
+
See how to map the vertices together to represent a Hand as linked lines using LANDMARK_CONNECTIVITY
|
| 145 |
+
"""
|
| 146 |
+
|
| 147 |
+
@staticmethod
|
| 148 |
+
def normalized(
|
| 149 |
+
vecs: np.ndarray, axis: int = -1, add_const_to_denom: bool = True
|
| 150 |
+
) -> np.ndarray:
|
| 151 |
+
"""
|
| 152 |
+
Normalize a set of vectors.
|
| 153 |
+
Args:
|
| 154 |
+
vecs: np.ndarray of shape (..., V).
|
| 155 |
+
axis: axis along which to normalize.
|
| 156 |
+
add_const_to_denom: if True, add a small constant to the denominator to prevent numerical issues.
|
| 157 |
+
Returns:
|
| 158 |
+
np.ndarray of the same shape as vecs.
|
| 159 |
+
"""
|
| 160 |
+
denom = np.linalg.norm(vecs, axis=axis, keepdims=True)
|
| 161 |
+
if add_const_to_denom:
|
| 162 |
+
denom += 1e-5
|
| 163 |
+
return vecs / denom
|
| 164 |
+
|
| 165 |
+
@staticmethod
|
| 166 |
+
def get_triangular_mesh_normals(
|
| 167 |
+
vertices: np.ndarray, triangles: np.ndarray
|
| 168 |
+
) -> np.ndarray:
|
| 169 |
+
"""
|
| 170 |
+
Compute the normals of a triangular mesh.
|
| 171 |
+
Args:
|
| 172 |
+
vertices: np.ndarray of shape (..., V, 3).
|
| 173 |
+
triangles: np.ndarray of shape (..., F, 3).
|
| 174 |
+
Returns:
|
| 175 |
+
normals: np.ndarray of shape (..., F, 3).
|
| 176 |
+
"""
|
| 177 |
+
norm = np.zeros_like(vertices)
|
| 178 |
+
tris = vertices[triangles]
|
| 179 |
+
n = np.cross(tris[::, 1] - tris[::, 0], tris[::, 2] - tris[::, 0])
|
| 180 |
+
n = HandDataProviderBase.normalized(n)
|
| 181 |
+
norm[triangles[:, 0]] += n
|
| 182 |
+
norm[triangles[:, 1]] += n
|
| 183 |
+
norm[triangles[:, 2]] += n
|
| 184 |
+
return HandDataProviderBase.normalized(norm)
|
HOT3DHUGGFACE/data_loaders/HeadsetPose3dProvider.py
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
import csv
|
| 16 |
+
from dataclasses import dataclass
|
| 17 |
+
from typing import Any, Dict, List, Optional, Tuple
|
| 18 |
+
|
| 19 |
+
import numpy as np
|
| 20 |
+
from projectaria_tools.core.sensor_data import TimeDomain, TimeQueryOptions # @manual
|
| 21 |
+
from projectaria_tools.core.sophus import SE3 # @manual
|
| 22 |
+
|
| 23 |
+
from .constants import POSE_DATA_CSV_COLUMNS
|
| 24 |
+
from .loader_poses_utils import check_csv_columns
|
| 25 |
+
from .pose_utils import lookup_timestamp
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
@dataclass
|
| 29 |
+
class HeadsetPose3d:
|
| 30 |
+
"""
|
| 31 |
+
Class to store pose of a headset
|
| 32 |
+
"""
|
| 33 |
+
|
| 34 |
+
T_world_device: Optional[SE3] = None
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
HeadsetPose3dTrajectory = Dict[int, HeadsetPose3d]
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
@dataclass
|
| 41 |
+
class HeadsetPose3dWithDt:
|
| 42 |
+
pose3d: HeadsetPose3d
|
| 43 |
+
time_delta_ns: int
|
| 44 |
+
|
| 45 |
+
#头显设备在每个时间戳下的位置和朝向信息
|
| 46 |
+
class HeadsetPose3dProvider(object):
|
| 47 |
+
def __init__(
|
| 48 |
+
self, headset_pose3d_trajectory: HeadsetPose3dTrajectory, headset_uid: str
|
| 49 |
+
):
|
| 50 |
+
self._pose3d_trajectory: HeadsetPose3dTrajectory = headset_pose3d_trajectory
|
| 51 |
+
self._sorted_timestamp_ns_list: List[int] = sorted(
|
| 52 |
+
self._pose3d_trajectory.keys()
|
| 53 |
+
)
|
| 54 |
+
self._headset_uid: str = str(headset_uid)
|
| 55 |
+
|
| 56 |
+
@property
|
| 57 |
+
def timestamp_ns_list(self) -> List[int]:
|
| 58 |
+
return self._sorted_timestamp_ns_list
|
| 59 |
+
|
| 60 |
+
@property
|
| 61 |
+
def headset_uid(self) -> str:
|
| 62 |
+
return self._headset_uid
|
| 63 |
+
|
| 64 |
+
def get_data_statistics(self) -> Dict[str, Any]:
|
| 65 |
+
"""
|
| 66 |
+
Returns the stats of the trajectory
|
| 67 |
+
"""
|
| 68 |
+
stats = {}
|
| 69 |
+
stats["num_frames"] = len(self._sorted_timestamp_ns_list)
|
| 70 |
+
stats["headset_uid"] = str(self._headset_uid)
|
| 71 |
+
return stats
|
| 72 |
+
|
| 73 |
+
def get_pose_at_timestamp(
|
| 74 |
+
self,
|
| 75 |
+
timestamp_ns: int,
|
| 76 |
+
time_query_options: TimeQueryOptions,
|
| 77 |
+
time_domain: TimeDomain,
|
| 78 |
+
acceptable_time_delta: Optional[int] = None,
|
| 79 |
+
) -> Optional[HeadsetPose3dWithDt]:
|
| 80 |
+
"""
|
| 81 |
+
Return the list of poses at the given timestamp
|
| 82 |
+
"""
|
| 83 |
+
if time_domain is not TimeDomain.TIME_CODE:
|
| 84 |
+
raise ValueError("Value other than TimeDomain.TIME_CODE not yet supported.")
|
| 85 |
+
|
| 86 |
+
headset_pose3d, time_delta_ns = lookup_timestamp(
|
| 87 |
+
time_indexed_dict=self._pose3d_trajectory,
|
| 88 |
+
sorted_timestamp_list=self._sorted_timestamp_ns_list,
|
| 89 |
+
query_timestamp=timestamp_ns,
|
| 90 |
+
time_query_options=time_query_options,
|
| 91 |
+
)
|
| 92 |
+
|
| 93 |
+
if (
|
| 94 |
+
headset_pose3d is None
|
| 95 |
+
or time_delta_ns is None
|
| 96 |
+
or (
|
| 97 |
+
acceptable_time_delta is not None
|
| 98 |
+
and abs(time_delta_ns) > acceptable_time_delta
|
| 99 |
+
)
|
| 100 |
+
):
|
| 101 |
+
return None
|
| 102 |
+
else:
|
| 103 |
+
return HeadsetPose3dWithDt(
|
| 104 |
+
pose3d=headset_pose3d, time_delta_ns=time_delta_ns
|
| 105 |
+
)
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
def load_headset_pose_trajectory_from_csv(filename: str) -> Tuple[Dict[int, SE3], str]:
|
| 109 |
+
"""Load Device Poses meta data from a CSV file.
|
| 110 |
+
|
| 111 |
+
Keyword arguments:
|
| 112 |
+
filename -- the csv file i.e. sequence_folder + "/headset_trajectory.csv"
|
| 113 |
+
"""
|
| 114 |
+
|
| 115 |
+
pose3d_trajectory: HeadsetPose3dTrajectory = {}
|
| 116 |
+
headset_uids = set()
|
| 117 |
+
|
| 118 |
+
# Open the CSV file for reading
|
| 119 |
+
with open(filename, "r") as f:
|
| 120 |
+
reader = csv.reader(f)
|
| 121 |
+
|
| 122 |
+
# Read the header row
|
| 123 |
+
header = next(reader)
|
| 124 |
+
|
| 125 |
+
# Ensure we have the desired columns
|
| 126 |
+
check_csv_columns(header, POSE_DATA_CSV_COLUMNS)
|
| 127 |
+
|
| 128 |
+
# Read the rest of the rows in the CSV file
|
| 129 |
+
for row in reader:
|
| 130 |
+
translation = [
|
| 131 |
+
row[header.index("t_wo_x[m]")],
|
| 132 |
+
row[header.index("t_wo_y[m]")],
|
| 133 |
+
row[header.index("t_wo_z[m]")],
|
| 134 |
+
]
|
| 135 |
+
quaternion_xyz = [
|
| 136 |
+
row[header.index("q_wo_x")],
|
| 137 |
+
row[header.index("q_wo_y")],
|
| 138 |
+
row[header.index("q_wo_z")],
|
| 139 |
+
]
|
| 140 |
+
quaternion_w = row[header.index("q_wo_w")]
|
| 141 |
+
timestamp_ns = int(row[header.index("timestamp[ns]")])
|
| 142 |
+
headset_uids.add(str(row[header.index("object_uid")]))
|
| 143 |
+
|
| 144 |
+
object_pose = SE3.from_quat_and_translation(
|
| 145 |
+
float(quaternion_w),
|
| 146 |
+
np.array([float(o) for o in quaternion_xyz]),
|
| 147 |
+
np.array([float(o) for o in translation]),
|
| 148 |
+
)[0]
|
| 149 |
+
|
| 150 |
+
pose3d_trajectory[timestamp_ns] = HeadsetPose3d(T_world_device=object_pose)
|
| 151 |
+
|
| 152 |
+
if len(headset_uids) != 1:
|
| 153 |
+
raise ValueError(
|
| 154 |
+
f"Expected 1 headset pose per timestamp, got {len(headset_uids)}. headset_uids: {headset_uids}"
|
| 155 |
+
)
|
| 156 |
+
|
| 157 |
+
return pose3d_trajectory, headset_uids.pop()
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
def load_headset_pose_provider_from_csv(filename: str) -> HeadsetPose3dProvider:
|
| 161 |
+
"""
|
| 162 |
+
Load pose_provider from csv
|
| 163 |
+
"""
|
| 164 |
+
|
| 165 |
+
headset_pose3d_trajectory, headset_uid = load_headset_pose_trajectory_from_csv(
|
| 166 |
+
filename
|
| 167 |
+
)
|
| 168 |
+
return HeadsetPose3dProvider(
|
| 169 |
+
headset_pose3d_trajectory=headset_pose3d_trajectory,
|
| 170 |
+
headset_uid=headset_uid,
|
| 171 |
+
)
|
HOT3DHUGGFACE/data_loaders/ManoHandDataProvider.py
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
from typing import List, Optional
|
| 16 |
+
|
| 17 |
+
import numpy as np
|
| 18 |
+
import torch
|
| 19 |
+
from data_loaders.HandDataProviderBase import HandDataProviderBase
|
| 20 |
+
from data_loaders.loader_hand_poses import Handedness, HandPose, load_mano_shape_params
|
| 21 |
+
from data_loaders.pytorch3d_rotation.rotation_conversions import ( # @manual
|
| 22 |
+
matrix_to_axis_angle,
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
from .mano_layer import MANOHandModel
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
class MANOHandDataProvider(HandDataProviderBase):
|
| 29 |
+
def __init__(
|
| 30 |
+
self,
|
| 31 |
+
hand_pose_trajectory_filepath: str,
|
| 32 |
+
mano_layer: MANOHandModel,
|
| 33 |
+
) -> None:
|
| 34 |
+
super().__init__()
|
| 35 |
+
#mano_hand_pose_trajectory.jsonl:每一帧中每只手的“手腕位置 + 手腕朝向 + 手指姿态 + 手型”
|
| 36 |
+
super()._init_hand_poses(hand_pose_trajectory_filepath)
|
| 37 |
+
|
| 38 |
+
# Hand profile
|
| 39 |
+
self._mano_shape_params = load_mano_shape_params(hand_pose_trajectory_filepath)
|
| 40 |
+
if self._mano_shape_params is not None:
|
| 41 |
+
self._mano_shape_params = torch.from_numpy(
|
| 42 |
+
np.array(self._mano_shape_params)
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
self.mano_layer = mano_layer
|
| 46 |
+
|
| 47 |
+
def get_hand_mesh_vertices(
|
| 48 |
+
self, hand_wrist_data: HandPose
|
| 49 |
+
) -> Optional[torch.Tensor]:
|
| 50 |
+
"""
|
| 51 |
+
Return the hand mesh corresponding to given HandPose
|
| 52 |
+
"""
|
| 53 |
+
if (
|
| 54 |
+
hand_wrist_data.wrist_pose is not None
|
| 55 |
+
and self._mano_shape_params is not None
|
| 56 |
+
and self.mano_layer is not None
|
| 57 |
+
):
|
| 58 |
+
hand_wrist_pose_matrix = hand_wrist_data.wrist_pose.to_matrix()
|
| 59 |
+
hand_wrist_pose_tensor = torch.from_numpy(hand_wrist_pose_matrix)
|
| 60 |
+
|
| 61 |
+
hand_wrist_rotation_axis_angle = matrix_to_axis_angle(
|
| 62 |
+
hand_wrist_pose_tensor[:3, :3]
|
| 63 |
+
)
|
| 64 |
+
hand_wrist_pose_tensor = torch.cat(
|
| 65 |
+
[hand_wrist_rotation_axis_angle, hand_wrist_pose_tensor[:3, 3]]
|
| 66 |
+
)
|
| 67 |
+
|
| 68 |
+
mesh_vertices, landmarks = self.mano_layer.forward_kinematics(
|
| 69 |
+
self._mano_shape_params,
|
| 70 |
+
torch.from_numpy(np.array(hand_wrist_data.joint_angles)),
|
| 71 |
+
hand_wrist_pose_tensor,
|
| 72 |
+
torch.tensor([hand_wrist_data.handedness == Handedness.Right]),
|
| 73 |
+
)
|
| 74 |
+
|
| 75 |
+
return mesh_vertices
|
| 76 |
+
return None
|
| 77 |
+
|
| 78 |
+
def get_hand_mesh_faces_and_normals(
|
| 79 |
+
self, hand_wrist_data: HandPose
|
| 80 |
+
) -> Optional[List[np.ndarray]]:
|
| 81 |
+
"""
|
| 82 |
+
Return the hand mesh faces and normals
|
| 83 |
+
"""
|
| 84 |
+
if self.mano_layer is not None:
|
| 85 |
+
if hand_wrist_data.handedness == Handedness.Right:
|
| 86 |
+
hand_triangles = self.mano_layer.mano_layer_right.faces
|
| 87 |
+
else:
|
| 88 |
+
hand_triangles = self.mano_layer.mano_layer_left.faces
|
| 89 |
+
|
| 90 |
+
vertices = self.get_hand_mesh_vertices(hand_wrist_data)
|
| 91 |
+
assert vertices is not None
|
| 92 |
+
normals = HandDataProviderBase.get_triangular_mesh_normals(
|
| 93 |
+
vertices.float().numpy(), hand_triangles
|
| 94 |
+
)
|
| 95 |
+
return [hand_triangles, normals]
|
| 96 |
+
else:
|
| 97 |
+
return None
|
| 98 |
+
|
| 99 |
+
def get_hand_landmarks(self, hand_wrist_data: HandPose) -> Optional[torch.Tensor]:
|
| 100 |
+
"""
|
| 101 |
+
Return the hand joint landmarks corresponding to given HandPose
|
| 102 |
+
See how to map the vertices together to represent a Hand as linked lines using LANDMARK_CONNECTIVITY
|
| 103 |
+
"""
|
| 104 |
+
if (
|
| 105 |
+
hand_wrist_data.wrist_pose is not None
|
| 106 |
+
and self._mano_shape_params is not None
|
| 107 |
+
and self.mano_layer is not None
|
| 108 |
+
):
|
| 109 |
+
hand_wrist_pose_matrix = hand_wrist_data.wrist_pose.to_matrix()
|
| 110 |
+
hand_wrist_pose_tensor = torch.from_numpy(hand_wrist_pose_matrix)
|
| 111 |
+
|
| 112 |
+
hand_wrist_rotation_axis_angle = matrix_to_axis_angle(
|
| 113 |
+
hand_wrist_pose_tensor[:3, :3]
|
| 114 |
+
)
|
| 115 |
+
hand_wrist_pose_tensor = torch.cat(
|
| 116 |
+
[hand_wrist_rotation_axis_angle, hand_wrist_pose_tensor[:3, 3]]
|
| 117 |
+
)
|
| 118 |
+
|
| 119 |
+
mesh_vertices, hand_landmarks = self.mano_layer.forward_kinematics(
|
| 120 |
+
self._mano_shape_params,
|
| 121 |
+
torch.from_numpy(np.array(hand_wrist_data.joint_angles)),
|
| 122 |
+
hand_wrist_pose_tensor,
|
| 123 |
+
torch.tensor([hand_wrist_data.handedness == Handedness.Right]),
|
| 124 |
+
)
|
| 125 |
+
|
| 126 |
+
return hand_landmarks
|
| 127 |
+
|
| 128 |
+
return None
|
HOT3DHUGGFACE/data_loaders/ObjectBox2dDataProvider.py
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
import csv
|
| 16 |
+
import logging
|
| 17 |
+
import os
|
| 18 |
+
from dataclasses import dataclass
|
| 19 |
+
from typing import Any, Dict, List, Optional, Set
|
| 20 |
+
|
| 21 |
+
from projectaria_tools.core.sensor_data import TimeDomain, TimeQueryOptions # @manual
|
| 22 |
+
from projectaria_tools.core.stream_id import StreamId # @manual
|
| 23 |
+
|
| 24 |
+
from .AlignedBox2d import AlignedBox2d
|
| 25 |
+
from .constants import BOX2D_DATA_CSV_COLUMNS
|
| 26 |
+
from .io_utils import float_or_none, is_float
|
| 27 |
+
from .loader_poses_utils import check_csv_columns
|
| 28 |
+
from .pose_utils import lookup_timestamp
|
| 29 |
+
|
| 30 |
+
logger = logging.getLogger(__name__)
|
| 31 |
+
logging.basicConfig(
|
| 32 |
+
level=logging.INFO,
|
| 33 |
+
format="%(asctime)s - %(filename)s - %(lineno)d - %(levelname)s - %(message)s",
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
#物体在图像上的 2D 边界框
|
| 37 |
+
@dataclass
|
| 38 |
+
class ObjectBox2d:
|
| 39 |
+
box2d: Optional[AlignedBox2d]
|
| 40 |
+
visibility_ratio: float
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
@dataclass
|
| 44 |
+
class ObjectBox2dCollection:
|
| 45 |
+
timestamp_ns: int
|
| 46 |
+
box2ds: Dict[str, ObjectBox2d]
|
| 47 |
+
|
| 48 |
+
@property
|
| 49 |
+
def object_uid_list(self) -> Set[str]:
|
| 50 |
+
return set(self.box2ds.keys())
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
ObjectBox2dTrajectory = Dict[
|
| 54 |
+
int, ObjectBox2dCollection
|
| 55 |
+
] # trajectory for a single stream
|
| 56 |
+
ObjectBox2dTrajectoryCollection = Dict[
|
| 57 |
+
str, ObjectBox2dTrajectory
|
| 58 |
+
] # trajectories for multiple streams
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
@dataclass
|
| 62 |
+
class ObjectBox2dCollectionWithDt:
|
| 63 |
+
box2d_collection: ObjectBox2dCollection
|
| 64 |
+
time_delta_ns: int
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
class ObjectBox2dProvider:
|
| 68 |
+
def __init__(
|
| 69 |
+
self, box2d_trajectory_collection: ObjectBox2dTrajectoryCollection
|
| 70 |
+
) -> None:
|
| 71 |
+
#真正存数据的,但没有进行排序
|
| 72 |
+
self._box2d_trajectory_collection = box2d_trajectory_collection
|
| 73 |
+
#对时间戳进行排序,纯时间序列
|
| 74 |
+
self._sorted_timestamp_ns_list: Dict[str, List[int]] = {}
|
| 75 |
+
for stream_id in self._box2d_trajectory_collection.keys():
|
| 76 |
+
self._sorted_timestamp_ns_list[stream_id] = sorted(
|
| 77 |
+
self._box2d_trajectory_collection[stream_id].keys()
|
| 78 |
+
)
|
| 79 |
+
#生成一个set,里面是所有出现过的物体ID
|
| 80 |
+
self._object_uids_with_box2ds: Set = {
|
| 81 |
+
x
|
| 82 |
+
for box2d_trajectory in self._box2d_trajectory_collection.values()
|
| 83 |
+
for v in box2d_trajectory.values()
|
| 84 |
+
for x in v.object_uid_list
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
def get_timestamp_ns_list(self, stream_id: StreamId) -> Optional[List[int]]:
|
| 88 |
+
return self._sorted_timestamp_ns_list.get(str(stream_id), None)
|
| 89 |
+
|
| 90 |
+
@property
|
| 91 |
+
def stream_ids(self) -> List[StreamId]:
|
| 92 |
+
return [StreamId(x) for x in self._box2d_trajectory_collection.keys()]
|
| 93 |
+
|
| 94 |
+
@property
|
| 95 |
+
def object_uids(self) -> Set[str]:
|
| 96 |
+
return set(self._object_uids_with_box2ds)
|
| 97 |
+
|
| 98 |
+
def get_data_statistics(self) -> Dict[str, Any]:
|
| 99 |
+
"""
|
| 100 |
+
Returns the stats for Object 2D bounding boxes
|
| 101 |
+
"""
|
| 102 |
+
stats = {}
|
| 103 |
+
stats["num_frames"] = {
|
| 104 |
+
k: len(v) for k, v in self._sorted_timestamp_ns_list.items()
|
| 105 |
+
}
|
| 106 |
+
stats["stream_ids"] = [str(x) for x in self.stream_ids]
|
| 107 |
+
stats["num_objects"] = len(self.object_uids)
|
| 108 |
+
stats["object_uids"] = [str(x) for x in self.object_uids]
|
| 109 |
+
return stats
|
| 110 |
+
|
| 111 |
+
def get_bbox_at_timestamp(
|
| 112 |
+
self,
|
| 113 |
+
stream_id: StreamId,
|
| 114 |
+
timestamp_ns: int,
|
| 115 |
+
time_query_options: TimeQueryOptions,
|
| 116 |
+
time_domain: TimeDomain,
|
| 117 |
+
acceptable_time_delta: Optional[int] = None,
|
| 118 |
+
) -> Optional[ObjectBox2dCollectionWithDt]:
|
| 119 |
+
"""
|
| 120 |
+
Return the list of boxes at the given timestamp
|
| 121 |
+
"""
|
| 122 |
+
if time_domain is not TimeDomain.TIME_CODE:
|
| 123 |
+
raise ValueError("Value other than TimeDomain.TIME_CODE not yet supported.")
|
| 124 |
+
|
| 125 |
+
if stream_id not in self.stream_ids:
|
| 126 |
+
raise ValueError(f"Box2d trajectory not available for stream {stream_id}.")
|
| 127 |
+
|
| 128 |
+
box2d_collection, time_delta_ns = lookup_timestamp(
|
| 129 |
+
time_indexed_dict=self._box2d_trajectory_collection[str(stream_id)],
|
| 130 |
+
sorted_timestamp_list=self.get_timestamp_ns_list(stream_id=stream_id),
|
| 131 |
+
query_timestamp=timestamp_ns,
|
| 132 |
+
time_query_options=time_query_options,
|
| 133 |
+
)
|
| 134 |
+
|
| 135 |
+
if (
|
| 136 |
+
box2d_collection is None
|
| 137 |
+
or time_delta_ns is None
|
| 138 |
+
or (
|
| 139 |
+
acceptable_time_delta is not None
|
| 140 |
+
and abs(time_delta_ns) > acceptable_time_delta
|
| 141 |
+
)
|
| 142 |
+
):
|
| 143 |
+
return None
|
| 144 |
+
else:
|
| 145 |
+
return ObjectBox2dCollectionWithDt(
|
| 146 |
+
box2d_collection=box2d_collection, time_delta_ns=time_delta_ns
|
| 147 |
+
)
|
| 148 |
+
|
| 149 |
+
# box2d_trajectory_collection[stream_id][timestamp_ns].box2ds[object_uid] = (
|
| 150 |
+
# object_box2d
|
| 151 |
+
# )
|
| 152 |
+
def parse_box2ds_from_csv_reader(csv_reader) -> ObjectBox2dTrajectoryCollection:
|
| 153 |
+
box2d_trajectory_collection: ObjectBox2dTrajectoryCollection = {}
|
| 154 |
+
|
| 155 |
+
# Read the header row
|
| 156 |
+
header = next(csv_reader)
|
| 157 |
+
|
| 158 |
+
# Ensure we have the desired columns
|
| 159 |
+
check_csv_columns(header, BOX2D_DATA_CSV_COLUMNS)
|
| 160 |
+
|
| 161 |
+
# Read the rest of the rows in the CSV file
|
| 162 |
+
for row in csv_reader:
|
| 163 |
+
stream_id = str(StreamId(row[header.index("stream_id")]))
|
| 164 |
+
timestamp_ns = int(row[header.index("timestamp[ns]")])
|
| 165 |
+
object_uid = str(row[header.index("object_uid")])
|
| 166 |
+
visibility_ratio = float_or_none(row[header.index("visibility_ratio[%]")])
|
| 167 |
+
|
| 168 |
+
#读取和存储已有的框
|
| 169 |
+
if is_float(row[header.index("x_min[pixel]")]):
|
| 170 |
+
x_min_px = float(row[header.index("x_min[pixel]")])
|
| 171 |
+
x_max_px = float(row[header.index("x_max[pixel]")])
|
| 172 |
+
y_min_px = float(row[header.index("y_min[pixel]")])
|
| 173 |
+
y_max_px = float(row[header.index("y_max[pixel]")])
|
| 174 |
+
|
| 175 |
+
box2d = AlignedBox2d(
|
| 176 |
+
left=x_min_px, top=y_min_px, right=x_max_px, bottom=y_max_px
|
| 177 |
+
)
|
| 178 |
+
else:
|
| 179 |
+
box2d = None
|
| 180 |
+
|
| 181 |
+
object_box2d = ObjectBox2d(
|
| 182 |
+
box2d=box2d,
|
| 183 |
+
visibility_ratio=visibility_ratio,
|
| 184 |
+
)
|
| 185 |
+
|
| 186 |
+
if stream_id not in box2d_trajectory_collection:
|
| 187 |
+
box2d_trajectory_collection[stream_id] = {}
|
| 188 |
+
|
| 189 |
+
if timestamp_ns not in box2d_trajectory_collection[stream_id]:
|
| 190 |
+
box2d_trajectory_collection[stream_id][timestamp_ns] = (
|
| 191 |
+
ObjectBox2dCollection(timestamp_ns=timestamp_ns, box2ds={})
|
| 192 |
+
)
|
| 193 |
+
#由于ObjectBox2dCollection用的所对象,所以使用"."
|
| 194 |
+
box2d_trajectory_collection[stream_id][timestamp_ns].box2ds[object_uid] = (
|
| 195 |
+
object_box2d
|
| 196 |
+
)
|
| 197 |
+
return box2d_trajectory_collection
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
def load_box2d_trajectory_from_csv(filename: str) -> Optional[ObjectBox2dProvider]:
|
| 201 |
+
"""Load Objects 2D bounding box meta data from a CSV file.
|
| 202 |
+
|
| 203 |
+
Keyword arguments:
|
| 204 |
+
filename -- the csv file i.e. sequence_folder + "/box2d_objects.csv"
|
| 205 |
+
"""
|
| 206 |
+
|
| 207 |
+
if not os.path.exists(filename):
|
| 208 |
+
logger.warn(f"filename: {filename} does not exist.")
|
| 209 |
+
return None
|
| 210 |
+
|
| 211 |
+
# Open the CSV file for reading
|
| 212 |
+
with open(filename, "r") as f:
|
| 213 |
+
csv_reader = csv.reader(f)
|
| 214 |
+
box2d_trajectory_collection = parse_box2ds_from_csv_reader(
|
| 215 |
+
csv_reader=csv_reader
|
| 216 |
+
)
|
| 217 |
+
return ObjectBox2dProvider(
|
| 218 |
+
box2d_trajectory_collection=box2d_trajectory_collection
|
| 219 |
+
)
|
HOT3DHUGGFACE/data_loaders/ObjectPose3dProvider.py
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
import csv
|
| 16 |
+
from dataclasses import dataclass
|
| 17 |
+
from typing import Any, Dict, List, Optional, Set
|
| 18 |
+
|
| 19 |
+
import numpy as np
|
| 20 |
+
from projectaria_tools.core.sensor_data import TimeDomain, TimeQueryOptions # @manual
|
| 21 |
+
from projectaria_tools.core.sophus import SE3 # @manual
|
| 22 |
+
|
| 23 |
+
from .constants import POSE_DATA_CSV_COLUMNS
|
| 24 |
+
from .loader_poses_utils import check_csv_columns
|
| 25 |
+
from .pose_utils import lookup_timestamp
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
@dataclass
|
| 29 |
+
class ObjectPose3d:
|
| 30 |
+
"""
|
| 31 |
+
Class to store pose of a single entity (object/headset/hand)
|
| 32 |
+
"""
|
| 33 |
+
|
| 34 |
+
T_world_object: Optional[SE3] = None
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
@dataclass
|
| 38 |
+
class ObjectPose3dCollection:
|
| 39 |
+
"""
|
| 40 |
+
Class to store the poses for a given timestamp
|
| 41 |
+
"""
|
| 42 |
+
|
| 43 |
+
timestamp_ns: int
|
| 44 |
+
poses: Dict[str, ObjectPose3d]
|
| 45 |
+
|
| 46 |
+
@property
|
| 47 |
+
def object_uid_list(self) -> Set[str]:
|
| 48 |
+
return set(self.poses.keys())
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
ObjectPose3dTrajectory = Dict[int, ObjectPose3dCollection]
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
@dataclass
|
| 55 |
+
class ObjectPose3dCollectionWithDt:
|
| 56 |
+
pose3d_collection: ObjectPose3dCollection
|
| 57 |
+
time_delta_ns: int
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
class ObjectPose3dProvider(object):
|
| 61 |
+
def __init__(self, pose3d_trajectory: ObjectPose3dTrajectory):
|
| 62 |
+
self._pose3d_trajectory: ObjectPose3dTrajectory = pose3d_trajectory
|
| 63 |
+
#排序时间戳
|
| 64 |
+
self._sorted_timestamp_ns_list: List[int] = sorted(
|
| 65 |
+
self._pose3d_trajectory.keys()
|
| 66 |
+
)
|
| 67 |
+
#所有出现过的物体ID
|
| 68 |
+
self._object_uids_with_poses: Set = {
|
| 69 |
+
x for v in self._pose3d_trajectory.values() for x in v.object_uid_list
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
#像属性一样访问,不用加括号
|
| 73 |
+
@property
|
| 74 |
+
def timestamp_ns_list(self) -> List[int]:
|
| 75 |
+
return self._sorted_timestamp_ns_list
|
| 76 |
+
|
| 77 |
+
@property
|
| 78 |
+
def object_uids_with_poses(self) -> Set[str]:
|
| 79 |
+
return set(self._object_uids_with_poses)
|
| 80 |
+
|
| 81 |
+
def get_data_statistics(self) -> Dict[str, Any]:
|
| 82 |
+
"""
|
| 83 |
+
Returns the stats of the trajectory
|
| 84 |
+
"""
|
| 85 |
+
stats = {}
|
| 86 |
+
stats["num_frames"] = len(self._sorted_timestamp_ns_list)
|
| 87 |
+
stats["num_objects"] = len(self._object_uids_with_poses)
|
| 88 |
+
stats["object_uids"] = [str(x) for x in self._object_uids_with_poses]
|
| 89 |
+
return stats
|
| 90 |
+
|
| 91 |
+
def get_pose_at_timestamp(
|
| 92 |
+
self,
|
| 93 |
+
timestamp_ns: int,
|
| 94 |
+
time_query_options: TimeQueryOptions,
|
| 95 |
+
time_domain: TimeDomain,
|
| 96 |
+
acceptable_time_delta: Optional[int] = None,
|
| 97 |
+
) -> Optional[ObjectPose3dCollectionWithDt]:
|
| 98 |
+
"""
|
| 99 |
+
Return the list of poses available at the given timestamp
|
| 100 |
+
"""
|
| 101 |
+
if time_domain is not TimeDomain.TIME_CODE:
|
| 102 |
+
raise ValueError("Value other than TimeDomain.TIME_CODE not yet supported.")
|
| 103 |
+
|
| 104 |
+
pose3d_collection, time_delta_ns = lookup_timestamp(
|
| 105 |
+
time_indexed_dict=self._pose3d_trajectory,
|
| 106 |
+
sorted_timestamp_list=self._sorted_timestamp_ns_list,
|
| 107 |
+
query_timestamp=timestamp_ns,
|
| 108 |
+
time_query_options=time_query_options,
|
| 109 |
+
)
|
| 110 |
+
|
| 111 |
+
if (
|
| 112 |
+
pose3d_collection is None
|
| 113 |
+
or time_delta_ns is None
|
| 114 |
+
or (
|
| 115 |
+
acceptable_time_delta is not None
|
| 116 |
+
and abs(time_delta_ns) > acceptable_time_delta
|
| 117 |
+
)
|
| 118 |
+
):
|
| 119 |
+
return None
|
| 120 |
+
else:
|
| 121 |
+
return ObjectPose3dCollectionWithDt(
|
| 122 |
+
pose3d_collection=pose3d_collection, time_delta_ns=time_delta_ns
|
| 123 |
+
)
|
| 124 |
+
|
| 125 |
+
#生成了一个pose3d_trajectory里面有物品在每个时间下的位置
|
| 126 |
+
def load_object_pose_trajectory_from_csv(filename: str) -> ObjectPose3dTrajectory:
|
| 127 |
+
"""Load Dynamic Objects meta data from a CSV file.
|
| 128 |
+
|
| 129 |
+
Keyword arguments:
|
| 130 |
+
filename -- the csv file i.e. sequence_folder + "/dynamic_objects.csv"
|
| 131 |
+
"""
|
| 132 |
+
#空字典,后面逐行读 CSV 往里填数据
|
| 133 |
+
pose3d_trajectory: ObjectPose3dTrajectory = {}
|
| 134 |
+
# Open the CSV file for reading
|
| 135 |
+
with open(filename, "r") as f:
|
| 136 |
+
reader = csv.reader(f)
|
| 137 |
+
|
| 138 |
+
# Read the header row
|
| 139 |
+
#读表头
|
| 140 |
+
header = next(reader)
|
| 141 |
+
|
| 142 |
+
# Ensure we have the desired columns
|
| 143 |
+
check_csv_columns(header, POSE_DATA_CSV_COLUMNS)
|
| 144 |
+
|
| 145 |
+
# Read the rest of the rows in the CSV file
|
| 146 |
+
for row in reader:
|
| 147 |
+
#位置
|
| 148 |
+
translation = [
|
| 149 |
+
#"t_wo_x[m]" 这个字符串在 header 列表的第几位? 然后读取
|
| 150 |
+
row[header.index("t_wo_x[m]")],
|
| 151 |
+
row[header.index("t_wo_y[m]")],
|
| 152 |
+
row[header.index("t_wo_z[m]")],
|
| 153 |
+
]
|
| 154 |
+
#朝向
|
| 155 |
+
quaternion_xyz = [
|
| 156 |
+
##"q_wo_x 这个字符串在 header 列表的第几位? 然后读取
|
| 157 |
+
row[header.index("q_wo_x")],
|
| 158 |
+
row[header.index("q_wo_y")],
|
| 159 |
+
row[header.index("q_wo_z")],
|
| 160 |
+
]
|
| 161 |
+
quaternion_w = row[header.index("q_wo_w")]
|
| 162 |
+
timestamp_ns = int(row[header.index("timestamp[ns]")])
|
| 163 |
+
object_uid = str(row[header.index("object_uid")])
|
| 164 |
+
#把位置和朝向转换成 SE3 变换矩阵,se3 物品位置和朝向的信息
|
| 165 |
+
T_world_object = SE3.from_quat_and_translation(
|
| 166 |
+
float(quaternion_w),
|
| 167 |
+
np.array([float(o) for o in quaternion_xyz]),
|
| 168 |
+
np.array([float(o) for o in translation]),
|
| 169 |
+
)[0]
|
| 170 |
+
|
| 171 |
+
pose3d = ObjectPose3d(T_world_object=T_world_object)
|
| 172 |
+
#确保timestamp_ns有位置
|
| 173 |
+
if timestamp_ns not in pose3d_trajectory:
|
| 174 |
+
pose3d_trajectory[timestamp_ns] = ObjectPose3dCollection(
|
| 175 |
+
timestamp_ns=timestamp_ns, poses={}
|
| 176 |
+
)
|
| 177 |
+
|
| 178 |
+
pose3d_trajectory[timestamp_ns].poses[object_uid] = pose3d
|
| 179 |
+
|
| 180 |
+
return pose3d_trajectory
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
def load_pose_provider_from_csv(filename: str) -> ObjectPose3dProvider:
|
| 184 |
+
"""
|
| 185 |
+
Load the ObjectPose3dProvider from a csv file
|
| 186 |
+
"""
|
| 187 |
+
return ObjectPose3dProvider(
|
| 188 |
+
pose3d_trajectory=load_object_pose_trajectory_from_csv(filename)
|
| 189 |
+
)
|
HOT3DHUGGFACE/data_loaders/PathProvider.py
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
import os
|
| 16 |
+
from abc import abstractmethod
|
| 17 |
+
|
| 18 |
+
from .headsets import Headset
|
| 19 |
+
from .io_utils import load_json
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
#提供所有文件的地址
|
| 23 |
+
class SequenceDatasetPathsBase:
|
| 24 |
+
"""
|
| 25 |
+
Class defining the expected filepaths for a given HOT3D sequence
|
| 26 |
+
This base class can be extended to support headset specific filepaths (Aria, Quest, etc.)
|
| 27 |
+
"""
|
| 28 |
+
|
| 29 |
+
def __init__(self, recording_instance_folderpath):
|
| 30 |
+
self._recording_instance_folderpath = recording_instance_folderpath
|
| 31 |
+
|
| 32 |
+
@property
|
| 33 |
+
def recording_instance_folderpath(self):
|
| 34 |
+
return self._recording_instance_folderpath
|
| 35 |
+
|
| 36 |
+
@property
|
| 37 |
+
def dynamic_objects_filepath(self):
|
| 38 |
+
return f"{self._recording_instance_folderpath}/dynamic_objects.csv"
|
| 39 |
+
|
| 40 |
+
@property
|
| 41 |
+
def headset_trajectory_filepath(self):
|
| 42 |
+
return f"{self._recording_instance_folderpath}/headset_trajectory.csv"
|
| 43 |
+
|
| 44 |
+
@property
|
| 45 |
+
def mano_hand_pose_trajectory_filepath(self):
|
| 46 |
+
return f"{self._recording_instance_folderpath}/mano_hand_pose_trajectory.jsonl"
|
| 47 |
+
|
| 48 |
+
@property
|
| 49 |
+
def umetrack_hand_user_profile_filepath(self):
|
| 50 |
+
return f"{self._recording_instance_folderpath}/umetrack_hand_user_profile.json"
|
| 51 |
+
|
| 52 |
+
@property
|
| 53 |
+
def umetrack_hand_pose_trajectory_filepath(self):
|
| 54 |
+
return (
|
| 55 |
+
f"{self._recording_instance_folderpath}/umetrack_hand_pose_trajectory.jsonl"
|
| 56 |
+
)
|
| 57 |
+
|
| 58 |
+
@property
|
| 59 |
+
def vrs_filepath(self):
|
| 60 |
+
return f"{self._recording_instance_folderpath}/recording.vrs"
|
| 61 |
+
|
| 62 |
+
@property
|
| 63 |
+
def box2d_objects_filepath(self):
|
| 64 |
+
return f"{self._recording_instance_folderpath}/box2d_objects.csv"
|
| 65 |
+
|
| 66 |
+
@property
|
| 67 |
+
def box2d_hands_filepath(self):
|
| 68 |
+
return f"{self._recording_instance_folderpath}/box2d_hands.csv"
|
| 69 |
+
|
| 70 |
+
@property
|
| 71 |
+
def scene_metadata_filepath(self):
|
| 72 |
+
return f"{self._recording_instance_folderpath}/metadata.json"
|
| 73 |
+
|
| 74 |
+
@abstractmethod
|
| 75 |
+
def is_valid(self) -> bool:
|
| 76 |
+
"""
|
| 77 |
+
Returns if the list of required file for the Headset sequence are available
|
| 78 |
+
"""
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
class Hot3dDataPathProvider(object):
|
| 82 |
+
@staticmethod
|
| 83 |
+
def fromRecordingFolder(recording_instance_folderpath) -> SequenceDatasetPathsBase:
|
| 84 |
+
metadata_filepath = os.path.join(recording_instance_folderpath, "metadata.json")
|
| 85 |
+
metadata_json = load_json(metadata_filepath)
|
| 86 |
+
headset = Headset[metadata_json["headset"]]
|
| 87 |
+
|
| 88 |
+
if headset is Headset.Aria:
|
| 89 |
+
return AriaDatasetPaths(
|
| 90 |
+
recording_instance_folderpath=recording_instance_folderpath
|
| 91 |
+
)
|
| 92 |
+
elif headset is Headset.Quest3:
|
| 93 |
+
return Quest3DatasetPaths(
|
| 94 |
+
recording_instance_folderpath=recording_instance_folderpath
|
| 95 |
+
)
|
| 96 |
+
else:
|
| 97 |
+
raise NotImplementedError(f"{headset} not supported at the moment.")
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
#继承,子类自动拥有父类的所有属性和方法
|
| 101 |
+
class Quest3DatasetPaths(SequenceDatasetPathsBase):
|
| 102 |
+
def __init__(self, recording_instance_folderpath):
|
| 103 |
+
super().__init__(recording_instance_folderpath)
|
| 104 |
+
|
| 105 |
+
@property
|
| 106 |
+
def camera_models_filepath(self):
|
| 107 |
+
return f"{self._recording_instance_folderpath}/camera_models.json"
|
| 108 |
+
|
| 109 |
+
@property
|
| 110 |
+
def required_filepaths(self):
|
| 111 |
+
return [
|
| 112 |
+
self.vrs_filepath,
|
| 113 |
+
self.dynamic_objects_filepath,
|
| 114 |
+
self.headset_trajectory_filepath,
|
| 115 |
+
self.camera_models_filepath,
|
| 116 |
+
self.mano_hand_pose_trajectory_filepath,
|
| 117 |
+
]
|
| 118 |
+
|
| 119 |
+
def is_valid(self) -> bool:
|
| 120 |
+
return all(os.path.exists(filepath) for filepath in self.required_filepaths)
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
class AriaDatasetPaths(SequenceDatasetPathsBase):
|
| 124 |
+
def __init__(self, recording_instance_folderpath):
|
| 125 |
+
super().__init__(recording_instance_folderpath)
|
| 126 |
+
|
| 127 |
+
@property
|
| 128 |
+
def mps_folderpath(self):
|
| 129 |
+
return f"{self._recording_instance_folderpath}/mps"
|
| 130 |
+
|
| 131 |
+
@property
|
| 132 |
+
def required_filepaths(self):
|
| 133 |
+
return [
|
| 134 |
+
self.vrs_filepath,
|
| 135 |
+
self.dynamic_objects_filepath,
|
| 136 |
+
self.headset_trajectory_filepath,
|
| 137 |
+
self.mano_hand_pose_trajectory_filepath,
|
| 138 |
+
]
|
| 139 |
+
|
| 140 |
+
def is_valid(self) -> bool:
|
| 141 |
+
return all(os.path.exists(filepath) for filepath in self.required_filepaths)
|
HOT3DHUGGFACE/data_loaders/QuestDataProvider.py
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
from typing import Dict, List, Optional
|
| 16 |
+
|
| 17 |
+
import numpy as np
|
| 18 |
+
from data_loaders.frameset import compute_frameset_for_timestamp
|
| 19 |
+
from data_loaders.io_utils import load_json
|
| 20 |
+
from PIL import Image
|
| 21 |
+
from projectaria_tools.core.calibration import ( # @manual
|
| 22 |
+
CameraCalibration,
|
| 23 |
+
DeviceCadExtrinsics,
|
| 24 |
+
DeviceCalibration,
|
| 25 |
+
distort_by_calibration,
|
| 26 |
+
FISHEYE624,
|
| 27 |
+
get_linear_camera_calibration,
|
| 28 |
+
LINEAR,
|
| 29 |
+
)
|
| 30 |
+
from projectaria_tools.core.sensor_data import TimeDomain # @manual
|
| 31 |
+
from projectaria_tools.core.sophus import SE3 # @manual
|
| 32 |
+
from projectaria_tools.core.stream_id import StreamId # @manual
|
| 33 |
+
|
| 34 |
+
try:
|
| 35 |
+
from pyvrs import ImageConversion, SyncVRSReader # @manual
|
| 36 |
+
except ImportError:
|
| 37 |
+
from pyvrs2 import SyncVRSReader # @manual
|
| 38 |
+
from vrsbindings import ImageConversion # @manual
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
class QuestDataProvider:
|
| 42 |
+
#recording.vrs-----vrs_filepath,
|
| 43 |
+
#camera_models.json---device_calibration_filepath,
|
| 44 |
+
def __init__(self, vrs_filepath: str, device_calibration_filepath: str) -> None:
|
| 45 |
+
#打开VRS 文件
|
| 46 |
+
self._vrs_reader = SyncVRSReader(vrs_filepath)
|
| 47 |
+
# Configure Image conversion
|
| 48 |
+
#把所有图像像素值归一化到 [0, 1]
|
| 49 |
+
self._vrs_reader.set_image_conversion(ImageConversion.NORMALIZE)
|
| 50 |
+
#转换成 8位灰度图
|
| 51 |
+
self._vrs_reader.set_stream_type_image_conversion(
|
| 52 |
+
8010, ImageConversion.NORMALIZE_GREY8
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
# extract the streamids corresponding to the image streams
|
| 56 |
+
#判断这个流是否包含图像,只保留图像流,过滤掉 IMU、音频等其他流。
|
| 57 |
+
image_stream_ids = []
|
| 58 |
+
for stream_id in self._vrs_reader.stream_ids:
|
| 59 |
+
if self._vrs_reader.might_contain_images(stream_id):
|
| 60 |
+
image_stream_ids.append(stream_id)
|
| 61 |
+
image_stream_ids = sorted(image_stream_ids)
|
| 62 |
+
image_stream_ids = []
|
| 63 |
+
for stream_id in self._vrs_reader.stream_ids:
|
| 64 |
+
if self._vrs_reader.might_contain_images(stream_id):
|
| 65 |
+
image_stream_ids.append(stream_id)
|
| 66 |
+
image_stream_ids = sorted(image_stream_ids)
|
| 67 |
+
# Filter the reader
|
| 68 |
+
filtered_reader = self._vrs_reader.filtered_by_fields(
|
| 69 |
+
stream_ids=image_stream_ids
|
| 70 |
+
)
|
| 71 |
+
self._vrs_reader = filtered_reader
|
| 72 |
+
|
| 73 |
+
# Loading camera calibration data
|
| 74 |
+
device_calibration_json = load_json(device_calibration_filepath)
|
| 75 |
+
camera_calibration = {}
|
| 76 |
+
for it in device_calibration_json:
|
| 77 |
+
quaternion = it["T_Device_Camera"]["quaternion_wxyz"]
|
| 78 |
+
translation = it["T_Device_Camera"]["translation_xyz"]
|
| 79 |
+
image_height = it["imageHeight"]
|
| 80 |
+
image_width = it["imageWidth"]
|
| 81 |
+
label = it["label"]
|
| 82 |
+
max_solid_angle = 1 # Limiting the fov to a constant value.
|
| 83 |
+
# projection_model_type = it["projectionModelType"]
|
| 84 |
+
projection_params = it["projectionParams"]
|
| 85 |
+
serial_number = it["serialNumber"]
|
| 86 |
+
#两个分开的数据合并成一个 SE3
|
| 87 |
+
#有误导性的命名,T_world_device 实际上是从相机坐标系到设备坐标系的变换??
|
| 88 |
+
T_world_device = SE3.from_quat_and_translation(
|
| 89 |
+
quaternion[0],
|
| 90 |
+
quaternion[1:4],
|
| 91 |
+
translation,
|
| 92 |
+
)
|
| 93 |
+
# Skip focal_y and rely on a single focal length for x,y
|
| 94 |
+
projection_params = projection_params[:1] + projection_params[2:]
|
| 95 |
+
|
| 96 |
+
# Build the corresponding camera calibration object
|
| 97 |
+
camera_calibration[label] = CameraCalibration(
|
| 98 |
+
label,
|
| 99 |
+
FISHEYE624,
|
| 100 |
+
projection_params,
|
| 101 |
+
T_world_device,
|
| 102 |
+
image_width,
|
| 103 |
+
image_height,
|
| 104 |
+
None,
|
| 105 |
+
max_solid_angle,
|
| 106 |
+
serial_number,
|
| 107 |
+
)
|
| 108 |
+
|
| 109 |
+
self._device_calibration = DeviceCalibration(
|
| 110 |
+
camera_calibration,
|
| 111 |
+
{},
|
| 112 |
+
{},
|
| 113 |
+
{},
|
| 114 |
+
{},
|
| 115 |
+
DeviceCadExtrinsics(),
|
| 116 |
+
"",
|
| 117 |
+
"",
|
| 118 |
+
)
|
| 119 |
+
|
| 120 |
+
# Pre-compute the sorted timestamps for each image stream
|
| 121 |
+
self._stream_timestamps_sorted: Dict[str, List[int]] = {}
|
| 122 |
+
for stream_id in self.get_image_stream_ids():
|
| 123 |
+
self._stream_timestamps_sorted[str(stream_id)] = sorted(
|
| 124 |
+
self.get_sequence_timestamps()
|
| 125 |
+
)
|
| 126 |
+
|
| 127 |
+
def get_device_calibration(self) -> DeviceCalibration:
|
| 128 |
+
"""
|
| 129 |
+
Return the device calibration (factory calibration of all sensors)
|
| 130 |
+
"""
|
| 131 |
+
return self._device_calibration
|
| 132 |
+
#返回设备的相机标定数据,以及每个摄像头的内参
|
| 133 |
+
def get_camera_calibration(
|
| 134 |
+
self,
|
| 135 |
+
stream_id: StreamId,
|
| 136 |
+
camera_model=FISHEYE624,
|
| 137 |
+
) -> tuple[SE3, CameraCalibration]:
|
| 138 |
+
"""
|
| 139 |
+
Return the camera calibration of the device of the sequence as [Extrinsics, Intrinsics]
|
| 140 |
+
Note:
|
| 141 |
+
- A corresponding pinhole camera can be requested by using camera_model = LINEAR.
|
| 142 |
+
- This is the camera model used to generate the 'get_undistorted_image'.
|
| 143 |
+
"""
|
| 144 |
+
if not (camera_model is FISHEYE624 or camera_model is LINEAR):
|
| 145 |
+
raise ValueError(
|
| 146 |
+
"Invalid camera_model type, only FISHEYE624 and LINEAR are supported"
|
| 147 |
+
)
|
| 148 |
+
|
| 149 |
+
device_calibration = self.get_device_calibration()
|
| 150 |
+
# Map the string to the right label
|
| 151 |
+
stream_label = self.get_image_stream_label(stream_id)
|
| 152 |
+
stream_labels_str = [
|
| 153 |
+
self.get_image_stream_label(x) for x in self.get_image_stream_ids()
|
| 154 |
+
]
|
| 155 |
+
idx_stream = stream_labels_str.index(stream_label)
|
| 156 |
+
corresponding_calibration_label = device_calibration.get_camera_labels()[
|
| 157 |
+
idx_stream
|
| 158 |
+
]
|
| 159 |
+
camera_calibration = device_calibration.get_camera_calib(
|
| 160 |
+
corresponding_calibration_label
|
| 161 |
+
)
|
| 162 |
+
|
| 163 |
+
# Store the relative transform from device to camera
|
| 164 |
+
T_device_camera = camera_calibration.get_transform_device_camera()
|
| 165 |
+
|
| 166 |
+
# If a corresponding pinhole camera is requested, we build one on the fly
|
| 167 |
+
if camera_model == LINEAR:
|
| 168 |
+
focal_lengths = camera_calibration.get_focal_lengths()
|
| 169 |
+
image_size = camera_calibration.get_image_size()
|
| 170 |
+
camera_calibration = get_linear_camera_calibration(
|
| 171 |
+
image_size[0], image_size[1], focal_lengths[0]
|
| 172 |
+
)
|
| 173 |
+
# else return the native FISHEYE624 camera model
|
| 174 |
+
|
| 175 |
+
return [T_device_camera, camera_calibration]
|
| 176 |
+
|
| 177 |
+
def get_image_stream_ids(self) -> List[StreamId]:
|
| 178 |
+
# retrieve all streams ids and filter the one that are image based
|
| 179 |
+
image_stream_ids = []
|
| 180 |
+
for stream_id in self._vrs_reader.stream_ids:
|
| 181 |
+
if self._vrs_reader.might_contain_images(stream_id):
|
| 182 |
+
image_stream_ids.append(stream_id)
|
| 183 |
+
image_stream_ids = sorted(image_stream_ids)
|
| 184 |
+
return [StreamId(x) for x in image_stream_ids]
|
| 185 |
+
|
| 186 |
+
def get_sequence_timestamps(self) -> List[int]:
|
| 187 |
+
"""
|
| 188 |
+
Returns the list of "time code" timestamp for the sequence
|
| 189 |
+
"""
|
| 190 |
+
timestamps = self._vrs_reader.get_timestamp_list()
|
| 191 |
+
# convert timestamp from float to int in ns
|
| 192 |
+
return sorted({int(x * 1e9) for x in timestamps})
|
| 193 |
+
|
| 194 |
+
def get_frameset_from_timestamp(
|
| 195 |
+
self,
|
| 196 |
+
timestamp_ns: int,
|
| 197 |
+
frameset_acceptable_time_diff_ns: int,
|
| 198 |
+
time_domain: TimeDomain = TimeDomain.TIME_CODE,
|
| 199 |
+
) -> Dict[str, Optional[int]]:
|
| 200 |
+
"""
|
| 201 |
+
Computes a frameset from a given timestamp within an acceptable time difference.
|
| 202 |
+
The frameset consists of the closest timestamps for each stream that are within the acceptable time difference.
|
| 203 |
+
For Quest3, the recommended acceptable time difference is 1e6 ns (or 1ms).
|
| 204 |
+
Returns a dictionary mapping each str(StreamId) to its closest timestamp.
|
| 205 |
+
"""
|
| 206 |
+
if time_domain is not TimeDomain.TIME_CODE:
|
| 207 |
+
raise ValueError(
|
| 208 |
+
f"{time_domain} is not supported. Only TIME_CODE is supported"
|
| 209 |
+
)
|
| 210 |
+
out_frameset = compute_frameset_for_timestamp(
|
| 211 |
+
stream_timestamps_sorted=self._stream_timestamps_sorted,
|
| 212 |
+
target_timestamp=timestamp_ns,
|
| 213 |
+
frameset_acceptable_time_diff=frameset_acceptable_time_diff_ns,
|
| 214 |
+
)
|
| 215 |
+
return out_frameset
|
| 216 |
+
|
| 217 |
+
def get_image_stream_label(self, stream_id: StreamId) -> str:
|
| 218 |
+
return str(stream_id)
|
| 219 |
+
|
| 220 |
+
def get_image(self, timestamp_ns: int, stream_id: StreamId) -> Optional[np.ndarray]:
|
| 221 |
+
try:
|
| 222 |
+
record = self._vrs_reader.read_record_by_time(
|
| 223 |
+
stream_id=self.get_image_stream_label(stream_id),
|
| 224 |
+
timestamp=timestamp_ns / 1e9,
|
| 225 |
+
)
|
| 226 |
+
except ValueError as e:
|
| 227 |
+
print(
|
| 228 |
+
f"No record found for timestamp {timestamp_ns} and stream {stream_id}. Caught exception: {e}"
|
| 229 |
+
)
|
| 230 |
+
record = None
|
| 231 |
+
|
| 232 |
+
if record is not None and record.record_type == "data":
|
| 233 |
+
grey8 = Image.fromarray(record.image_blocks[0])
|
| 234 |
+
return np.array(grey8)
|
| 235 |
+
else:
|
| 236 |
+
print(f"No image found for timestamp {timestamp_ns} and stream {stream_id}")
|
| 237 |
+
return None
|
| 238 |
+
|
| 239 |
+
def get_undistorted_image(
|
| 240 |
+
self, timestamp_ns: int, stream_id: StreamId
|
| 241 |
+
) -> Optional[np.ndarray]:
|
| 242 |
+
image = self.get_image(timestamp_ns, stream_id)
|
| 243 |
+
if image is None:
|
| 244 |
+
return None
|
| 245 |
+
|
| 246 |
+
[T_device_camera, native_camera_calibration] = self.get_camera_calibration(
|
| 247 |
+
stream_id, camera_model=FISHEYE624
|
| 248 |
+
)
|
| 249 |
+
[T_device_camera, pinhole_camera_calibration] = self.get_camera_calibration(
|
| 250 |
+
stream_id, camera_model=LINEAR
|
| 251 |
+
)
|
| 252 |
+
|
| 253 |
+
# Compute the actual undistorted image
|
| 254 |
+
undistorted_image = distort_by_calibration(
|
| 255 |
+
image, pinhole_camera_calibration, native_camera_calibration
|
| 256 |
+
)
|
| 257 |
+
return undistorted_image
|
HOT3DHUGGFACE/data_loaders/UmeTrackHandDataProvider.py
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
import json
|
| 16 |
+
from dataclasses import dataclass
|
| 17 |
+
from typing import Any, Dict, List, Optional
|
| 18 |
+
|
| 19 |
+
import numpy as np
|
| 20 |
+
import torch
|
| 21 |
+
from data_loaders.HandDataProviderBase import HandDataProviderBase
|
| 22 |
+
from data_loaders.loader_hand_poses import Handedness, HandPose
|
| 23 |
+
from data_loaders.umetrack_layer import get_skinning_weights, skin_points
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
@dataclass
|
| 27 |
+
class UmeTrackHandModelData:
|
| 28 |
+
joint_rotation_axes: torch.Tensor
|
| 29 |
+
joint_rest_positions: torch.Tensor
|
| 30 |
+
joint_frame_index: torch.Tensor
|
| 31 |
+
joint_parent: torch.Tensor
|
| 32 |
+
joint_first_child: torch.Tensor
|
| 33 |
+
joint_next_sibling: torch.Tensor
|
| 34 |
+
landmark_rest_positions: torch.Tensor
|
| 35 |
+
landmark_rest_bone_weights: torch.Tensor
|
| 36 |
+
landmark_rest_bone_indices: torch.Tensor
|
| 37 |
+
hand_scale: Optional[torch.Tensor] = None
|
| 38 |
+
mesh_vertices: Optional[torch.Tensor] = None
|
| 39 |
+
mesh_triangles: Optional[torch.Tensor] = None
|
| 40 |
+
dense_bone_weights: Optional[torch.Tensor] = None
|
| 41 |
+
joint_limits: Optional[torch.Tensor] = None
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def from_dict(j: Dict[str, Any]) -> UmeTrackHandModelData:
|
| 45 |
+
model = UmeTrackHandModelData(**{k: torch.tensor(v) for k, v in j.items()})
|
| 46 |
+
MM_TO_M = 1e-3
|
| 47 |
+
model.joint_rest_positions *= MM_TO_M
|
| 48 |
+
model.landmark_rest_positions *= MM_TO_M
|
| 49 |
+
if model.mesh_vertices is not None:
|
| 50 |
+
model.mesh_vertices *= MM_TO_M
|
| 51 |
+
return model
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def load_hand_model_from_file(filename: str) -> Optional[UmeTrackHandModelData]:
|
| 55 |
+
with open(filename, "rb") as f:
|
| 56 |
+
hand_model_dict = json.load(f)
|
| 57 |
+
if "hand_model" in hand_model_dict.keys():
|
| 58 |
+
return from_dict(hand_model_dict["hand_model"])
|
| 59 |
+
return None
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
class UmeTrackHandDataProvider(HandDataProviderBase):
|
| 63 |
+
def __init__(
|
| 64 |
+
self, hand_pose_trajectory_filepath: str, hand_profile_filepath: str
|
| 65 |
+
) -> None:
|
| 66 |
+
super().__init__()
|
| 67 |
+
super()._init_hand_poses(hand_pose_trajectory_filepath)
|
| 68 |
+
|
| 69 |
+
# Hand profile
|
| 70 |
+
self._hand_model = (
|
| 71 |
+
None
|
| 72 |
+
if len(self._hand_poses) == 0
|
| 73 |
+
else load_hand_model_from_file(hand_profile_filepath)
|
| 74 |
+
)
|
| 75 |
+
|
| 76 |
+
def get_hand_mesh_vertices(
|
| 77 |
+
self, hand_wrist_data: HandPose
|
| 78 |
+
) -> Optional[torch.Tensor]:
|
| 79 |
+
"""
|
| 80 |
+
Return the hand mesh corresponding to given HandPose
|
| 81 |
+
"""
|
| 82 |
+
if hand_wrist_data.wrist_pose is not None and self._hand_model is not None:
|
| 83 |
+
hand_wrist_pose_matrix = hand_wrist_data.wrist_pose.to_matrix()
|
| 84 |
+
hand_wrist_pose_tensor = torch.from_numpy(hand_wrist_pose_matrix)
|
| 85 |
+
|
| 86 |
+
# self._hand_model is defined for the Left hand,
|
| 87 |
+
# flipping here the pose X axis is moving the Left Hand to a Right Hand
|
| 88 |
+
if hand_wrist_data.handedness == Handedness.Right:
|
| 89 |
+
hand_wrist_pose_tensor[:, 0] *= -1
|
| 90 |
+
|
| 91 |
+
mesh_vertices = skin_vertices(
|
| 92 |
+
self._hand_model,
|
| 93 |
+
torch.Tensor(hand_wrist_data.joint_angles),
|
| 94 |
+
hand_wrist_pose_tensor,
|
| 95 |
+
)
|
| 96 |
+
return mesh_vertices
|
| 97 |
+
return None
|
| 98 |
+
|
| 99 |
+
def get_hand_mesh_faces_and_normals(
|
| 100 |
+
self, hand_wrist_data: HandPose
|
| 101 |
+
) -> Optional[List[np.ndarray]]:
|
| 102 |
+
"""
|
| 103 |
+
Return the hand mesh faces and normals
|
| 104 |
+
"""
|
| 105 |
+
if self._hand_model is not None and self._hand_model.mesh_triangles is not None:
|
| 106 |
+
hand_triangles = self._hand_model.mesh_triangles.int().numpy()
|
| 107 |
+
vertices = self.get_hand_mesh_vertices(hand_wrist_data)
|
| 108 |
+
assert vertices is not None
|
| 109 |
+
normals = HandDataProviderBase.get_triangular_mesh_normals(
|
| 110 |
+
vertices.float().numpy(), hand_triangles
|
| 111 |
+
)
|
| 112 |
+
return [hand_triangles, normals]
|
| 113 |
+
else:
|
| 114 |
+
return None
|
| 115 |
+
|
| 116 |
+
def get_hand_landmarks(self, hand_wrist_data: HandPose) -> Optional[torch.Tensor]:
|
| 117 |
+
"""
|
| 118 |
+
Return the hand joint landmarks corresponding to given HandPose
|
| 119 |
+
See how to map the vertices together to represent a Hand as linked lines using LANDMARK_CONNECTIVITY
|
| 120 |
+
"""
|
| 121 |
+
if self._hand_model is not None and self._hand_model.mesh_triangles is not None:
|
| 122 |
+
hand_wrist_pose_matrix = hand_wrist_data.wrist_pose.to_matrix()
|
| 123 |
+
hand_wrist_pose_tensor = torch.from_numpy(hand_wrist_pose_matrix)
|
| 124 |
+
|
| 125 |
+
# self._hand_model is defined for the Left hand,
|
| 126 |
+
# flipping here the pose X axis is moving the Left Hand to a Right Hand
|
| 127 |
+
if hand_wrist_data.handedness == Handedness.Right:
|
| 128 |
+
hand_wrist_pose_tensor[:, 0] *= -1
|
| 129 |
+
|
| 130 |
+
hand_landmarks = skin_landmarks(
|
| 131 |
+
self._hand_model,
|
| 132 |
+
torch.Tensor(hand_wrist_data.joint_angles),
|
| 133 |
+
hand_wrist_pose_tensor,
|
| 134 |
+
)
|
| 135 |
+
return hand_landmarks
|
| 136 |
+
|
| 137 |
+
return None
|
| 138 |
+
|
| 139 |
+
|
| 140 |
+
NUM_JOINT_FRAMES: int = 1 + 1 + 3 * 5 # root + wrist + finger frames * 5
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
def skin_landmarks(
|
| 144 |
+
hand_model: UmeTrackHandModelData,
|
| 145 |
+
joint_angles: torch.Tensor,
|
| 146 |
+
wrist_transforms: torch.Tensor,
|
| 147 |
+
) -> torch.Tensor:
|
| 148 |
+
leading_dims = joint_angles.shape[:-1]
|
| 149 |
+
numel = torch.flatten(joint_angles, end_dim=-2).shape[0] if len(leading_dims) else 1
|
| 150 |
+
max_weights = hand_model.landmark_rest_bone_indices.shape[-1]
|
| 151 |
+
skin_mat = get_skinning_weights(
|
| 152 |
+
hand_model.landmark_rest_bone_indices.reshape(numel, -1, max_weights),
|
| 153 |
+
hand_model.landmark_rest_bone_weights.reshape(numel, -1, max_weights),
|
| 154 |
+
NUM_JOINT_FRAMES,
|
| 155 |
+
)
|
| 156 |
+
return skin_points(
|
| 157 |
+
hand_model.joint_rest_positions.double(),
|
| 158 |
+
hand_model.joint_rotation_axes.double(),
|
| 159 |
+
skin_mat.double(),
|
| 160 |
+
joint_angles.double(),
|
| 161 |
+
hand_model.landmark_rest_positions.double(),
|
| 162 |
+
wrist_transforms.double(),
|
| 163 |
+
)
|
| 164 |
+
|
| 165 |
+
|
| 166 |
+
def skin_vertices(
|
| 167 |
+
hand_model: UmeTrackHandModelData,
|
| 168 |
+
joint_angles: torch.Tensor,
|
| 169 |
+
wrist_transforms: Optional[torch.Tensor] = None,
|
| 170 |
+
) -> torch.Tensor:
|
| 171 |
+
assert hand_model.mesh_vertices is not None, "mesh vertices should not be none"
|
| 172 |
+
assert hand_model.dense_bone_weights is not None, (
|
| 173 |
+
"dense bone weights should not be none"
|
| 174 |
+
)
|
| 175 |
+
vertices = skin_points(
|
| 176 |
+
hand_model.joint_rest_positions.double(),
|
| 177 |
+
hand_model.joint_rotation_axes.double(),
|
| 178 |
+
hand_model.dense_bone_weights.double(),
|
| 179 |
+
joint_angles.double(),
|
| 180 |
+
hand_model.mesh_vertices.double(),
|
| 181 |
+
wrist_transforms.double(),
|
| 182 |
+
)
|
| 183 |
+
|
| 184 |
+
leading_dims = joint_angles.shape[:-1]
|
| 185 |
+
vertices = vertices.reshape(list(leading_dims) + list(vertices.shape[-2:]))
|
| 186 |
+
return vertices
|
HOT3DHUGGFACE/data_loaders/constants.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
POSE_DATA_CSV_COLUMNS = [
|
| 16 |
+
"object_uid",
|
| 17 |
+
"timestamp[ns]",
|
| 18 |
+
"t_wo_x[m]",
|
| 19 |
+
"t_wo_y[m]",
|
| 20 |
+
"t_wo_z[m]",
|
| 21 |
+
"q_wo_w",
|
| 22 |
+
"q_wo_x",
|
| 23 |
+
"q_wo_y",
|
| 24 |
+
"q_wo_z",
|
| 25 |
+
]
|
| 26 |
+
|
| 27 |
+
BOX2D_DATA_CSV_COLUMNS = [
|
| 28 |
+
"stream_id",
|
| 29 |
+
"object_uid",
|
| 30 |
+
"timestamp[ns]",
|
| 31 |
+
"x_min[pixel]",
|
| 32 |
+
"x_max[pixel]",
|
| 33 |
+
"y_min[pixel]",
|
| 34 |
+
"y_max[pixel]",
|
| 35 |
+
"visibility_ratio[%]",
|
| 36 |
+
]
|
| 37 |
+
|
| 38 |
+
HAND_BOX2D_DATA_CSV_COLUMNS = [
|
| 39 |
+
"stream_id",
|
| 40 |
+
"hand_index",
|
| 41 |
+
"timestamp[ns]",
|
| 42 |
+
"x_min[pixel]",
|
| 43 |
+
"x_max[pixel]",
|
| 44 |
+
"y_min[pixel]",
|
| 45 |
+
"y_max[pixel]",
|
| 46 |
+
"visibility_ratio[%]",
|
| 47 |
+
]
|
| 48 |
+
|
| 49 |
+
MASK_DATA_CSV_COLUMNS = [
|
| 50 |
+
"timestamp[ns]",
|
| 51 |
+
"stream_id",
|
| 52 |
+
"mask",
|
| 53 |
+
]
|
HOT3DHUGGFACE/data_loaders/frameset.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
import bisect
|
| 16 |
+
from typing import Dict, List, Optional
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def find_closest(sorted_input_list: List[int], target: int) -> int:
|
| 20 |
+
"""
|
| 21 |
+
Find the closest value in a sorted list to a target value
|
| 22 |
+
"""
|
| 23 |
+
index = bisect.bisect_left(sorted_input_list, target)
|
| 24 |
+
if index == 0:
|
| 25 |
+
closest = sorted_input_list[0]
|
| 26 |
+
elif index == len(sorted_input_list):
|
| 27 |
+
closest = sorted_input_list[-1]
|
| 28 |
+
else:
|
| 29 |
+
before = sorted_input_list[index - 1]
|
| 30 |
+
after = sorted_input_list[index]
|
| 31 |
+
if abs(target - after) > abs(target - before):
|
| 32 |
+
closest = before
|
| 33 |
+
else:
|
| 34 |
+
closest = after
|
| 35 |
+
return closest
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def compute_frameset_for_timestamp(
|
| 39 |
+
stream_timestamps_sorted: Dict[str, List[int]],
|
| 40 |
+
target_timestamp: int,
|
| 41 |
+
frameset_acceptable_time_diff: int,
|
| 42 |
+
) -> Dict[str, Optional[int]]:
|
| 43 |
+
"""
|
| 44 |
+
Compute the frameset for a given timestamp.
|
| 45 |
+
The frameset consists of the closest timestamps for each stream that are within the acceptable time difference.
|
| 46 |
+
Args:
|
| 47 |
+
stream_timestamps_sorted: A dictionary containing lists of sorted timestamps indexed by str(StreamId).
|
| 48 |
+
target_timestamp: The target timestamp to compute the frameset for.
|
| 49 |
+
frameset_acceptable_time_diff: The maximum difference between the target timestamp and the closest timestamp in each stream.
|
| 50 |
+
Returns:
|
| 51 |
+
A dictionary of str(StreamId) to timestamps which defines a frameset at the target timestamp.
|
| 52 |
+
"""
|
| 53 |
+
|
| 54 |
+
stream_id_strs = list(stream_timestamps_sorted.keys())
|
| 55 |
+
frameset = {}
|
| 56 |
+
for stream_id_str in stream_id_strs:
|
| 57 |
+
closest_timestamp = find_closest(
|
| 58 |
+
sorted_input_list=stream_timestamps_sorted[stream_id_str],
|
| 59 |
+
target=target_timestamp,
|
| 60 |
+
)
|
| 61 |
+
if abs(closest_timestamp - target_timestamp) < frameset_acceptable_time_diff:
|
| 62 |
+
frameset[stream_id_str] = closest_timestamp
|
| 63 |
+
else:
|
| 64 |
+
frameset[stream_id_str] = None
|
| 65 |
+
|
| 66 |
+
return frameset
|
HOT3DHUGGFACE/data_loaders/hand_common.py
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
from enum import Enum
|
| 16 |
+
|
| 17 |
+
# Define a HAND with 21 landmarks
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
class LANDMARK(Enum):
|
| 21 |
+
THUMB_FINGERTIP = "Thumb fingertip"
|
| 22 |
+
INDEX_FINGER_FINGERTIP = "Index finger fingertip"
|
| 23 |
+
MIDDLE_FINGER_FINGERTIP = "Middle finger fingertip"
|
| 24 |
+
RING_FINGER_FINGERTIP = "Ring finger fingertip"
|
| 25 |
+
PINKY_FINGER_FINGERTIP = "Pinky finger fingertip"
|
| 26 |
+
WRIST_JOINT = "Wrist joint"
|
| 27 |
+
THUMB_INTERMEDIATE_FRAME = "Thumb intermediate frame"
|
| 28 |
+
THUMB_DISTAL_FRAME = "Thumb distal frame"
|
| 29 |
+
INDEX_PROXIMAL_FRAME = "Index proximal frame"
|
| 30 |
+
INDEX_INTERMEDIATE_FRAME = "Index intermediate frame"
|
| 31 |
+
INDEX_DISTAL_FRAME = "Index distal frame"
|
| 32 |
+
MIDDLE_PROXIMAL_FRAME = "Middle proximal frame"
|
| 33 |
+
MIDDLE_INTERMEDIATE_FRAME = "Middle intermediate frame"
|
| 34 |
+
MIDDLE_DISTAL_FRAME = "Middle distal frame"
|
| 35 |
+
RING_PROXIMAL_FRAME = "Ring proximal frame"
|
| 36 |
+
RING_INTERMEDIATE_FRAME = "Ring intermediate frame"
|
| 37 |
+
RING_DISTAL_FRAME = "Ring distal frame"
|
| 38 |
+
PINKY_PROXIMAL_FRAME = "Pinky proximal frame"
|
| 39 |
+
PINKY_INTERMEDIATE_FRAME = "Pinky intermediate frame"
|
| 40 |
+
PINKY_DISTAL_FRAME = "Pinky distal frame"
|
| 41 |
+
PALM_CENTER = "Palm center"
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
LANDMARK_INDEX_TO_NAMING = [
|
| 45 |
+
LANDMARK.THUMB_FINGERTIP,
|
| 46 |
+
LANDMARK.INDEX_FINGER_FINGERTIP,
|
| 47 |
+
LANDMARK.MIDDLE_FINGER_FINGERTIP,
|
| 48 |
+
LANDMARK.RING_FINGER_FINGERTIP,
|
| 49 |
+
LANDMARK.PINKY_FINGER_FINGERTIP,
|
| 50 |
+
LANDMARK.WRIST_JOINT,
|
| 51 |
+
LANDMARK.THUMB_INTERMEDIATE_FRAME,
|
| 52 |
+
LANDMARK.THUMB_DISTAL_FRAME,
|
| 53 |
+
LANDMARK.INDEX_PROXIMAL_FRAME,
|
| 54 |
+
LANDMARK.INDEX_INTERMEDIATE_FRAME,
|
| 55 |
+
LANDMARK.INDEX_DISTAL_FRAME,
|
| 56 |
+
LANDMARK.MIDDLE_PROXIMAL_FRAME,
|
| 57 |
+
LANDMARK.MIDDLE_INTERMEDIATE_FRAME,
|
| 58 |
+
LANDMARK.MIDDLE_DISTAL_FRAME,
|
| 59 |
+
LANDMARK.RING_PROXIMAL_FRAME,
|
| 60 |
+
LANDMARK.RING_INTERMEDIATE_FRAME,
|
| 61 |
+
LANDMARK.RING_DISTAL_FRAME,
|
| 62 |
+
LANDMARK.PINKY_PROXIMAL_FRAME,
|
| 63 |
+
LANDMARK.PINKY_INTERMEDIATE_FRAME,
|
| 64 |
+
LANDMARK.PINKY_DISTAL_FRAME,
|
| 65 |
+
LANDMARK.PALM_CENTER,
|
| 66 |
+
]
|
| 67 |
+
|
| 68 |
+
LANDMARK_NAMING_TO_INDEX = {k: i for i, k in enumerate(LANDMARK_INDEX_TO_NAMING)}
|
| 69 |
+
|
| 70 |
+
LANDMARK_CONNECTIVITY = [
|
| 71 |
+
# pinky
|
| 72 |
+
[
|
| 73 |
+
LANDMARK_NAMING_TO_INDEX[LANDMARK.WRIST_JOINT],
|
| 74 |
+
LANDMARK_NAMING_TO_INDEX[LANDMARK.PINKY_PROXIMAL_FRAME],
|
| 75 |
+
],
|
| 76 |
+
[
|
| 77 |
+
LANDMARK_NAMING_TO_INDEX[LANDMARK.PINKY_PROXIMAL_FRAME],
|
| 78 |
+
LANDMARK_NAMING_TO_INDEX[LANDMARK.PINKY_INTERMEDIATE_FRAME],
|
| 79 |
+
],
|
| 80 |
+
[
|
| 81 |
+
LANDMARK_NAMING_TO_INDEX[LANDMARK.PINKY_INTERMEDIATE_FRAME],
|
| 82 |
+
LANDMARK_NAMING_TO_INDEX[LANDMARK.PINKY_DISTAL_FRAME],
|
| 83 |
+
],
|
| 84 |
+
[
|
| 85 |
+
LANDMARK_NAMING_TO_INDEX[LANDMARK.PINKY_DISTAL_FRAME],
|
| 86 |
+
LANDMARK_NAMING_TO_INDEX[LANDMARK.PINKY_FINGER_FINGERTIP],
|
| 87 |
+
],
|
| 88 |
+
# ring
|
| 89 |
+
[
|
| 90 |
+
LANDMARK_NAMING_TO_INDEX[LANDMARK.WRIST_JOINT],
|
| 91 |
+
LANDMARK_NAMING_TO_INDEX[LANDMARK.RING_PROXIMAL_FRAME],
|
| 92 |
+
],
|
| 93 |
+
[
|
| 94 |
+
LANDMARK_NAMING_TO_INDEX[LANDMARK.RING_PROXIMAL_FRAME],
|
| 95 |
+
LANDMARK_NAMING_TO_INDEX[LANDMARK.RING_INTERMEDIATE_FRAME],
|
| 96 |
+
],
|
| 97 |
+
[
|
| 98 |
+
LANDMARK_NAMING_TO_INDEX[LANDMARK.RING_INTERMEDIATE_FRAME],
|
| 99 |
+
LANDMARK_NAMING_TO_INDEX[LANDMARK.RING_DISTAL_FRAME],
|
| 100 |
+
],
|
| 101 |
+
[
|
| 102 |
+
LANDMARK_NAMING_TO_INDEX[LANDMARK.RING_DISTAL_FRAME],
|
| 103 |
+
LANDMARK_NAMING_TO_INDEX[LANDMARK.RING_FINGER_FINGERTIP],
|
| 104 |
+
],
|
| 105 |
+
# middle
|
| 106 |
+
[
|
| 107 |
+
LANDMARK_NAMING_TO_INDEX[LANDMARK.WRIST_JOINT],
|
| 108 |
+
LANDMARK_NAMING_TO_INDEX[LANDMARK.MIDDLE_PROXIMAL_FRAME],
|
| 109 |
+
],
|
| 110 |
+
[
|
| 111 |
+
LANDMARK_NAMING_TO_INDEX[LANDMARK.MIDDLE_PROXIMAL_FRAME],
|
| 112 |
+
LANDMARK_NAMING_TO_INDEX[LANDMARK.MIDDLE_INTERMEDIATE_FRAME],
|
| 113 |
+
],
|
| 114 |
+
[
|
| 115 |
+
LANDMARK_NAMING_TO_INDEX[LANDMARK.MIDDLE_INTERMEDIATE_FRAME],
|
| 116 |
+
LANDMARK_NAMING_TO_INDEX[LANDMARK.MIDDLE_DISTAL_FRAME],
|
| 117 |
+
],
|
| 118 |
+
[
|
| 119 |
+
LANDMARK_NAMING_TO_INDEX[LANDMARK.MIDDLE_DISTAL_FRAME],
|
| 120 |
+
LANDMARK_NAMING_TO_INDEX[LANDMARK.MIDDLE_FINGER_FINGERTIP],
|
| 121 |
+
],
|
| 122 |
+
# index
|
| 123 |
+
[
|
| 124 |
+
LANDMARK_NAMING_TO_INDEX[LANDMARK.WRIST_JOINT],
|
| 125 |
+
LANDMARK_NAMING_TO_INDEX[LANDMARK.INDEX_PROXIMAL_FRAME],
|
| 126 |
+
],
|
| 127 |
+
[
|
| 128 |
+
LANDMARK_NAMING_TO_INDEX[LANDMARK.INDEX_PROXIMAL_FRAME],
|
| 129 |
+
LANDMARK_NAMING_TO_INDEX[LANDMARK.INDEX_INTERMEDIATE_FRAME],
|
| 130 |
+
],
|
| 131 |
+
[
|
| 132 |
+
LANDMARK_NAMING_TO_INDEX[LANDMARK.INDEX_INTERMEDIATE_FRAME],
|
| 133 |
+
LANDMARK_NAMING_TO_INDEX[LANDMARK.INDEX_DISTAL_FRAME],
|
| 134 |
+
],
|
| 135 |
+
[
|
| 136 |
+
LANDMARK_NAMING_TO_INDEX[LANDMARK.INDEX_DISTAL_FRAME],
|
| 137 |
+
LANDMARK_NAMING_TO_INDEX[LANDMARK.INDEX_FINGER_FINGERTIP],
|
| 138 |
+
],
|
| 139 |
+
# thumb
|
| 140 |
+
[
|
| 141 |
+
LANDMARK_NAMING_TO_INDEX[LANDMARK.WRIST_JOINT],
|
| 142 |
+
LANDMARK_NAMING_TO_INDEX[LANDMARK.THUMB_INTERMEDIATE_FRAME],
|
| 143 |
+
],
|
| 144 |
+
[
|
| 145 |
+
LANDMARK_NAMING_TO_INDEX[LANDMARK.THUMB_INTERMEDIATE_FRAME],
|
| 146 |
+
LANDMARK_NAMING_TO_INDEX[LANDMARK.THUMB_DISTAL_FRAME],
|
| 147 |
+
],
|
| 148 |
+
[
|
| 149 |
+
LANDMARK_NAMING_TO_INDEX[LANDMARK.THUMB_DISTAL_FRAME],
|
| 150 |
+
LANDMARK_NAMING_TO_INDEX[LANDMARK.THUMB_FINGERTIP],
|
| 151 |
+
],
|
| 152 |
+
# palm
|
| 153 |
+
[
|
| 154 |
+
LANDMARK_NAMING_TO_INDEX[LANDMARK.THUMB_INTERMEDIATE_FRAME],
|
| 155 |
+
LANDMARK_NAMING_TO_INDEX[LANDMARK.INDEX_PROXIMAL_FRAME],
|
| 156 |
+
],
|
| 157 |
+
[
|
| 158 |
+
LANDMARK_NAMING_TO_INDEX[LANDMARK.INDEX_PROXIMAL_FRAME],
|
| 159 |
+
LANDMARK_NAMING_TO_INDEX[LANDMARK.MIDDLE_PROXIMAL_FRAME],
|
| 160 |
+
],
|
| 161 |
+
[
|
| 162 |
+
LANDMARK_NAMING_TO_INDEX[LANDMARK.MIDDLE_PROXIMAL_FRAME],
|
| 163 |
+
LANDMARK_NAMING_TO_INDEX[LANDMARK.RING_PROXIMAL_FRAME],
|
| 164 |
+
],
|
| 165 |
+
[
|
| 166 |
+
LANDMARK_NAMING_TO_INDEX[LANDMARK.RING_PROXIMAL_FRAME],
|
| 167 |
+
LANDMARK_NAMING_TO_INDEX[LANDMARK.PINKY_PROXIMAL_FRAME],
|
| 168 |
+
],
|
| 169 |
+
]
|
HOT3DHUGGFACE/data_loaders/headsets.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
from enum import auto, Enum
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
class Headset(Enum):
|
| 19 |
+
Aria = auto()
|
| 20 |
+
Quest3 = auto()
|
HOT3DHUGGFACE/data_loaders/io_utils.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
import json
|
| 16 |
+
from typing import Any, Optional
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def load_json(json_filepath):
|
| 20 |
+
with open(json_filepath, "r") as fp:
|
| 21 |
+
return json.loads(fp.read())
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def write_json(payload, json_filepath):
|
| 25 |
+
with open(json_filepath, "w") as fp:
|
| 26 |
+
json.dump(payload, fp, indent=4, sort_keys=True)
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def is_float(x: Any) -> bool:
|
| 30 |
+
"""
|
| 31 |
+
Function checks if the input is convertible to float
|
| 32 |
+
"""
|
| 33 |
+
if x is None:
|
| 34 |
+
return False
|
| 35 |
+
if len(x) == 0:
|
| 36 |
+
return False
|
| 37 |
+
try:
|
| 38 |
+
float(x)
|
| 39 |
+
return True
|
| 40 |
+
except ValueError:
|
| 41 |
+
return False
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def is_int(x: Any) -> bool:
|
| 45 |
+
"""
|
| 46 |
+
Function checks if the input is convertible to int
|
| 47 |
+
"""
|
| 48 |
+
if x is None:
|
| 49 |
+
return False
|
| 50 |
+
if len(x) == 0:
|
| 51 |
+
return False
|
| 52 |
+
try:
|
| 53 |
+
int(x)
|
| 54 |
+
return True
|
| 55 |
+
except ValueError:
|
| 56 |
+
return False
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def float_or_none(x: Any) -> Optional[float]:
|
| 60 |
+
"""
|
| 61 |
+
Function returns a float if x is convertible to float, otherwise None
|
| 62 |
+
"""
|
| 63 |
+
return float(x) if is_float(x) else None
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def int_or_none(x: Any) -> Optional[int]:
|
| 67 |
+
"""
|
| 68 |
+
Function returns a int if x is convertible to int, otherwise None
|
| 69 |
+
"""
|
| 70 |
+
return int(x) if is_int(x) else None
|
HOT3DHUGGFACE/data_loaders/loader_hand_poses.py
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
import json
|
| 16 |
+
from dataclasses import dataclass
|
| 17 |
+
from enum import auto, Enum
|
| 18 |
+
from typing import Dict, List, Optional
|
| 19 |
+
|
| 20 |
+
import numpy as np
|
| 21 |
+
from projectaria_tools.core.sophus import SE3 # @manual
|
| 22 |
+
|
| 23 |
+
LEFT_HAND_INDEX = 0
|
| 24 |
+
RIGHT_HAND_INDEX = 1
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
class Handedness(Enum):
|
| 28 |
+
Left = int(LEFT_HAND_INDEX)
|
| 29 |
+
Right = int(RIGHT_HAND_INDEX)
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
class HandType(Enum):
|
| 33 |
+
Mano = auto()
|
| 34 |
+
Umetrack = auto()
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
@dataclass
|
| 38 |
+
class HandPose:
|
| 39 |
+
"""Define a Hand pose as wrist_pose (SE3), and joint_angles."""
|
| 40 |
+
|
| 41 |
+
handedness: Handedness
|
| 42 |
+
wrist_pose: Optional[SE3]
|
| 43 |
+
joint_angles: List[float]
|
| 44 |
+
|
| 45 |
+
def is_left_hand(self) -> bool:
|
| 46 |
+
return self.handedness == Handedness.Left
|
| 47 |
+
|
| 48 |
+
def is_right_hand(self) -> bool:
|
| 49 |
+
return self.handedness == Handedness.Right
|
| 50 |
+
|
| 51 |
+
def handedness_label(self) -> str:
|
| 52 |
+
return "left" if self.is_left_hand() else "right"
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
@dataclass
|
| 56 |
+
class HandPose3dCollection:
|
| 57 |
+
"""
|
| 58 |
+
Class to store the Hand poses for a given timestamp
|
| 59 |
+
"""
|
| 60 |
+
|
| 61 |
+
timestamp_ns: int
|
| 62 |
+
poses: Dict[Handedness, HandPose]
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
TimestampHandPoses3d = Dict[int, HandPose3dCollection]
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def _get_hand_pose(handedness: str, hand_poses_json: Dict) -> Optional[SE3]:
|
| 69 |
+
if handedness in hand_poses_json.keys():
|
| 70 |
+
wrist = hand_poses_json[handedness]["wrist_xform"]
|
| 71 |
+
#JSONL文件,可以直接用标签读取,不用像csv文件一样用header.index()读取
|
| 72 |
+
quaternion_w = wrist["q_wxyz"][0]
|
| 73 |
+
quaternion_xyz = wrist["q_wxyz"][1:4]
|
| 74 |
+
translation = wrist["t_xyz"]
|
| 75 |
+
hand_pose = SE3.from_quat_and_translation(
|
| 76 |
+
float(quaternion_w),
|
| 77 |
+
np.array([float(o) for o in quaternion_xyz]),
|
| 78 |
+
np.array([float(o) for o in translation]),
|
| 79 |
+
)[0]
|
| 80 |
+
return hand_pose
|
| 81 |
+
return None
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
def _get_joint_angles(handedness: str, hand_poses_json: Dict) -> Optional[List[float]]:
|
| 85 |
+
if handedness in hand_poses_json.keys():
|
| 86 |
+
if "pose" in hand_poses_json[handedness].keys():
|
| 87 |
+
return hand_poses_json[handedness]["pose"] # MANO pose_pca
|
| 88 |
+
elif "joint_angles" in hand_poses_json[handedness].keys():
|
| 89 |
+
return hand_poses_json[handedness]["joint_angles"] # UMETRACK joint angles
|
| 90 |
+
return None
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
def parse_hand_poses_from_fileobject(fileobject):
|
| 94 |
+
hand_poses_per_timestamp: TimestampHandPoses3d = {}
|
| 95 |
+
for line in fileobject:
|
| 96 |
+
# Parse the JSON file line
|
| 97 |
+
#把json转移成字典
|
| 98 |
+
hand_pose_instance = json.loads(line)
|
| 99 |
+
timestamp_ns = hand_pose_instance["timestamp_ns"]
|
| 100 |
+
hand_poses_json = hand_pose_instance["hand_poses"]
|
| 101 |
+
|
| 102 |
+
# Read hand pose data
|
| 103 |
+
# 在哪里
|
| 104 |
+
left_hand_pose = _get_hand_pose(str(LEFT_HAND_INDEX), hand_poses_json)
|
| 105 |
+
right_hand_pose = _get_hand_pose(str(RIGHT_HAND_INDEX), hand_poses_json)
|
| 106 |
+
|
| 107 |
+
# 各关节角度(手势)
|
| 108 |
+
left_joint_angles = _get_joint_angles(str(LEFT_HAND_INDEX), hand_poses_json)
|
| 109 |
+
right_joint_angles = _get_joint_angles(str(RIGHT_HAND_INDEX), hand_poses_json)
|
| 110 |
+
|
| 111 |
+
# If hand pose data is available, add it to the dictionary
|
| 112 |
+
if (
|
| 113 |
+
left_hand_pose is not None or right_hand_pose is not None
|
| 114 |
+
) and timestamp_ns not in hand_poses_per_timestamp:
|
| 115 |
+
#将hand_poses_per_timestamp[timestamp_ns]放入一个HandPose3dCollection对象,里面包含timestamp_ns=timestamp_ns, poses={}
|
| 116 |
+
hand_poses_per_timestamp[timestamp_ns] = HandPose3dCollection(
|
| 117 |
+
timestamp_ns=timestamp_ns, poses={}
|
| 118 |
+
)
|
| 119 |
+
|
| 120 |
+
if left_hand_pose is not None:
|
| 121 |
+
#调用上面创建的对象中的posees字典,poses是一个dict Dict[Handedness, HandPose]
|
| 122 |
+
#Handedness0=左手 Handedness1=右手
|
| 123 |
+
hand_poses_per_timestamp[timestamp_ns].poses[Handedness.Left] = HandPose(
|
| 124 |
+
Handedness.Left, left_hand_pose, left_joint_angles
|
| 125 |
+
)
|
| 126 |
+
|
| 127 |
+
if right_hand_pose is not None:
|
| 128 |
+
hand_poses_per_timestamp[timestamp_ns].poses[Handedness.Right] = HandPose(
|
| 129 |
+
Handedness.Right, right_hand_pose, right_joint_angles
|
| 130 |
+
)
|
| 131 |
+
return hand_poses_per_timestamp
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
def load_hand_poses(filename: str) -> TimestampHandPoses3d:
|
| 135 |
+
"""Load Hand Poses meta data from a JSONL file.
|
| 136 |
+
|
| 137 |
+
Keyword arguments:
|
| 138 |
+
filename -- the jsonl file i.e. sequence_folder + "/hand_pose_trajectory.jsonl"
|
| 139 |
+
"""
|
| 140 |
+
with open(filename, "r") as fobj:
|
| 141 |
+
hand_poses_per_timestamp = parse_hand_poses_from_fileobject(fobj)
|
| 142 |
+
|
| 143 |
+
return hand_poses_per_timestamp
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
def load_hand_pose_as_json_lines(filename: str) -> Dict[int, Dict]:
|
| 147 |
+
"""
|
| 148 |
+
Load Hand Poses as JSON payload (Dict) per timestamp from a json line file
|
| 149 |
+
"""
|
| 150 |
+
timestamp_jsons = {}
|
| 151 |
+
with open(filename, "r") as f:
|
| 152 |
+
for line in f:
|
| 153 |
+
# Parse the JSON file line
|
| 154 |
+
hand_pose_instance = json.loads(line)
|
| 155 |
+
timestamp_ns = hand_pose_instance["timestamp_ns"]
|
| 156 |
+
hand_poses_json = hand_pose_instance["hand_poses"]
|
| 157 |
+
timestamp_jsons[timestamp_ns] = hand_poses_json
|
| 158 |
+
return timestamp_jsons
|
| 159 |
+
|
| 160 |
+
|
| 161 |
+
def load_mano_shape_params(filename: str) -> Optional[List[float]]:
|
| 162 |
+
betas = None
|
| 163 |
+
with open(filename, "rb") as f:
|
| 164 |
+
for line in f:
|
| 165 |
+
hand_pose_instance = json.loads(line)
|
| 166 |
+
for handedness in ["0", "1"]:
|
| 167 |
+
if (
|
| 168 |
+
handedness in hand_pose_instance["hand_poses"].keys()
|
| 169 |
+
and "betas" in hand_pose_instance["hand_poses"][handedness]
|
| 170 |
+
):
|
| 171 |
+
betas = hand_pose_instance["hand_poses"][handedness]["betas"]
|
| 172 |
+
break
|
| 173 |
+
if betas is not None:
|
| 174 |
+
break
|
| 175 |
+
return betas
|
HOT3DHUGGFACE/data_loaders/loader_masks.py
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
import csv
|
| 16 |
+
from collections import Counter
|
| 17 |
+
from typing import Dict, List, Optional
|
| 18 |
+
|
| 19 |
+
import numpy as np
|
| 20 |
+
from projectaria_tools.core.stream_id import StreamId # @manual
|
| 21 |
+
|
| 22 |
+
from .constants import MASK_DATA_CSV_COLUMNS
|
| 23 |
+
from .loader_poses_utils import check_csv_columns
|
| 24 |
+
|
| 25 |
+
TimestampedMask = Dict[int, bool]
|
| 26 |
+
StreamMask = Dict[str, TimestampedMask]
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
class MaskData(object):
|
| 30 |
+
def __init__(self, mask_data: Optional[StreamMask] = None):
|
| 31 |
+
self._mask = mask_data if mask_data is not None else Dict[str, bool]
|
| 32 |
+
|
| 33 |
+
@property
|
| 34 |
+
def data(self):
|
| 35 |
+
return self._mask
|
| 36 |
+
|
| 37 |
+
@property
|
| 38 |
+
def stream_ids(self):
|
| 39 |
+
return [StreamId(x) for x in self._mask.keys()]
|
| 40 |
+
|
| 41 |
+
def stream_mask(self, stream_id: StreamId) -> Optional[TimestampedMask]:
|
| 42 |
+
return self._mask.get(str(stream_id), None)
|
| 43 |
+
|
| 44 |
+
def length(self, stream_id: StreamId) -> int:
|
| 45 |
+
if str(stream_id) not in self._mask:
|
| 46 |
+
return 0
|
| 47 |
+
return len(self._mask[str(stream_id)])
|
| 48 |
+
|
| 49 |
+
def num_true(self, stream_id: StreamId) -> int:
|
| 50 |
+
"""Return the number of True values"""
|
| 51 |
+
if str(stream_id) not in self._mask:
|
| 52 |
+
return 0
|
| 53 |
+
|
| 54 |
+
return Counter(self._mask[str(stream_id)].values()).get(True, 0)
|
| 55 |
+
|
| 56 |
+
def num_false(self, stream_id: StreamId) -> int:
|
| 57 |
+
"""Return the number of False values"""
|
| 58 |
+
if str(stream_id) not in self._mask:
|
| 59 |
+
return 0
|
| 60 |
+
return Counter(self._mask[str(stream_id)].values()).get(False, 0)
|
| 61 |
+
|
| 62 |
+
def stats(self):
|
| 63 |
+
return {
|
| 64 |
+
sid: {
|
| 65 |
+
"length": self.length(sid),
|
| 66 |
+
"num_true": self.num_true(sid),
|
| 67 |
+
"num_false": self.num_false(sid),
|
| 68 |
+
}
|
| 69 |
+
for sid in sorted(self._mask.keys())
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
def load_mask_data(mask_filename: str) -> MaskData:
|
| 74 |
+
"""Load mask data from a HOT3D mask CSV file.
|
| 75 |
+
Data saved as CSV with three columns:
|
| 76 |
+
# timestamp[ns],stream_id,mask
|
| 77 |
+
# 67842008213302,214-1,True
|
| 78 |
+
# ...
|
| 79 |
+
"""
|
| 80 |
+
mask = {}
|
| 81 |
+
with open(mask_filename, "r") as f:
|
| 82 |
+
reader = csv.reader(f)
|
| 83 |
+
|
| 84 |
+
# Read the header row
|
| 85 |
+
header = next(reader)
|
| 86 |
+
|
| 87 |
+
# Ensure we have the desired columns
|
| 88 |
+
check_csv_columns(header, MASK_DATA_CSV_COLUMNS)
|
| 89 |
+
|
| 90 |
+
# Read the rest of the rows in the CSV file
|
| 91 |
+
for row in reader:
|
| 92 |
+
timestamp_int = int(row[header.index("timestamp[ns]")])
|
| 93 |
+
stream_id_str = row[header.index("stream_id")]
|
| 94 |
+
value = row[header.index("mask")]
|
| 95 |
+
|
| 96 |
+
if stream_id_str not in mask:
|
| 97 |
+
mask[stream_id_str] = {}
|
| 98 |
+
|
| 99 |
+
mask[stream_id_str][timestamp_int] = bool(value == "True")
|
| 100 |
+
|
| 101 |
+
return MaskData(mask)
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
def combine_mask_data(
|
| 105 |
+
mask_list: List[MaskData],
|
| 106 |
+
operator: str = "and", # i.e 'and' or 'or'
|
| 107 |
+
) -> MaskData:
|
| 108 |
+
"""
|
| 109 |
+
Combine mask data from two or three sources given a logical operator.
|
| 110 |
+
"""
|
| 111 |
+
|
| 112 |
+
stream_id_strs = {str(y) for x in mask_list for y in x.stream_ids}
|
| 113 |
+
stream_ids = [StreamId(x) for x in stream_id_strs]
|
| 114 |
+
|
| 115 |
+
out_mask_dict = {}
|
| 116 |
+
for stream_id in stream_ids:
|
| 117 |
+
timestamped_mask_list = [x.stream_mask(stream_id=stream_id) for x in mask_list]
|
| 118 |
+
if any(x is None for x in timestamped_mask_list):
|
| 119 |
+
raise ValueError("mask data must be present for all streams")
|
| 120 |
+
out_mask_dict[str(stream_id)] = combine_timestamped_mask_data(
|
| 121 |
+
mask_list=timestamped_mask_list, operator=operator
|
| 122 |
+
)
|
| 123 |
+
return MaskData(out_mask_dict)
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
def combine_timestamped_mask_data(
|
| 127 |
+
mask_list: List[TimestampedMask],
|
| 128 |
+
operator: str = "and", # i.e 'and' or 'or'
|
| 129 |
+
) -> TimestampedMask:
|
| 130 |
+
if len(mask_list) > 0:
|
| 131 |
+
if not all(len(d) == len(mask_list[0]) for d in mask_list):
|
| 132 |
+
raise ValueError("Mask data must have the same length")
|
| 133 |
+
else:
|
| 134 |
+
raise ValueError("mask_list must not be empty")
|
| 135 |
+
|
| 136 |
+
## ensure the timestamps are identical across lists
|
| 137 |
+
reference_tsns_list = list(mask_list[0].keys())
|
| 138 |
+
for it in mask_list[1:]:
|
| 139 |
+
if list(it.keys()) != reference_tsns_list:
|
| 140 |
+
raise ValueError("Mask data must have the same timestamps")
|
| 141 |
+
|
| 142 |
+
resulting_array = np.array([mask_list[0][tsns] for tsns in reference_tsns_list])
|
| 143 |
+
# resulting_array = np.array(list(mask_list[0].values()))
|
| 144 |
+
for it in mask_list[1:]:
|
| 145 |
+
if operator == "and":
|
| 146 |
+
resulting_array = resulting_array & np.array(
|
| 147 |
+
[it[tsns] for tsns in reference_tsns_list]
|
| 148 |
+
)
|
| 149 |
+
elif operator == "or":
|
| 150 |
+
resulting_array = resulting_array | np.array(
|
| 151 |
+
[it[tsns] for tsns in reference_tsns_list]
|
| 152 |
+
)
|
| 153 |
+
else:
|
| 154 |
+
raise ValueError("Invalid operator")
|
| 155 |
+
|
| 156 |
+
return dict(zip(reference_tsns_list, resulting_array.tolist()))
|
HOT3DHUGGFACE/data_loaders/loader_object_library.py
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
import os
|
| 17 |
+
from typing import Any, Dict, Set
|
| 18 |
+
|
| 19 |
+
from .io_utils import load_json
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
class ObjectLibrary(object):
|
| 23 |
+
def __init__(self, object_library_json: Dict[str, Any], asset_folder: str):
|
| 24 |
+
self._object_library_json = object_library_json
|
| 25 |
+
(
|
| 26 |
+
self._object_id_to_name_dict,
|
| 27 |
+
self._object_name_to_id_dict,
|
| 28 |
+
) = self._get_object_id_name_mappings(object_library_json)
|
| 29 |
+
(
|
| 30 |
+
self._headset_id_to_name_dict,
|
| 31 |
+
self._headset_name_to_id_dict,
|
| 32 |
+
) = self._get_headset_id_name_mappings(object_library_json)
|
| 33 |
+
|
| 34 |
+
self._asset_folder = asset_folder
|
| 35 |
+
|
| 36 |
+
@property
|
| 37 |
+
def object_id_to_name_dict(self):
|
| 38 |
+
return self._object_id_to_name_dict
|
| 39 |
+
|
| 40 |
+
@property
|
| 41 |
+
def object_name_to_id_dict(self):
|
| 42 |
+
return self._object_name_to_id_dict
|
| 43 |
+
|
| 44 |
+
@property
|
| 45 |
+
def headset_id_to_name_dict(self):
|
| 46 |
+
return self._headset_id_to_name_dict
|
| 47 |
+
|
| 48 |
+
@property
|
| 49 |
+
def headset_name_to_id_dict(self):
|
| 50 |
+
return self._headset_name_to_id_dict
|
| 51 |
+
|
| 52 |
+
@property
|
| 53 |
+
def object_uids(self) -> Set[str]:
|
| 54 |
+
return set(self._object_name_to_id_dict.values())
|
| 55 |
+
|
| 56 |
+
@property
|
| 57 |
+
def headset_uids(self) -> Set[str]:
|
| 58 |
+
return set(self._headset_name_to_id_dict.values())
|
| 59 |
+
|
| 60 |
+
@property
|
| 61 |
+
def asset_folder_name(self) -> str:
|
| 62 |
+
return self._asset_folder
|
| 63 |
+
|
| 64 |
+
def _get_object_id_name_mappings(self, object_info_json):
|
| 65 |
+
object_id_to_name_dict = {
|
| 66 |
+
k: v["instance_name"]
|
| 67 |
+
for k, v in object_info_json.items()
|
| 68 |
+
if v["instance_type"] == "object" and v["motion_type"] == "dynamic"
|
| 69 |
+
}
|
| 70 |
+
object_name_to_id_dict = {v: k for k, v in object_id_to_name_dict.items()}
|
| 71 |
+
return object_id_to_name_dict, object_name_to_id_dict
|
| 72 |
+
|
| 73 |
+
def _get_headset_id_name_mappings(self, object_info_json):
|
| 74 |
+
headset_id_to_name_dict = {
|
| 75 |
+
k: v["instance_name"]
|
| 76 |
+
for k, v in object_info_json.items()
|
| 77 |
+
if v["instance_type"] == "headset"
|
| 78 |
+
}
|
| 79 |
+
headset_name_to_id_dict = {v: k for k, v in headset_id_to_name_dict.items()}
|
| 80 |
+
return headset_id_to_name_dict, headset_name_to_id_dict
|
| 81 |
+
|
| 82 |
+
@staticmethod
|
| 83 |
+
def get_cad_asset_path(object_library_folderpath: str, object_id: str) -> str:
|
| 84 |
+
return os.path.join(object_library_folderpath, f"{object_id}.glb")
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
def load_object_library(object_library_folderpath: str) -> ObjectLibrary:
|
| 88 |
+
instance_filepath = os.path.join(object_library_folderpath, "instance.json")
|
| 89 |
+
object_library_json = load_json(instance_filepath)
|
| 90 |
+
asset_folder = os.path.join(object_library_folderpath)
|
| 91 |
+
return ObjectLibrary(object_library_json, asset_folder)
|
HOT3DHUGGFACE/data_loaders/loader_poses_utils.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
from typing import List
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def check_csv_columns(csv_columns: List[str], expected_columns: List[str]) -> None:
|
| 20 |
+
"""Ensure csv_columns is containing all value from expected_columns"""
|
| 21 |
+
for column in csv_columns:
|
| 22 |
+
if column not in expected_columns:
|
| 23 |
+
raise ValueError(
|
| 24 |
+
"Invalid Object CSV format. Expected columns are: {}".format(
|
| 25 |
+
", ".join(expected_columns)
|
| 26 |
+
)
|
| 27 |
+
)
|
HOT3DHUGGFACE/data_loaders/mano_layer.py
ADDED
|
@@ -0,0 +1,314 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
import os
|
| 16 |
+
from typing import List, Optional
|
| 17 |
+
|
| 18 |
+
SMPLX_IMPORT_SUCCEEDED = False # default suppose we can't import SMPLX
|
| 19 |
+
|
| 20 |
+
try:
|
| 21 |
+
import smplx
|
| 22 |
+
|
| 23 |
+
SMPLX_IMPORT_SUCCEEDED = True
|
| 24 |
+
except ImportError:
|
| 25 |
+
print(
|
| 26 |
+
"INFO: HOT3D hands requires smplx (See our GitHub repository for more information on its installation)."
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
import torch
|
| 30 |
+
|
| 31 |
+
mano_joint_mapping = [
|
| 32 |
+
16,
|
| 33 |
+
17,
|
| 34 |
+
18,
|
| 35 |
+
19,
|
| 36 |
+
20,
|
| 37 |
+
0,
|
| 38 |
+
14,
|
| 39 |
+
15,
|
| 40 |
+
1,
|
| 41 |
+
2,
|
| 42 |
+
3,
|
| 43 |
+
4,
|
| 44 |
+
5,
|
| 45 |
+
6,
|
| 46 |
+
10,
|
| 47 |
+
11,
|
| 48 |
+
12,
|
| 49 |
+
7,
|
| 50 |
+
8,
|
| 51 |
+
9,
|
| 52 |
+
]
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
class MANOHandModel:
|
| 56 |
+
#一只手有 778 个 3D 顶点
|
| 57 |
+
N_VERT = 778
|
| 58 |
+
N_LANDMARKS = 21
|
| 59 |
+
#每一个手指N_VERT中的index分区
|
| 60 |
+
MANO_FINGERTIP_VERT_INDICES = {
|
| 61 |
+
"thumb": 744,
|
| 62 |
+
"index": 320,
|
| 63 |
+
"middle": 443,
|
| 64 |
+
"ring": 554,
|
| 65 |
+
"pinky": 671,
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
def __init__(
|
| 69 |
+
self,
|
| 70 |
+
mano_model_files_dir: str,
|
| 71 |
+
##手部关节索引列表:index list,也就是“索引列表”
|
| 72 |
+
joint_mapper: Optional[List] = mano_joint_mapping,
|
| 73 |
+
):
|
| 74 |
+
mano_left_filename = os.path.join(mano_model_files_dir, "MANO_LEFT.pkl")
|
| 75 |
+
mano_right_filename = os.path.join(mano_model_files_dir, "MANO_RIGHT.pkl")
|
| 76 |
+
|
| 77 |
+
#PCA 全称是 Principal Component Analysis,中文通常叫 主成分分析
|
| 78 |
+
#降维方法,把很多手部参数,压缩成更少的几个重要参数。
|
| 79 |
+
#使用PCA,15个参数描述手部姿势变化,10 个参数描述手的形状
|
| 80 |
+
self.use_pose_pca = True
|
| 81 |
+
self.num_pose_coeffs = 15
|
| 82 |
+
self.num_shape_params = 10
|
| 83 |
+
self.device = "cpu"
|
| 84 |
+
self.dtype = torch.float32
|
| 85 |
+
self.joint_mapper = joint_mapper
|
| 86 |
+
|
| 87 |
+
#smplx.create创建 mano左手模型,一个 PyTorch 模型对象
|
| 88 |
+
self.mano_layer_left = smplx.create(
|
| 89 |
+
mano_left_filename,
|
| 90 |
+
"mano",
|
| 91 |
+
use_pca=self.use_pose_pca,
|
| 92 |
+
is_rhand=False,
|
| 93 |
+
num_pca_comps=self.num_pose_coeffs,
|
| 94 |
+
)
|
| 95 |
+
self.mano_layer_left.to(self.device)
|
| 96 |
+
|
| 97 |
+
self.mano_layer_right = smplx.create(
|
| 98 |
+
mano_right_filename,
|
| 99 |
+
"mano",
|
| 100 |
+
use_pca=self.use_pose_pca,
|
| 101 |
+
is_rhand=True,
|
| 102 |
+
num_pca_comps=self.num_pose_coeffs,
|
| 103 |
+
)
|
| 104 |
+
self.mano_layer_right.to(self.device)
|
| 105 |
+
|
| 106 |
+
#左右手同向bug
|
| 107 |
+
# fix MANO shapedirs of the left hand bug (https://github.com/vchoutas/smplx/issues/48)
|
| 108 |
+
if (
|
| 109 |
+
torch.sum(
|
| 110 |
+
torch.abs(
|
| 111 |
+
self.mano_layer_left.shapedirs[:, 0, :]
|
| 112 |
+
- self.mano_layer_right.shapedirs[:, 0, :]
|
| 113 |
+
)
|
| 114 |
+
)
|
| 115 |
+
< 1
|
| 116 |
+
):
|
| 117 |
+
self.mano_layer_left.shapedirs[:, 0, :] *= -1
|
| 118 |
+
|
| 119 |
+
def forward_kinematics(
|
| 120 |
+
self,
|
| 121 |
+
shape_params: torch.Tensor,
|
| 122 |
+
#手指怎么弯、怎么张开
|
| 123 |
+
joint_angles: torch.Tensor,
|
| 124 |
+
#手的方向
|
| 125 |
+
global_xfrom: torch.Tensor,
|
| 126 |
+
is_right_hand: torch.Tensor,
|
| 127 |
+
#tuple元组,固定结构的返回值,x, y = get_result()
|
| 128 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 129 |
+
assert shape_params.shape[0] == self.num_shape_params
|
| 130 |
+
#在第 0 维前面加一个新维度,统一成 batch 格式。
|
| 131 |
+
is_batched = len(joint_angles.shape) == 2
|
| 132 |
+
if len(global_xfrom.shape) == 1:
|
| 133 |
+
global_xfrom = torch.unsqueeze(global_xfrom, 0)
|
| 134 |
+
|
| 135 |
+
assert global_xfrom.shape[1] == 6
|
| 136 |
+
if len(joint_angles.shape) == 1:
|
| 137 |
+
joint_angles = torch.unsqueeze(joint_angles, 0)
|
| 138 |
+
|
| 139 |
+
if self.use_pose_pca:
|
| 140 |
+
assert joint_angles.shape[1] == self.num_pose_coeffs
|
| 141 |
+
assert is_right_hand.shape[0] == joint_angles.shape[0]
|
| 142 |
+
|
| 143 |
+
num_frames = joint_angles.shape[0]
|
| 144 |
+
|
| 145 |
+
# Left hand FK
|
| 146 |
+
if torch.any(torch.logical_not(is_right_hand)):
|
| 147 |
+
#取出左手的 global_xfrom 和 joint_angles
|
| 148 |
+
left_global_xform = global_xfrom[torch.logical_not(is_right_hand)]
|
| 149 |
+
left_joint_angles = joint_angles[torch.logical_not(is_right_hand)]
|
| 150 |
+
#调用之前的left hand模型
|
| 151 |
+
left_mano_output = self.mano_layer_left(
|
| 152 |
+
#复制shape_params匹配batch大小
|
| 153 |
+
betas=shape_params[None]
|
| 154 |
+
.repeat(left_global_xform.shape[0], 1)
|
| 155 |
+
.to(self.dtype),
|
| 156 |
+
#手的朝向
|
| 157 |
+
global_orient=left_global_xform[:, :3].to(self.dtype),
|
| 158 |
+
hand_pose=left_joint_angles.to(self.dtype),
|
| 159 |
+
#整只手的平移
|
| 160 |
+
transl=left_global_xform[:, 3:].to(self.dtype),
|
| 161 |
+
#返回手部 mesh 顶点
|
| 162 |
+
return_verts=True, # MANO doesn't return landmarks as well if this is false
|
| 163 |
+
)
|
| 164 |
+
|
| 165 |
+
# Right hand FK
|
| 166 |
+
if torch.any(is_right_hand):
|
| 167 |
+
right_global_xform = global_xfrom[is_right_hand]
|
| 168 |
+
right_joint_angles = joint_angles[is_right_hand]
|
| 169 |
+
right_mano_output = self.mano_layer_right(
|
| 170 |
+
betas=shape_params[None]
|
| 171 |
+
.repeat(right_global_xform.shape[0], 1)
|
| 172 |
+
.to(self.dtype),
|
| 173 |
+
global_orient=right_global_xform[:, :3].to(self.dtype),
|
| 174 |
+
hand_pose=right_joint_angles.to(self.dtype),
|
| 175 |
+
transl=right_global_xform[:, 3:].to(self.dtype),
|
| 176 |
+
return_verts=True, # MANO doesn't return landmarks as well if this is false
|
| 177 |
+
)
|
| 178 |
+
|
| 179 |
+
# Merge the left and right hand outputs
|
| 180 |
+
#把左右手的顶点和关节合并到一起(mesh)
|
| 181 |
+
out_vertices = torch.zeros(
|
| 182 |
+
(
|
| 183 |
+
num_frames,
|
| 184 |
+
self.N_VERT,
|
| 185 |
+
3,
|
| 186 |
+
)
|
| 187 |
+
).to(self.device)
|
| 188 |
+
if torch.any(torch.logical_not(is_right_hand)):
|
| 189 |
+
out_vertices[torch.logical_not(is_right_hand)] = left_mano_output.vertices
|
| 190 |
+
if torch.sum(is_right_hand) > 0:
|
| 191 |
+
out_vertices[is_right_hand] = right_mano_output.vertices
|
| 192 |
+
|
| 193 |
+
#把左右手的顶点和关节合并到一起(points)
|
| 194 |
+
out_landmarks = torch.zeros(
|
| 195 |
+
(
|
| 196 |
+
num_frames,
|
| 197 |
+
self.N_LANDMARKS,
|
| 198 |
+
3,
|
| 199 |
+
)
|
| 200 |
+
).to(self.device)
|
| 201 |
+
if torch.any(torch.logical_not(is_right_hand)):
|
| 202 |
+
if left_mano_output.joints.shape[1] != self.N_LANDMARKS:
|
| 203 |
+
extra_joints = torch.index_select(
|
| 204 |
+
left_mano_output.vertices,
|
| 205 |
+
1,
|
| 206 |
+
torch.tensor(
|
| 207 |
+
list(self.MANO_FINGERTIP_VERT_INDICES.values()),
|
| 208 |
+
dtype=torch.long,
|
| 209 |
+
),
|
| 210 |
+
)
|
| 211 |
+
joints = torch.cat([left_mano_output.joints, extra_joints], dim=1)
|
| 212 |
+
else:
|
| 213 |
+
joints = left_mano_output.joints
|
| 214 |
+
out_landmarks[torch.logical_not(is_right_hand)] = joints
|
| 215 |
+
if torch.sum(is_right_hand) > 0:
|
| 216 |
+
if right_mano_output.joints.shape[1] != self.N_LANDMARKS:
|
| 217 |
+
extra_joints = torch.index_select(
|
| 218 |
+
right_mano_output.vertices,
|
| 219 |
+
1,
|
| 220 |
+
torch.tensor(
|
| 221 |
+
list(self.MANO_FINGERTIP_VERT_INDICES.values()),
|
| 222 |
+
dtype=torch.long,
|
| 223 |
+
),
|
| 224 |
+
)
|
| 225 |
+
joints = torch.cat([right_mano_output.joints, extra_joints], dim=1)
|
| 226 |
+
else:
|
| 227 |
+
joints = right_mano_output.joints
|
| 228 |
+
out_landmarks[is_right_hand] = joints
|
| 229 |
+
|
| 230 |
+
assert out_landmarks.shape[1] == self.N_LANDMARKS
|
| 231 |
+
|
| 232 |
+
if self.joint_mapper is not None:
|
| 233 |
+
out_landmarks = out_landmarks[:, self.joint_mapper]
|
| 234 |
+
|
| 235 |
+
if not is_batched:
|
| 236 |
+
out_vertices = torch.squeeze(out_vertices, 0)
|
| 237 |
+
out_landmarks = torch.squeeze(out_landmarks, 0)
|
| 238 |
+
|
| 239 |
+
return out_vertices, out_landmarks
|
| 240 |
+
|
| 241 |
+
#简化版本,只有shape参数,pose参数和global xform都设为0
|
| 242 |
+
#pose_params = 0-->手指不弯曲,global_xform = 0 --> 手的朝向是默认的
|
| 243 |
+
#pose_xform = 0 --> 手的朝向是默认的,手的位置也是默认的
|
| 244 |
+
|
| 245 |
+
def shape_only_forward_kinematics(
|
| 246 |
+
self,
|
| 247 |
+
shape_params: torch.Tensor,
|
| 248 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 249 |
+
"""
|
| 250 |
+
Method to get the vertices and landmarks of the hand using only the shape
|
| 251 |
+
parameters and passing 0s for pose params and global xform.
|
| 252 |
+
|
| 253 |
+
Args:
|
| 254 |
+
shape_params: N x 6 (N is the number of frames) or 6,
|
| 255 |
+
"""
|
| 256 |
+
|
| 257 |
+
is_batched = len(shape_params.shape) == 2
|
| 258 |
+
if is_batched:
|
| 259 |
+
assert shape_params.shape[1] == self.num_shape_params
|
| 260 |
+
num_frames = shape_params.shape[0]
|
| 261 |
+
else:
|
| 262 |
+
assert shape_params.shape[0] == self.num_shape_params
|
| 263 |
+
shape_params = shape_params.unsqueeze(0)
|
| 264 |
+
num_frames = 1
|
| 265 |
+
|
| 266 |
+
# create zero pose params
|
| 267 |
+
pose_params = torch.zeros((num_frames, 15))
|
| 268 |
+
pose_xform = torch.zeros((num_frames, 6))
|
| 269 |
+
|
| 270 |
+
# FK
|
| 271 |
+
left_mano_output = self.mano_layer_left(
|
| 272 |
+
betas=shape_params.to(self.dtype),
|
| 273 |
+
global_orient=pose_xform[:, :3].to(self.dtype),
|
| 274 |
+
hand_pose=pose_params.to(self.dtype),
|
| 275 |
+
transl=pose_xform[:, 3:].to(self.dtype),
|
| 276 |
+
return_verts=True, # MANO doesn't return landmarks as well if this is false
|
| 277 |
+
)
|
| 278 |
+
|
| 279 |
+
# Merge the left and right hand outputs
|
| 280 |
+
out_vertices = left_mano_output.vertices
|
| 281 |
+
|
| 282 |
+
if left_mano_output.joints.shape[1] != self.N_LANDMARKS:
|
| 283 |
+
extra_joints = torch.index_select(
|
| 284 |
+
left_mano_output.vertices,
|
| 285 |
+
1,
|
| 286 |
+
torch.tensor(
|
| 287 |
+
list(self.MANO_FINGERTIP_VERT_INDICES.values()),
|
| 288 |
+
dtype=torch.long,
|
| 289 |
+
),
|
| 290 |
+
)
|
| 291 |
+
joints = torch.cat([left_mano_output.joints, extra_joints], dim=1)
|
| 292 |
+
else:
|
| 293 |
+
joints = left_mano_output.joints
|
| 294 |
+
out_landmarks = joints
|
| 295 |
+
|
| 296 |
+
assert out_landmarks.shape[1] == self.N_LANDMARKS
|
| 297 |
+
|
| 298 |
+
if self.joint_mapper is not None:
|
| 299 |
+
out_landmarks = out_landmarks[:, self.joint_mapper]
|
| 300 |
+
|
| 301 |
+
if not is_batched:
|
| 302 |
+
out_vertices = torch.squeeze(out_vertices, 0)
|
| 303 |
+
out_landmarks = torch.squeeze(out_landmarks, 0)
|
| 304 |
+
|
| 305 |
+
return out_vertices, out_landmarks
|
| 306 |
+
|
| 307 |
+
|
| 308 |
+
def loadManoHandModel(
|
| 309 |
+
mano_model_files_dir: Optional[str],
|
| 310 |
+
) -> MANOHandModel:
|
| 311 |
+
if not SMPLX_IMPORT_SUCCEEDED or mano_model_files_dir is None:
|
| 312 |
+
return None
|
| 313 |
+
|
| 314 |
+
return MANOHandModel(mano_model_files_dir)
|
HOT3DHUGGFACE/data_loaders/pose_utils.py
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
import bisect
|
| 16 |
+
from typing import Any, Dict, List, Optional, Tuple
|
| 17 |
+
|
| 18 |
+
from projectaria_tools.core.sensor_data import TimeQueryOptions # @manual
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def query_left_right(ordered_timestamps: List, query_timestamp: int):
|
| 22 |
+
"""
|
| 23 |
+
Return the left and right timestamp of the query timestamp by using bisection.
|
| 24 |
+
Assumption: timestamps are monotonically sorted in the ordered_timestamps List
|
| 25 |
+
"""
|
| 26 |
+
idx = bisect.bisect_left(ordered_timestamps, query_timestamp)
|
| 27 |
+
if idx == 0:
|
| 28 |
+
lower_timestamp = None
|
| 29 |
+
else:
|
| 30 |
+
lower_timestamp = ordered_timestamps[idx - 1]
|
| 31 |
+
|
| 32 |
+
if idx == len(ordered_timestamps):
|
| 33 |
+
upper_timestamp = None
|
| 34 |
+
else:
|
| 35 |
+
upper_timestamp = ordered_timestamps[idx]
|
| 36 |
+
|
| 37 |
+
if lower_timestamp is not None and upper_timestamp is not None:
|
| 38 |
+
alpha = (query_timestamp - lower_timestamp) / (
|
| 39 |
+
upper_timestamp - lower_timestamp
|
| 40 |
+
)
|
| 41 |
+
else:
|
| 42 |
+
alpha = None
|
| 43 |
+
return lower_timestamp, upper_timestamp, alpha
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def lookup_timestamp(
|
| 47 |
+
time_indexed_dict: Dict[int, Any],
|
| 48 |
+
sorted_timestamp_list: Optional[List[int]],
|
| 49 |
+
query_timestamp: int,
|
| 50 |
+
time_query_options: TimeQueryOptions,
|
| 51 |
+
) -> Tuple[Any, int]:
|
| 52 |
+
"""
|
| 53 |
+
Lookup the object corresponding to query_timestamp based on the time_query_options.
|
| 54 |
+
time_indexed_dict: a dictionary of timestamp to object
|
| 55 |
+
sorted_timestamp_list: a precomputed list of sorted timestamps in time_indexed_dict. If None, it will be computed from time_indexed_dict.
|
| 56 |
+
query_timestamp: the timestamp to query
|
| 57 |
+
time_query_options: the time query options to use (CLOSEST, BEFORE, AFTER)
|
| 58 |
+
"""
|
| 59 |
+
|
| 60 |
+
if sorted_timestamp_list is None:
|
| 61 |
+
sorted_timestamp_list = sorted(time_indexed_dict.keys())
|
| 62 |
+
|
| 63 |
+
obj = None
|
| 64 |
+
time_delta_ns = None
|
| 65 |
+
|
| 66 |
+
if query_timestamp in time_indexed_dict:
|
| 67 |
+
obj = time_indexed_dict[query_timestamp]
|
| 68 |
+
time_delta_ns = 0
|
| 69 |
+
else:
|
| 70 |
+
left_frame_tsns, right_frame_tsns, alpha = query_left_right(
|
| 71 |
+
ordered_timestamps=sorted_timestamp_list,
|
| 72 |
+
query_timestamp=query_timestamp,
|
| 73 |
+
)
|
| 74 |
+
if time_query_options == TimeQueryOptions.BEFORE:
|
| 75 |
+
if left_frame_tsns is not None:
|
| 76 |
+
obj = time_indexed_dict[left_frame_tsns]
|
| 77 |
+
time_delta_ns = query_timestamp - left_frame_tsns
|
| 78 |
+
|
| 79 |
+
elif time_query_options == TimeQueryOptions.AFTER:
|
| 80 |
+
if right_frame_tsns is not None:
|
| 81 |
+
obj = time_indexed_dict[right_frame_tsns]
|
| 82 |
+
time_delta_ns = query_timestamp - right_frame_tsns
|
| 83 |
+
|
| 84 |
+
elif time_query_options == TimeQueryOptions.CLOSEST:
|
| 85 |
+
if left_frame_tsns is not None and right_frame_tsns is not None:
|
| 86 |
+
if abs(query_timestamp - left_frame_tsns) > abs(
|
| 87 |
+
query_timestamp - right_frame_tsns
|
| 88 |
+
):
|
| 89 |
+
obj = time_indexed_dict[right_frame_tsns]
|
| 90 |
+
time_delta_ns = query_timestamp - right_frame_tsns
|
| 91 |
+
else:
|
| 92 |
+
obj = time_indexed_dict[left_frame_tsns]
|
| 93 |
+
time_delta_ns = query_timestamp - left_frame_tsns
|
| 94 |
+
elif left_frame_tsns is not None:
|
| 95 |
+
obj = time_indexed_dict[left_frame_tsns]
|
| 96 |
+
time_delta_ns = query_timestamp - left_frame_tsns
|
| 97 |
+
elif right_frame_tsns is not None:
|
| 98 |
+
obj = time_indexed_dict[right_frame_tsns]
|
| 99 |
+
time_delta_ns = query_timestamp - right_frame_tsns
|
| 100 |
+
|
| 101 |
+
return obj, time_delta_ns
|
HOT3DHUGGFACE/data_loaders/pytorch3d_rotation/rotation_conversions.py
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 2 |
+
#
|
| 3 |
+
# Redistribution and use in source and binary forms, with or without modification,
|
| 4 |
+
# are permitted provided that the following conditions are met:
|
| 5 |
+
#
|
| 6 |
+
# * Redistributions of source code must retain the above copyright notice, this
|
| 7 |
+
# list of conditions and the following disclaimer.
|
| 8 |
+
#
|
| 9 |
+
# * Redistributions in binary form must reproduce the above copyright notice,
|
| 10 |
+
# this list of conditions and the following disclaimer in the documentation
|
| 11 |
+
# and/or other materials provided with the distribution.
|
| 12 |
+
#
|
| 13 |
+
# * Neither the name Meta nor the names of its contributors may be used to
|
| 14 |
+
# endorse or promote products derived from this software without specific
|
| 15 |
+
# prior written permission.
|
| 16 |
+
#
|
| 17 |
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
| 18 |
+
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
| 19 |
+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
| 20 |
+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
| 21 |
+
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
| 22 |
+
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 23 |
+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
| 24 |
+
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 25 |
+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
| 26 |
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 27 |
+
|
| 28 |
+
# @lint-ignore-every LICENSELINT
|
| 29 |
+
|
| 30 |
+
# Content of this file
|
| 31 |
+
# Rotation functions extracted from PyTorch3d
|
| 32 |
+
# https://github.com/facebookresearch/pytorch3d/blob/main/pytorch3d/transforms/rotation_conversions.py
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
import torch
|
| 36 |
+
import torch.nn.functional as F
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def standardize_quaternion(quaternions: torch.Tensor) -> torch.Tensor:
|
| 40 |
+
"""
|
| 41 |
+
Convert a unit quaternion to a standard form: one in which the real
|
| 42 |
+
part is non negative.
|
| 43 |
+
|
| 44 |
+
Args:
|
| 45 |
+
quaternions: Quaternions with real part first,
|
| 46 |
+
as tensor of shape (..., 4).
|
| 47 |
+
|
| 48 |
+
Returns:
|
| 49 |
+
Standardized quaternions as tensor of shape (..., 4).
|
| 50 |
+
"""
|
| 51 |
+
return torch.where(quaternions[..., 0:1] < 0, -quaternions, quaternions)
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def _sqrt_positive_part(x: torch.Tensor) -> torch.Tensor:
|
| 55 |
+
"""
|
| 56 |
+
Returns torch.sqrt(torch.max(0, x))
|
| 57 |
+
but with a zero subgradient where x is 0.
|
| 58 |
+
"""
|
| 59 |
+
ret = torch.zeros_like(x)
|
| 60 |
+
positive_mask = x > 0
|
| 61 |
+
ret[positive_mask] = torch.sqrt(x[positive_mask])
|
| 62 |
+
return ret
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
def matrix_to_quaternion(matrix: torch.Tensor) -> torch.Tensor:
|
| 66 |
+
"""
|
| 67 |
+
Convert rotations given as rotation matrices to quaternions.
|
| 68 |
+
|
| 69 |
+
Args:
|
| 70 |
+
matrix: Rotation matrices as tensor of shape (..., 3, 3).
|
| 71 |
+
|
| 72 |
+
Returns:
|
| 73 |
+
quaternions with real part first, as tensor of shape (..., 4).
|
| 74 |
+
"""
|
| 75 |
+
if matrix.size(-1) != 3 or matrix.size(-2) != 3:
|
| 76 |
+
raise ValueError(f"Invalid rotation matrix shape {matrix.shape}.")
|
| 77 |
+
|
| 78 |
+
batch_dim = matrix.shape[:-2]
|
| 79 |
+
m00, m01, m02, m10, m11, m12, m20, m21, m22 = torch.unbind(
|
| 80 |
+
matrix.reshape(batch_dim + (9,)), dim=-1
|
| 81 |
+
)
|
| 82 |
+
|
| 83 |
+
q_abs = _sqrt_positive_part(
|
| 84 |
+
torch.stack(
|
| 85 |
+
[
|
| 86 |
+
1.0 + m00 + m11 + m22,
|
| 87 |
+
1.0 + m00 - m11 - m22,
|
| 88 |
+
1.0 - m00 + m11 - m22,
|
| 89 |
+
1.0 - m00 - m11 + m22,
|
| 90 |
+
],
|
| 91 |
+
dim=-1,
|
| 92 |
+
)
|
| 93 |
+
)
|
| 94 |
+
|
| 95 |
+
# we produce the desired quaternion multiplied by each of r, i, j, k
|
| 96 |
+
quat_by_rijk = torch.stack(
|
| 97 |
+
[
|
| 98 |
+
# pyre-fixme[58]: `**` is not supported for operand types `Tensor` and
|
| 99 |
+
# `int`.
|
| 100 |
+
torch.stack([q_abs[..., 0] ** 2, m21 - m12, m02 - m20, m10 - m01], dim=-1),
|
| 101 |
+
# pyre-fixme[58]: `**` is not supported for operand types `Tensor` and
|
| 102 |
+
# `int`.
|
| 103 |
+
torch.stack([m21 - m12, q_abs[..., 1] ** 2, m10 + m01, m02 + m20], dim=-1),
|
| 104 |
+
# pyre-fixme[58]: `**` is not supported for operand types `Tensor` and
|
| 105 |
+
# `int`.
|
| 106 |
+
torch.stack([m02 - m20, m10 + m01, q_abs[..., 2] ** 2, m12 + m21], dim=-1),
|
| 107 |
+
# pyre-fixme[58]: `**` is not supported for operand types `Tensor` and
|
| 108 |
+
# `int`.
|
| 109 |
+
torch.stack([m10 - m01, m20 + m02, m21 + m12, q_abs[..., 3] ** 2], dim=-1),
|
| 110 |
+
],
|
| 111 |
+
dim=-2,
|
| 112 |
+
)
|
| 113 |
+
|
| 114 |
+
# We floor here at 0.1 but the exact level is not important; if q_abs is small,
|
| 115 |
+
# the candidate won't be picked.
|
| 116 |
+
flr = torch.tensor(0.1).to(dtype=q_abs.dtype, device=q_abs.device)
|
| 117 |
+
quat_candidates = quat_by_rijk / (2.0 * q_abs[..., None].max(flr))
|
| 118 |
+
|
| 119 |
+
# if not for numerical problems, quat_candidates[i] should be same (up to a sign),
|
| 120 |
+
# forall i; we pick the best-conditioned one (with the largest denominator)
|
| 121 |
+
out = quat_candidates[
|
| 122 |
+
F.one_hot(q_abs.argmax(dim=-1), num_classes=4) > 0.5, :
|
| 123 |
+
].reshape(batch_dim + (4,))
|
| 124 |
+
return standardize_quaternion(out)
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
def quaternion_to_axis_angle(quaternions: torch.Tensor) -> torch.Tensor:
|
| 128 |
+
"""
|
| 129 |
+
Convert rotations given as quaternions to axis/angle.
|
| 130 |
+
|
| 131 |
+
Args:
|
| 132 |
+
quaternions: quaternions with real part first,
|
| 133 |
+
as tensor of shape (..., 4).
|
| 134 |
+
|
| 135 |
+
Returns:
|
| 136 |
+
Rotations given as a vector in axis angle form, as a tensor
|
| 137 |
+
of shape (..., 3), where the magnitude is the angle
|
| 138 |
+
turned anticlockwise in radians around the vector's
|
| 139 |
+
direction.
|
| 140 |
+
"""
|
| 141 |
+
norms = torch.norm(quaternions[..., 1:], p=2, dim=-1, keepdim=True)
|
| 142 |
+
half_angles = torch.atan2(norms, quaternions[..., :1])
|
| 143 |
+
angles = 2 * half_angles
|
| 144 |
+
eps = 1e-6
|
| 145 |
+
small_angles = angles.abs() < eps
|
| 146 |
+
sin_half_angles_over_angles = torch.empty_like(angles)
|
| 147 |
+
sin_half_angles_over_angles[~small_angles] = (
|
| 148 |
+
torch.sin(half_angles[~small_angles]) / angles[~small_angles]
|
| 149 |
+
)
|
| 150 |
+
# for x small, sin(x/2) is about x/2 - (x/2)^3/6
|
| 151 |
+
# so sin(x/2)/x is about 1/2 - (x*x)/48
|
| 152 |
+
sin_half_angles_over_angles[small_angles] = (
|
| 153 |
+
0.5 - (angles[small_angles] * angles[small_angles]) / 48
|
| 154 |
+
)
|
| 155 |
+
return quaternions[..., 1:] / sin_half_angles_over_angles
|
| 156 |
+
|
| 157 |
+
|
| 158 |
+
def matrix_to_axis_angle(matrix: torch.Tensor) -> torch.Tensor:
|
| 159 |
+
"""
|
| 160 |
+
Convert rotations given as rotation matrices to axis/angle.
|
| 161 |
+
|
| 162 |
+
Args:
|
| 163 |
+
matrix: Rotation matrices as tensor of shape (..., 3, 3).
|
| 164 |
+
|
| 165 |
+
Returns:
|
| 166 |
+
Rotations given as a vector in axis angle form, as a tensor
|
| 167 |
+
of shape (..., 3), where the magnitude is the angle
|
| 168 |
+
turned anticlockwise in radians around the vector's
|
| 169 |
+
direction.
|
| 170 |
+
"""
|
| 171 |
+
return quaternion_to_axis_angle(matrix_to_quaternion(matrix))
|
HOT3DHUGGFACE/data_loaders/umetrack_layer.py
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
from typing import List
|
| 16 |
+
|
| 17 |
+
import torch
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
NUM_DIGITS: int = 5
|
| 21 |
+
DOF_PER_FINGER: int = 4
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def _axis_angle_to_matrix(axis_angle: torch.Tensor) -> torch.Tensor:
|
| 25 |
+
theta = torch.norm(axis_angle, p=2, dim=-1)
|
| 26 |
+
axis = axis_angle / theta[..., None]
|
| 27 |
+
|
| 28 |
+
c = torch.cos(theta)
|
| 29 |
+
s = torch.sin(theta)
|
| 30 |
+
kx = axis[..., 0]
|
| 31 |
+
ky = axis[..., 1]
|
| 32 |
+
kz = axis[..., 2]
|
| 33 |
+
kxky = kx * ky
|
| 34 |
+
kxkz = kx * kz
|
| 35 |
+
kykz = ky * kz
|
| 36 |
+
kx2 = kx * kx
|
| 37 |
+
ky2 = ky * ky
|
| 38 |
+
kz2 = kz * kz
|
| 39 |
+
|
| 40 |
+
o = torch.stack(
|
| 41 |
+
(
|
| 42 |
+
c + kx2 * (1 - c),
|
| 43 |
+
kxky * (1 - c) - kz * s,
|
| 44 |
+
kxkz * (1 - c) + ky * s,
|
| 45 |
+
kxky * (1 - c) + kz * s,
|
| 46 |
+
c + ky2 * (1 - c),
|
| 47 |
+
kykz * (1 - c) - kx * s,
|
| 48 |
+
kxkz * (1 - c) - ky * s,
|
| 49 |
+
kykz * (1 - c) + kx * s,
|
| 50 |
+
c + kz2 * (1 - c),
|
| 51 |
+
),
|
| 52 |
+
-1,
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
return o.reshape(*axis_angle.shape[:-1], 3, 3)
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
def _finger_fk(
|
| 59 |
+
joint_local_xfs: torch.Tensor, parent_transform: torch.Tensor
|
| 60 |
+
) -> List[torch.Tensor]:
|
| 61 |
+
"""
|
| 62 |
+
each finger consists 4 DoF / Joints,
|
| 63 |
+
and returns 3 transformation frames
|
| 64 |
+
Input:
|
| 65 |
+
joint_local_xfs: (B, 4, 4)
|
| 66 |
+
parent_transform: (B, 4, 4)
|
| 67 |
+
Return:
|
| 68 |
+
transform_mats: (B, 3, 4, 4)
|
| 69 |
+
"""
|
| 70 |
+
transform_mats = [parent_transform]
|
| 71 |
+
for i in range(4):
|
| 72 |
+
transform_mats.append(torch.matmul(transform_mats[-1], joint_local_xfs[:, i]))
|
| 73 |
+
return transform_mats[2:]
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
def _joint_local_transform(
|
| 77 |
+
rotation_axis: torch.Tensor, rest_pose: torch.Tensor, joint_angles: torch.Tensor
|
| 78 |
+
) -> torch.Tensor:
|
| 79 |
+
rotation_axis_flat = rotation_axis.reshape(-1, 3)
|
| 80 |
+
rest_pose_flat = rest_pose.reshape(-1, 3)
|
| 81 |
+
joint_angles_flat = joint_angles.reshape(-1)
|
| 82 |
+
|
| 83 |
+
angle_axis = rotation_axis_flat * joint_angles_flat.unsqueeze(-1)
|
| 84 |
+
local_transform = torch.eye(4, dtype=angle_axis.dtype, device=angle_axis.device)
|
| 85 |
+
local_transform = local_transform.unsqueeze(dim=0).repeat(angle_axis.shape[0], 1, 1)
|
| 86 |
+
|
| 87 |
+
rot_mat = _axis_angle_to_matrix(angle_axis)
|
| 88 |
+
translation = rest_pose_flat - torch.matmul(
|
| 89 |
+
rot_mat, rest_pose_flat.unsqueeze(dim=-1)
|
| 90 |
+
).squeeze(dim=-1)
|
| 91 |
+
local_transform[:, :3, :3] = rot_mat
|
| 92 |
+
local_transform[:, 0:3, 3] = torch.squeeze(translation, dim=-1)
|
| 93 |
+
|
| 94 |
+
return local_transform.reshape(*rotation_axis.shape[0:-1], 4, 4)
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
def _lbs(trans_mats: torch.Tensor, skinned_points: torch.Tensor) -> torch.Tensor:
|
| 98 |
+
"""
|
| 99 |
+
Input:
|
| 100 |
+
trans_mats: (B, 17, 4, 4)
|
| 101 |
+
skinned_points: (B, V, 17, 4)
|
| 102 |
+
Return:
|
| 103 |
+
fk_points: (B, V, 4)
|
| 104 |
+
"""
|
| 105 |
+
trans_mats = trans_mats.unsqueeze(dim=1)
|
| 106 |
+
skinned_points = skinned_points.unsqueeze(dim=-1)
|
| 107 |
+
fk_points = torch.matmul(trans_mats, skinned_points).sum(dim=2).squeeze(dim=-1)
|
| 108 |
+
return fk_points
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
def get_skinning_weights(
|
| 112 |
+
bone_indices: torch.Tensor, bone_weights: torch.Tensor, n_frames: int
|
| 113 |
+
) -> torch.Tensor:
|
| 114 |
+
"""
|
| 115 |
+
Input:
|
| 116 |
+
bone_indices: (B, V, K)
|
| 117 |
+
bone_weights: (B, V, K)
|
| 118 |
+
n_frames: (or n_bones) Number of frames/bones (17 for hands)
|
| 119 |
+
Note: K is number of bones.
|
| 120 |
+
Return:
|
| 121 |
+
skin_mat: (B, V, n_frames)
|
| 122 |
+
"""
|
| 123 |
+
|
| 124 |
+
bs = bone_indices.shape[0]
|
| 125 |
+
n_lms = bone_indices.shape[1]
|
| 126 |
+
# Offset all the bones linearly from 0 to (bs*n_lms*n_frames) so that we can directly
|
| 127 |
+
# index into the flattened weight matrix and set the corresponding skinning weights
|
| 128 |
+
flat_idx_offset = torch.arange(0, bs * n_lms, device=bone_indices.device) * n_frames
|
| 129 |
+
bone_flat_idx = bone_indices.long() + flat_idx_offset.reshape(bs, n_lms, 1)
|
| 130 |
+
skin_mat = torch.zeros(
|
| 131 |
+
bs * n_lms * n_frames, device=bone_weights.device, dtype=bone_weights.dtype
|
| 132 |
+
)
|
| 133 |
+
non0_w_mask = bone_weights != 0
|
| 134 |
+
non0_indices = bone_flat_idx[non0_w_mask]
|
| 135 |
+
skin_mat[non0_indices] = bone_weights[non0_w_mask]
|
| 136 |
+
skin_mat = skin_mat.reshape(bs, n_lms, n_frames)
|
| 137 |
+
|
| 138 |
+
return skin_mat
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
def _hand_skinning_transform(
|
| 142 |
+
rotation_axis: torch.Tensor,
|
| 143 |
+
rest_poses: torch.Tensor,
|
| 144 |
+
joint_angles: torch.Tensor,
|
| 145 |
+
wrist_transforms: torch.Tensor,
|
| 146 |
+
) -> torch.Tensor:
|
| 147 |
+
"""
|
| 148 |
+
Input:
|
| 149 |
+
rotation_axis: (B, 20, 3)
|
| 150 |
+
rest_poses: (B, 20, 3)
|
| 151 |
+
joint_angles: (B, 20)
|
| 152 |
+
wrist_transforms: (B, 4, 4)
|
| 153 |
+
Return:
|
| 154 |
+
skinning_matrices: (B, 17, 4, 4)
|
| 155 |
+
"""
|
| 156 |
+
transform_mats = [wrist_transforms] * 2 # [root_transform, wrist_transforms]
|
| 157 |
+
d = DOF_PER_FINGER
|
| 158 |
+
|
| 159 |
+
joint_local_xfs = _joint_local_transform(
|
| 160 |
+
rotation_axis[:, 0:20], rest_poses[:, 0:20], joint_angles[:, 0:20]
|
| 161 |
+
)
|
| 162 |
+
|
| 163 |
+
for finger_idx in range(NUM_DIGITS):
|
| 164 |
+
transform_mats += _finger_fk(
|
| 165 |
+
joint_local_xfs[:, d * finger_idx : d * finger_idx + d], wrist_transforms
|
| 166 |
+
)
|
| 167 |
+
transform_mats = torch.cat([m.unsqueeze(1) for m in transform_mats], dim=1)
|
| 168 |
+
return transform_mats
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
def _get_skinned_vertices(
|
| 172 |
+
vertices: torch.Tensor, weights: torch.Tensor
|
| 173 |
+
) -> torch.Tensor:
|
| 174 |
+
"""
|
| 175 |
+
Input:
|
| 176 |
+
vertices: (B, V, 3) or (B, V, 4)
|
| 177 |
+
weights: (B, V, 17)
|
| 178 |
+
Return:
|
| 179 |
+
skinned_vertices: (B, V, 17, 4)
|
| 180 |
+
"""
|
| 181 |
+
if vertices.shape[2] == 3:
|
| 182 |
+
n_vertices = vertices.shape[1]
|
| 183 |
+
homo = torch.ones(
|
| 184 |
+
vertices.shape[0],
|
| 185 |
+
n_vertices,
|
| 186 |
+
1,
|
| 187 |
+
dtype=vertices.dtype,
|
| 188 |
+
device=vertices.device,
|
| 189 |
+
)
|
| 190 |
+
vertices = torch.cat([vertices, homo], dim=-1)
|
| 191 |
+
|
| 192 |
+
vertices = vertices.unsqueeze(dim=2)
|
| 193 |
+
weights = weights.unsqueeze(dim=-1)
|
| 194 |
+
return vertices * weights
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
def skin_points(
|
| 198 |
+
joint_rest_positions: torch.Tensor,
|
| 199 |
+
joint_rotation_axes: torch.Tensor,
|
| 200 |
+
skin_mat: torch.Tensor,
|
| 201 |
+
joint_angles: torch.Tensor,
|
| 202 |
+
points: torch.Tensor,
|
| 203 |
+
wrist_transforms: torch.Tensor,
|
| 204 |
+
) -> torch.Tensor:
|
| 205 |
+
leading_dims = joint_angles.shape[:-1]
|
| 206 |
+
assert joint_rest_positions.shape[:-2] == leading_dims, (
|
| 207 |
+
"Leading dimensions do not match, "
|
| 208 |
+
+ f"got {leading_dims} and {joint_rest_positions.shape[:-2]}"
|
| 209 |
+
)
|
| 210 |
+
|
| 211 |
+
# This allows querying the product of leading dimensions without making the
|
| 212 |
+
# model specialized to a particular shape
|
| 213 |
+
numel = torch.flatten(joint_angles, end_dim=-2).shape[0] if len(leading_dims) else 1
|
| 214 |
+
|
| 215 |
+
batched_joint_rest_positions = joint_rest_positions.reshape(numel, -1, 3)
|
| 216 |
+
|
| 217 |
+
skin_xfs = _hand_skinning_transform(
|
| 218 |
+
rotation_axis=joint_rotation_axes.reshape(numel, -1, 3),
|
| 219 |
+
rest_poses=batched_joint_rest_positions,
|
| 220 |
+
joint_angles=joint_angles.reshape(numel, -1),
|
| 221 |
+
wrist_transforms=wrist_transforms.reshape(numel, 4, 4),
|
| 222 |
+
)
|
| 223 |
+
|
| 224 |
+
verts = _get_skinned_vertices(points.reshape(numel, -1, 3), skin_mat)
|
| 225 |
+
skinned_vecs = _lbs(skin_xfs, verts)[..., :3]
|
| 226 |
+
skinned_vecs = skinned_vecs.reshape(
|
| 227 |
+
list(leading_dims) + list(skinned_vecs.shape[-2:])
|
| 228 |
+
)
|
| 229 |
+
return skinned_vecs
|
HOT3DHUGGFACE/dataset/P0002_2f137f83/.download_status.json
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"main_vrs": true,
|
| 3 |
+
"ground_truth": true,
|
| 4 |
+
"hand_data": true
|
| 5 |
+
}
|
HOT3DHUGGFACE/dataset/P0002_2f137f83/box2d_hands.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
HOT3DHUGGFACE/dataset/P0002_2f137f83/box2d_objects.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
HOT3DHUGGFACE/dataset/P0002_2f137f83/camera_models.json
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{
|
| 3 |
+
"T_Device_Camera": {
|
| 4 |
+
"quaternion_wxyz": [
|
| 5 |
+
-0.44995020258640295,
|
| 6 |
+
0.4002398518639525,
|
| 7 |
+
-0.5571697905977196,
|
| 8 |
+
0.5717645499833561
|
| 9 |
+
],
|
| 10 |
+
"translation_xyz": [
|
| 11 |
+
0.02676488494873047,
|
| 12 |
+
-0.1293854675292969,
|
| 13 |
+
-0.03089171028137207
|
| 14 |
+
]
|
| 15 |
+
},
|
| 16 |
+
"imageHeight": 1024,
|
| 17 |
+
"imageWidth": 1280,
|
| 18 |
+
"label": "camera-slam-left",
|
| 19 |
+
"maxSolidAngle": 1.8385352143167695,
|
| 20 |
+
"projectionModelType": "CameraModelType.FISHEYE624",
|
| 21 |
+
"projectionParams": [
|
| 22 |
+
504.5934753417969,
|
| 23 |
+
504.5934753417969,
|
| 24 |
+
638.3945922851562,
|
| 25 |
+
509.4228515625,
|
| 26 |
+
0.043982941657304764,
|
| 27 |
+
-0.0448598638176918,
|
| 28 |
+
0.01613209955394268,
|
| 29 |
+
-0.010928832925856113,
|
| 30 |
+
0.003512823488563299,
|
| 31 |
+
-0.0005242147017270327,
|
| 32 |
+
0.00047754947445355356,
|
| 33 |
+
-4.744782927446067e-05,
|
| 34 |
+
0.0,
|
| 35 |
+
0.0,
|
| 36 |
+
0.0,
|
| 37 |
+
0.0
|
| 38 |
+
],
|
| 39 |
+
"serialNumber": "21367848_11:mono10bit",
|
| 40 |
+
"stream_id": "1201-1"
|
| 41 |
+
},
|
| 42 |
+
{
|
| 43 |
+
"T_Device_Camera": {
|
| 44 |
+
"quaternion_wxyz": [
|
| 45 |
+
-0.43742901420997415,
|
| 46 |
+
0.40850468341688273,
|
| 47 |
+
-0.5546791775025043,
|
| 48 |
+
0.578023175312987
|
| 49 |
+
],
|
| 50 |
+
"translation_xyz": [
|
| 51 |
+
0.023434097290039063,
|
| 52 |
+
-0.13131076049804688,
|
| 53 |
+
0.03267765808105469
|
| 54 |
+
]
|
| 55 |
+
},
|
| 56 |
+
"imageHeight": 1024,
|
| 57 |
+
"imageWidth": 1280,
|
| 58 |
+
"label": "camera-slam-right",
|
| 59 |
+
"maxSolidAngle": 2.7418528142178835,
|
| 60 |
+
"projectionModelType": "CameraModelType.FISHEYE624",
|
| 61 |
+
"projectionParams": [
|
| 62 |
+
503.17462158203125,
|
| 63 |
+
503.17462158203125,
|
| 64 |
+
636.9581909179688,
|
| 65 |
+
511.8325500488281,
|
| 66 |
+
0.043429020792245865,
|
| 67 |
+
-0.046074334532022476,
|
| 68 |
+
0.02290933020412922,
|
| 69 |
+
-0.01852448284626007,
|
| 70 |
+
0.007009806111454964,
|
| 71 |
+
-0.001104349852539599,
|
| 72 |
+
-2.9515178539440967e-05,
|
| 73 |
+
0.000159201052156277,
|
| 74 |
+
0.0,
|
| 75 |
+
0.0,
|
| 76 |
+
0.0,
|
| 77 |
+
0.0
|
| 78 |
+
],
|
| 79 |
+
"serialNumber": "21366312_12:mono10bit",
|
| 80 |
+
"stream_id": "1201-2"
|
| 81 |
+
}
|
| 82 |
+
]
|
HOT3DHUGGFACE/dataset/P0002_2f137f83/dynamic_objects.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
HOT3DHUGGFACE/dataset/P0002_2f137f83/headset_trajectory.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
HOT3DHUGGFACE/dataset/P0002_2f137f83/license.txt
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
HOT3D Dataset License Agreement
|
| 2 |
+
|
| 3 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
| 4 |
+
|
| 5 |
+
Last updated May 29, 2024
|
| 6 |
+
|
| 7 |
+
Before you access or use the HOT3D Dataset (the "Dataset") made available by Meta Platforms Technologies, LLC ("Meta") please read the following Dataset License Agreement (“Agreement”). By accessing or using the Dataset, you agree to be bound by this Agreement. If you don’t agree to be bound by this Agreement, do not use the Dataset.
|
| 8 |
+
|
| 9 |
+
The dataset includes 3 data types, each governed by different license terms. You are responsible for complying with all license terms for the specific sequences, annotations, and models utilized by You.
|
| 10 |
+
|
| 11 |
+
1. Sequence captured by Project Aria and Quest devices, and annotations (excluding hand annotations) ("Sequence data") is licensed under CC BY-SA (https://creativecommons.org/licenses/by-sa/4.0/).
|
| 12 |
+
2. Hand annotations ("Hand data"”") is licensed under CC BY-NC-SA (https://creativecommons.org/licenses/by-nc-sa/4.0/). For example, the files under this license considered “Hand Data” includes but is not limited to: mano_hand_pose_trajectory.jsonl, umetrack_hand_pose_trajectory.jsonl, umetrack_hand_user_profile.json, box2d_hands.csv, mask_hand_pose_available.csv and mask_hand_visible.csv
|
| 13 |
+
3. 3D object models ("Model data") are licensed under a CC BY-SA (https://creativecommons.org/licenses/by-sa/4.0/), with the modification that notwithstanding anything to the contrary, You shall not sell the Licensed Material, or incorporate the Licensed Material into a product to be sold, including for the avoidance of doubt objects or models contained in the Licensed Materials.
|
| 14 |
+
|
| 15 |
+
The license terms are also visible in the readme of each corresponding download.
|
HOT3DHUGGFACE/dataset/P0002_2f137f83/mano_hand_pose_trajectory.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
HOT3DHUGGFACE/dataset/P0002_2f137f83/masks/mask_good_exposure.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
HOT3DHUGGFACE/dataset/P0002_2f137f83/masks/mask_hand_pose_available.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
HOT3DHUGGFACE/dataset/P0002_2f137f83/masks/mask_hand_visible.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
HOT3DHUGGFACE/dataset/P0002_2f137f83/masks/mask_headset_pose_available.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
HOT3DHUGGFACE/dataset/P0002_2f137f83/masks/mask_object_pose_available.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
HOT3DHUGGFACE/dataset/P0002_2f137f83/masks/mask_object_visible.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
HOT3DHUGGFACE/dataset/P0002_2f137f83/masks/mask_qa_pass.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
HOT3DHUGGFACE/dataset/P0002_2f137f83/metadata.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"have_hand_object_pose_gt": true,
|
| 3 |
+
"headset": "Quest3",
|
| 4 |
+
"object_bop_uids": [
|
| 5 |
+
"2",
|
| 6 |
+
"20",
|
| 7 |
+
"4",
|
| 8 |
+
"13",
|
| 9 |
+
"7",
|
| 10 |
+
"21"
|
| 11 |
+
],
|
| 12 |
+
"object_names": [
|
| 13 |
+
"bowl",
|
| 14 |
+
"food_waffles",
|
| 15 |
+
"spoon_wooden",
|
| 16 |
+
"bottle_mustard",
|
| 17 |
+
"coffee_pot",
|
| 18 |
+
"food_vegetables"
|
| 19 |
+
],
|
| 20 |
+
"object_uids": [
|
| 21 |
+
"194930206998778",
|
| 22 |
+
"253405647833885",
|
| 23 |
+
"225397651484143",
|
| 24 |
+
"261746112525368",
|
| 25 |
+
"228358276546933",
|
| 26 |
+
"96945373046044"
|
| 27 |
+
],
|
| 28 |
+
"participant_id": "P0002",
|
| 29 |
+
"recording_name": "P0002_2f137f83",
|
| 30 |
+
"version": 4
|
| 31 |
+
}
|
HOT3DHUGGFACE/dataset/P0002_2f137f83/recording.vrs
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c2b7f1a1c7474b8287bda181279e9185c5bc3d701e27c11713be045e2c6f8d13
|
| 3 |
+
size 1541144815
|
HOT3DHUGGFACE/dataset/P0002_2f137f83/umetrack_hand_pose_trajectory.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
HOT3DHUGGFACE/dataset/P0002_2f137f83/umetrack_hand_user_profile.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
HOT3DHUGGFACE/dataset_api.py
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
import os
|
| 16 |
+
from typing import Any, Dict, Optional
|
| 17 |
+
|
| 18 |
+
import data_loaders.HandBox2dDataProvider as HandBox2dDataProvider
|
| 19 |
+
import data_loaders.ObjectBox2dDataProvider as ObjectBox2dDataProvider
|
| 20 |
+
from data_loaders.AriaDataProvider import AriaDataProvider
|
| 21 |
+
from data_loaders.HeadsetPose3dProvider import (
|
| 22 |
+
HeadsetPose3dProvider,
|
| 23 |
+
load_headset_pose_provider_from_csv,
|
| 24 |
+
)
|
| 25 |
+
from data_loaders.headsets import Headset
|
| 26 |
+
from data_loaders.io_utils import load_json
|
| 27 |
+
from data_loaders.loader_object_library import ObjectLibrary
|
| 28 |
+
from data_loaders.mano_layer import MANOHandModel
|
| 29 |
+
from data_loaders.ManoHandDataProvider import MANOHandDataProvider
|
| 30 |
+
from data_loaders.ObjectPose3dProvider import (
|
| 31 |
+
load_pose_provider_from_csv,
|
| 32 |
+
ObjectPose3dProvider,
|
| 33 |
+
)
|
| 34 |
+
from data_loaders.PathProvider import Hot3dDataPathProvider
|
| 35 |
+
from data_loaders.QuestDataProvider import QuestDataProvider
|
| 36 |
+
from data_loaders.UmeTrackHandDataProvider import UmeTrackHandDataProvider
|
| 37 |
+
|
| 38 |
+
# 3D assets
|
| 39 |
+
# - object_uid
|
| 40 |
+
|
| 41 |
+
# 3D transform
|
| 42 |
+
# Aria Device to Optitrack
|
| 43 |
+
|
| 44 |
+
# Generic idea around the DataProvider is that is allow to initialize the data reading
|
| 45 |
+
# and offer a generic interface to retrieve timestamp data by TYPE (Image, Object, Hand, etc.)
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
class Hot3dDataProvider:
|
| 49 |
+
"""
|
| 50 |
+
High Level interface to retrieve and use data from the hot3d dataset
|
| 51 |
+
"""
|
| 52 |
+
|
| 53 |
+
def __init__(
|
| 54 |
+
self,
|
| 55 |
+
sequence_folder: str,
|
| 56 |
+
object_library: ObjectLibrary,
|
| 57 |
+
mano_hand_model: Optional[MANOHandModel] = None,
|
| 58 |
+
fail_on_missing_data: bool = True,
|
| 59 |
+
) -> None:
|
| 60 |
+
"""
|
| 61 |
+
INIT_DOC_STRING
|
| 62 |
+
"""
|
| 63 |
+
# Will read all required metadata
|
| 64 |
+
# Hands
|
| 65 |
+
# Objects
|
| 66 |
+
# Device type, ...
|
| 67 |
+
self.path_provider = Hot3dDataPathProvider.fromRecordingFolder(
|
| 68 |
+
recording_instance_folderpath=sequence_folder
|
| 69 |
+
)
|
| 70 |
+
#根据path_provider检查是否所有文件存在
|
| 71 |
+
if not self.path_provider.is_valid():
|
| 72 |
+
missing_filepaths = [
|
| 73 |
+
filepath
|
| 74 |
+
for filepath in self.path_provider.required_filepaths
|
| 75 |
+
if not os.path.exists(filepath)
|
| 76 |
+
]
|
| 77 |
+
|
| 78 |
+
if fail_on_missing_data:
|
| 79 |
+
raise RuntimeError(
|
| 80 |
+
f"Invalid hot3d path. Not all expected data are present. missing_filepaths: {missing_filepaths}"
|
| 81 |
+
)
|
| 82 |
+
else:
|
| 83 |
+
print(
|
| 84 |
+
f"Not all expected data are present. missing_filepaths: {missing_filepaths}"
|
| 85 |
+
)
|
| 86 |
+
|
| 87 |
+
self._dynamic_objects_provider = load_pose_provider_from_csv(
|
| 88 |
+
self.path_provider.dynamic_objects_filepath
|
| 89 |
+
)
|
| 90 |
+
#头显设备
|
| 91 |
+
self._device_pose_provider = load_headset_pose_provider_from_csv(
|
| 92 |
+
self.path_provider.headset_trajectory_filepath
|
| 93 |
+
)
|
| 94 |
+
#物体在图像上的 2D 边界框
|
| 95 |
+
self._object_box2d_provider = (
|
| 96 |
+
ObjectBox2dDataProvider.load_box2d_trajectory_from_csv(
|
| 97 |
+
self.path_provider.box2d_objects_filepath
|
| 98 |
+
)
|
| 99 |
+
)
|
| 100 |
+
#手在图像上的 2D 边界框,注意手是两个手,所以是一个list[0]是左手数据,list[1]是右手
|
| 101 |
+
self._hand_box2d_provider = (
|
| 102 |
+
HandBox2dDataProvider.load_box2d_trajectory_from_csv(
|
| 103 |
+
self.path_provider.box2d_hands_filepath
|
| 104 |
+
)
|
| 105 |
+
)
|
| 106 |
+
|
| 107 |
+
self._object_library: ObjectLibrary = object_library
|
| 108 |
+
|
| 109 |
+
self._mano_hand_data_provider = None
|
| 110 |
+
if os.path.isfile(self.path_provider.mano_hand_pose_trajectory_filepath):
|
| 111 |
+
if mano_hand_model is not None:
|
| 112 |
+
self._mano_hand_data_provider = MANOHandDataProvider(
|
| 113 |
+
#mano_hand_pose_trajectory.jsonl:每一帧中每只手的“手腕位置 + 手腕朝向 + 手指姿态 + 手型”
|
| 114 |
+
self.path_provider.mano_hand_pose_trajectory_filepath,
|
| 115 |
+
mano_hand_model,
|
| 116 |
+
)
|
| 117 |
+
else:
|
| 118 |
+
print("No MANO hand model provided, skipping MANO hand data provider")
|
| 119 |
+
else:
|
| 120 |
+
print(
|
| 121 |
+
f"WARN: Cannot find {self.path_provider.mano_hand_pose_trajectory_filepath}"
|
| 122 |
+
)
|
| 123 |
+
|
| 124 |
+
#umetrack_手部追踪系统,提供手部数据,但用的手模型不同
|
| 125 |
+
self._umetrack_hand_data_provider = None
|
| 126 |
+
if os.path.exists(
|
| 127 |
+
self.path_provider.umetrack_hand_pose_trajectory_filepath
|
| 128 |
+
) and os.path.exists(self.path_provider.umetrack_hand_user_profile_filepath):
|
| 129 |
+
self._umetrack_hand_data_provider = UmeTrackHandDataProvider(
|
| 130 |
+
self.path_provider.umetrack_hand_pose_trajectory_filepath,
|
| 131 |
+
self.path_provider.umetrack_hand_user_profile_filepath,
|
| 132 |
+
)
|
| 133 |
+
|
| 134 |
+
if self.get_device_type() == Headset.Aria:
|
| 135 |
+
self._device_data_provider = AriaDataProvider(
|
| 136 |
+
self.path_provider.vrs_filepath,
|
| 137 |
+
self.path_provider.mps_folderpath,
|
| 138 |
+
)
|
| 139 |
+
elif self.get_device_type() == Headset.Quest3:
|
| 140 |
+
self._device_data_provider = QuestDataProvider(
|
| 141 |
+
#recording.vrs
|
| 142 |
+
self.path_provider.vrs_filepath,
|
| 143 |
+
#camera_models.json
|
| 144 |
+
self.path_provider.camera_models_filepath,
|
| 145 |
+
)
|
| 146 |
+
else:
|
| 147 |
+
raise RuntimeError(f"Unsupported device type {self.get_device_type()}")
|
| 148 |
+
|
| 149 |
+
def get_data_statistics(self) -> Dict[str, Any]:
|
| 150 |
+
statistics_dict = {}
|
| 151 |
+
statistics_dict["dynamic_objects"] = (
|
| 152 |
+
self._dynamic_objects_provider.get_data_statistics()
|
| 153 |
+
)
|
| 154 |
+
|
| 155 |
+
if self._mano_hand_data_provider is not None:
|
| 156 |
+
statistics_dict["mano_hand_poses"] = (
|
| 157 |
+
self._mano_hand_data_provider.get_data_statistics()
|
| 158 |
+
)
|
| 159 |
+
|
| 160 |
+
if self._umetrack_hand_data_provider is not None:
|
| 161 |
+
statistics_dict["umetrack_hand_poses"] = (
|
| 162 |
+
self._umetrack_hand_data_provider.get_data_statistics()
|
| 163 |
+
)
|
| 164 |
+
|
| 165 |
+
if self._object_box2d_provider is not None:
|
| 166 |
+
statistics_dict["object_box2ds"] = (
|
| 167 |
+
self.object_box2d_data_provider.get_data_statistics()
|
| 168 |
+
)
|
| 169 |
+
|
| 170 |
+
if self._hand_box2d_provider is not None:
|
| 171 |
+
statistics_dict["hand_box2ds"] = (
|
| 172 |
+
self.hand_box2d_data_provider.get_data_statistics()
|
| 173 |
+
)
|
| 174 |
+
return statistics_dict
|
| 175 |
+
|
| 176 |
+
@property
|
| 177 |
+
def object_library(self) -> ObjectLibrary:
|
| 178 |
+
"""
|
| 179 |
+
Return the object library used for initializing the Hot3dDataProvider
|
| 180 |
+
"""
|
| 181 |
+
return self._object_library
|
| 182 |
+
|
| 183 |
+
@property
|
| 184 |
+
def device_data_provider(self):
|
| 185 |
+
"""
|
| 186 |
+
Return the device data provider (calibration and image stream data)
|
| 187 |
+
"""
|
| 188 |
+
return self._device_data_provider
|
| 189 |
+
|
| 190 |
+
@property
|
| 191 |
+
def mano_hand_data_provider(self) -> Optional[MANOHandDataProvider]:
|
| 192 |
+
"""
|
| 193 |
+
Return the Mano hand data provider
|
| 194 |
+
"""
|
| 195 |
+
return self._mano_hand_data_provider
|
| 196 |
+
|
| 197 |
+
@property
|
| 198 |
+
def umetrack_hand_data_provider(self) -> Optional[UmeTrackHandDataProvider]:
|
| 199 |
+
"""
|
| 200 |
+
Return the UmeTrack hand data provider
|
| 201 |
+
"""
|
| 202 |
+
return self._umetrack_hand_data_provider
|
| 203 |
+
|
| 204 |
+
@property
|
| 205 |
+
def object_box2d_data_provider(self):
|
| 206 |
+
"""
|
| 207 |
+
Return the object box2d data provider
|
| 208 |
+
"""
|
| 209 |
+
return self._object_box2d_provider
|
| 210 |
+
|
| 211 |
+
@property
|
| 212 |
+
def hand_box2d_data_provider(self):
|
| 213 |
+
"""
|
| 214 |
+
Return the hand box2d data provider
|
| 215 |
+
"""
|
| 216 |
+
return self._hand_box2d_provider
|
| 217 |
+
|
| 218 |
+
@property
|
| 219 |
+
def object_pose_data_provider(self) -> Optional[ObjectPose3dProvider]:
|
| 220 |
+
"""
|
| 221 |
+
Return the object pose provider
|
| 222 |
+
"""
|
| 223 |
+
return self._dynamic_objects_provider
|
| 224 |
+
|
| 225 |
+
@property
|
| 226 |
+
def device_pose_data_provider(self) -> Optional[HeadsetPose3dProvider]:
|
| 227 |
+
"""
|
| 228 |
+
Return the device pose provider
|
| 229 |
+
"""
|
| 230 |
+
return self._device_pose_provider
|
| 231 |
+
|
| 232 |
+
def get_device_type(self) -> Headset:
|
| 233 |
+
"""
|
| 234 |
+
Return the type of device used for recording (e.g. Quest3, Aria, etc.)
|
| 235 |
+
"""
|
| 236 |
+
return Headset[self.get_sequence_metadata()["headset"]]
|
| 237 |
+
|
| 238 |
+
def get_sequence_metadata(self) -> Dict:
|
| 239 |
+
"""
|
| 240 |
+
Return the metadata associated with the sequence
|
| 241 |
+
"""
|
| 242 |
+
metadata_json = load_json(self.path_provider.scene_metadata_filepath)
|
| 243 |
+
|
| 244 |
+
return metadata_json
|