humaneva_dataset.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. # Copyright (c) 2018-present, Facebook, Inc.
  2. # All rights reserved.
  3. #
  4. # This source code is licensed under the license found in the
  5. # LICENSE file in the root directory of this source tree.
  6. #
  7. import numpy as np
  8. import copy
  9. from video_pose.common.skeleton import Skeleton
  10. from video_pose.common.mocap_dataset import MocapDataset
  11. from video_pose.common.camera import normalize_screen_coordinates, image_coordinates
  12. humaneva_skeleton = Skeleton(parents=[-1, 0, 1, 2, 3, 1, 5, 6, 0, 8, 9, 0, 11, 12, 1],
  13. joints_left=[2, 3, 4, 8, 9, 10],
  14. joints_right=[5, 6, 7, 11, 12, 13])
  15. humaneva_cameras_intrinsic_params = [
  16. {
  17. 'id': 'C1',
  18. 'res_w': 640,
  19. 'res_h': 480,
  20. 'azimuth': 0, # Only used for visualization
  21. },
  22. {
  23. 'id': 'C2',
  24. 'res_w': 640,
  25. 'res_h': 480,
  26. 'azimuth': -90, # Only used for visualization
  27. },
  28. {
  29. 'id': 'C3',
  30. 'res_w': 640,
  31. 'res_h': 480,
  32. 'azimuth': 90, # Only used for visualization
  33. },
  34. ]
  35. humaneva_cameras_extrinsic_params = {
  36. 'S1': [
  37. {
  38. 'orientation': [0.424207, -0.4983646, -0.5802981, 0.4847012],
  39. 'translation': [4062.227, 663.2477, 1528.397],
  40. },
  41. {
  42. 'orientation': [0.6503354, -0.7481602, -0.0919284, 0.0941766],
  43. 'translation': [844.8131, -3805.2092, 1504.9929],
  44. },
  45. {
  46. 'orientation': [0.0664734, -0.0690535, 0.7416416, -0.6639132],
  47. 'translation': [-797.67377, 3916.3174, 1433.6602],
  48. },
  49. ],
  50. 'S2': [
  51. {
  52. 'orientation': [ 0.4214752, -0.4961493, -0.5838273, 0.4851187 ],
  53. 'translation': [ 4112.9121, 626.4929, 1545.2988],
  54. },
  55. {
  56. 'orientation': [ 0.6501393, -0.7476588, -0.0954617, 0.0959808 ],
  57. 'translation': [ 923.5740, -3877.9243, 1504.5518],
  58. },
  59. {
  60. 'orientation': [ 0.0699353, -0.0712403, 0.7421637, -0.662742 ],
  61. 'translation': [ -781.4915, 3838.8853, 1444.9929],
  62. },
  63. ],
  64. 'S3': [
  65. {
  66. 'orientation': [ 0.424207, -0.4983646, -0.5802981, 0.4847012 ],
  67. 'translation': [ 4062.2271, 663.2477, 1528.3970],
  68. },
  69. {
  70. 'orientation': [ 0.6503354, -0.7481602, -0.0919284, 0.0941766 ],
  71. 'translation': [ 844.8131, -3805.2092, 1504.9929],
  72. },
  73. {
  74. 'orientation': [ 0.0664734, -0.0690535, 0.7416416, -0.6639132 ],
  75. 'translation': [ -797.6738, 3916.3174, 1433.6602],
  76. },
  77. ],
  78. 'S4': [
  79. {},
  80. {},
  81. {},
  82. ],
  83. }
  84. class HumanEvaDataset(MocapDataset):
  85. def __init__(self, path):
  86. super().__init__(fps=60, skeleton=humaneva_skeleton)
  87. self._cameras = copy.deepcopy(humaneva_cameras_extrinsic_params)
  88. for cameras in self._cameras.values():
  89. for i, cam in enumerate(cameras):
  90. cam.update(humaneva_cameras_intrinsic_params[i])
  91. for k, v in cam.items():
  92. if k not in ['id', 'res_w', 'res_h']:
  93. cam[k] = np.array(v, dtype='float32')
  94. if 'translation' in cam:
  95. cam['translation'] = cam['translation']/1000 # mm to meters
  96. for subject in list(self._cameras.keys()):
  97. data = self._cameras[subject]
  98. del self._cameras[subject]
  99. for prefix in ['Train/', 'Validate/', 'Unlabeled/Train/', 'Unlabeled/Validate/', 'Unlabeled/']:
  100. self._cameras[prefix + subject] = data
  101. # Load serialized dataset
  102. data = np.load(path, allow_pickle=True)['positions_3d'].item()
  103. self._data = {}
  104. for subject, actions in data.items():
  105. self._data[subject] = {}
  106. for action_name, positions in actions.items():
  107. self._data[subject][action_name] = {
  108. 'positions': positions,
  109. 'cameras': self._cameras[subject],
  110. }