Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. """
  2. (*)~---------------------------------------------------------------------------
  3. Pupil - eye tracking platform
  4. Copyright (C) 2012-2019 Pupil Labs
  5.  
  6. Distributed under the terms of the GNU
  7. Lesser General Public License (LGPL v3.0).
  8. See COPYING and COPYING.LESSER for license details.
  9. ---------------------------------------------------------------------------~(*)
  10. """
  11.  
  12. import struct
  13.  
  14. import numpy as np
  15.  
  16. fmt = "<5s 9d 8d 9d"
  17.  
  18.  
  19. def pack(scene_sn, camera_matrix, dist_coefs, rotation_matrix):
  20. bytes_object = struct.pack(
  21. fmt,
  22. scene_sn.encode("utf-8"),
  23. *np.asarray(camera_matrix).ravel(),
  24. *np.asarray(dist_coefs).ravel(),
  25. *np.asarray(rotation_matrix).ravel()
  26. )
  27. return bytes_object
  28.  
  29.  
  30. def unpack(bytes_object):
  31. data = struct.unpack(fmt, bytes_object)
  32.  
  33. scene_sn = data[0].decode("utf-8")
  34. camera_matrix = np.array(data[1:10]).reshape(3, 3)
  35. dist_coefs = np.array(data[10:18]).reshape(1, 8)
  36. rotation_matrix = np.array(data[18:27]).reshape(3, 3)
  37.  
  38. return scene_sn, camera_matrix, dist_coefs, rotation_matrix
  39.  
  40.  
  41. if __name__ == "__main__":
  42. _scene_sn = "abcde"
  43. _camera_matrix = [
  44. [768.6506227400141, 0.0, 544.4086390822918],
  45. [0.0, 767.3984920290931, 542.8625702918421],
  46. [0.0, 0.0, 1.0],
  47. ]
  48. _dist_coefs = [
  49. [
  50. -0.12274814768315563,
  51. 0.09836418807524534,
  52. 0.0013970017965074415,
  53. -0.0002234252202650275,
  54. 0.022460546276536732,
  55. 0.20394056772660388,
  56. 0.008570320041593258,
  57. 0.07025679279405483,
  58. ]
  59. ]
  60. _rotation_matrix = [
  61. [-0.34290609741413736, -0.9252517728941283, -0.16224846721149222],
  62. [-0.3344758020769028, 0.28166226772991476, -0.8993288079241397],
  63. [0.8778048451570649, -0.2541171456110631, -0.4060580378779209],
  64. ]
  65.  
  66. _bytes_object = pack(_scene_sn, _camera_matrix, _dist_coefs, _rotation_matrix)
  67. print(_bytes_object)
  68.  
  69. print(unpack(_bytes_object))
  70.  
  71. print(struct.calcsize(fmt))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement