| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| import os |
| from typing import Any, Dict, Optional |
|
|
| import data_loaders.HandBox2dDataProvider as HandBox2dDataProvider |
| import data_loaders.ObjectBox2dDataProvider as ObjectBox2dDataProvider |
| from data_loaders.AriaDataProvider import AriaDataProvider |
| from data_loaders.HeadsetPose3dProvider import ( |
| HeadsetPose3dProvider, |
| load_headset_pose_provider_from_csv, |
| ) |
| from data_loaders.headsets import Headset |
| from data_loaders.io_utils import load_json |
| from data_loaders.loader_object_library import ObjectLibrary |
| from data_loaders.mano_layer import MANOHandModel |
| from data_loaders.ManoHandDataProvider import MANOHandDataProvider |
| from data_loaders.ObjectPose3dProvider import ( |
| load_pose_provider_from_csv, |
| ObjectPose3dProvider, |
| ) |
| from data_loaders.PathProvider import Hot3dDataPathProvider |
| from data_loaders.QuestDataProvider import QuestDataProvider |
| from data_loaders.UmeTrackHandDataProvider import UmeTrackHandDataProvider |
|
|
| |
| |
|
|
| |
| |
|
|
| |
| |
|
|
|
|
| class Hot3dDataProvider: |
| """ |
| High Level interface to retrieve and use data from the hot3d dataset |
| """ |
|
|
| def __init__( |
| self, |
| sequence_folder: str, |
| object_library: ObjectLibrary, |
| mano_hand_model: Optional[MANOHandModel] = None, |
| fail_on_missing_data: bool = True, |
| ) -> None: |
| """ |
| INIT_DOC_STRING |
| """ |
| |
| |
| |
| |
| self.path_provider = Hot3dDataPathProvider.fromRecordingFolder( |
| recording_instance_folderpath=sequence_folder |
| ) |
| |
| if not self.path_provider.is_valid(): |
| missing_filepaths = [ |
| filepath |
| for filepath in self.path_provider.required_filepaths |
| if not os.path.exists(filepath) |
| ] |
|
|
| if fail_on_missing_data: |
| raise RuntimeError( |
| f"Invalid hot3d path. Not all expected data are present. missing_filepaths: {missing_filepaths}" |
| ) |
| else: |
| print( |
| f"Not all expected data are present. missing_filepaths: {missing_filepaths}" |
| ) |
|
|
| self._dynamic_objects_provider = load_pose_provider_from_csv( |
| self.path_provider.dynamic_objects_filepath |
| ) |
| |
| self._device_pose_provider = load_headset_pose_provider_from_csv( |
| self.path_provider.headset_trajectory_filepath |
| ) |
| |
| self._object_box2d_provider = ( |
| ObjectBox2dDataProvider.load_box2d_trajectory_from_csv( |
| self.path_provider.box2d_objects_filepath |
| ) |
| ) |
| |
| self._hand_box2d_provider = ( |
| HandBox2dDataProvider.load_box2d_trajectory_from_csv( |
| self.path_provider.box2d_hands_filepath |
| ) |
| ) |
|
|
| self._object_library: ObjectLibrary = object_library |
|
|
| self._mano_hand_data_provider = None |
| if os.path.isfile(self.path_provider.mano_hand_pose_trajectory_filepath): |
| if mano_hand_model is not None: |
| self._mano_hand_data_provider = MANOHandDataProvider( |
| |
| self.path_provider.mano_hand_pose_trajectory_filepath, |
| mano_hand_model, |
| ) |
| else: |
| print("No MANO hand model provided, skipping MANO hand data provider") |
| else: |
| print( |
| f"WARN: Cannot find {self.path_provider.mano_hand_pose_trajectory_filepath}" |
| ) |
| |
| |
| self._umetrack_hand_data_provider = None |
| if os.path.exists( |
| self.path_provider.umetrack_hand_pose_trajectory_filepath |
| ) and os.path.exists(self.path_provider.umetrack_hand_user_profile_filepath): |
| self._umetrack_hand_data_provider = UmeTrackHandDataProvider( |
| self.path_provider.umetrack_hand_pose_trajectory_filepath, |
| self.path_provider.umetrack_hand_user_profile_filepath, |
| ) |
|
|
| if self.get_device_type() == Headset.Aria: |
| self._device_data_provider = AriaDataProvider( |
| self.path_provider.vrs_filepath, |
| self.path_provider.mps_folderpath, |
| ) |
| elif self.get_device_type() == Headset.Quest3: |
| self._device_data_provider = QuestDataProvider( |
| |
| self.path_provider.vrs_filepath, |
| |
| self.path_provider.camera_models_filepath, |
| ) |
| else: |
| raise RuntimeError(f"Unsupported device type {self.get_device_type()}") |
|
|
| def get_data_statistics(self) -> Dict[str, Any]: |
| statistics_dict = {} |
| statistics_dict["dynamic_objects"] = ( |
| self._dynamic_objects_provider.get_data_statistics() |
| ) |
|
|
| if self._mano_hand_data_provider is not None: |
| statistics_dict["mano_hand_poses"] = ( |
| self._mano_hand_data_provider.get_data_statistics() |
| ) |
|
|
| if self._umetrack_hand_data_provider is not None: |
| statistics_dict["umetrack_hand_poses"] = ( |
| self._umetrack_hand_data_provider.get_data_statistics() |
| ) |
|
|
| if self._object_box2d_provider is not None: |
| statistics_dict["object_box2ds"] = ( |
| self.object_box2d_data_provider.get_data_statistics() |
| ) |
|
|
| if self._hand_box2d_provider is not None: |
| statistics_dict["hand_box2ds"] = ( |
| self.hand_box2d_data_provider.get_data_statistics() |
| ) |
| return statistics_dict |
|
|
| @property |
| def object_library(self) -> ObjectLibrary: |
| """ |
| Return the object library used for initializing the Hot3dDataProvider |
| """ |
| return self._object_library |
|
|
| @property |
| def device_data_provider(self): |
| """ |
| Return the device data provider (calibration and image stream data) |
| """ |
| return self._device_data_provider |
|
|
| @property |
| def mano_hand_data_provider(self) -> Optional[MANOHandDataProvider]: |
| """ |
| Return the Mano hand data provider |
| """ |
| return self._mano_hand_data_provider |
|
|
| @property |
| def umetrack_hand_data_provider(self) -> Optional[UmeTrackHandDataProvider]: |
| """ |
| Return the UmeTrack hand data provider |
| """ |
| return self._umetrack_hand_data_provider |
|
|
| @property |
| def object_box2d_data_provider(self): |
| """ |
| Return the object box2d data provider |
| """ |
| return self._object_box2d_provider |
|
|
| @property |
| def hand_box2d_data_provider(self): |
| """ |
| Return the hand box2d data provider |
| """ |
| return self._hand_box2d_provider |
|
|
| @property |
| def object_pose_data_provider(self) -> Optional[ObjectPose3dProvider]: |
| """ |
| Return the object pose provider |
| """ |
| return self._dynamic_objects_provider |
|
|
| @property |
| def device_pose_data_provider(self) -> Optional[HeadsetPose3dProvider]: |
| """ |
| Return the device pose provider |
| """ |
| return self._device_pose_provider |
|
|
| def get_device_type(self) -> Headset: |
| """ |
| Return the type of device used for recording (e.g. Quest3, Aria, etc.) |
| """ |
| return Headset[self.get_sequence_metadata()["headset"]] |
|
|
| def get_sequence_metadata(self) -> Dict: |
| """ |
| Return the metadata associated with the sequence |
| """ |
| metadata_json = load_json(self.path_provider.scene_metadata_filepath) |
|
|
| return metadata_json |
|
|