Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- (*)~---------------------------------------------------------------------------
- Pupil - eye tracking platform
- Copyright (C) 2012-2019 Pupil Labs
- Distributed under the terms of the GNU
- Lesser General Public License (LGPL v3.0).
- See COPYING and COPYING.LESSER for license details.
- ---------------------------------------------------------------------------~(*)
- """
- import struct
- import numpy as np
- fmt = "<5s 9d 8d 9d"
- def pack(scene_sn, camera_matrix, dist_coefs, rotation_matrix):
- bytes_object = struct.pack(
- fmt,
- scene_sn.encode("utf-8"),
- *np.asarray(camera_matrix).ravel(),
- *np.asarray(dist_coefs).ravel(),
- *np.asarray(rotation_matrix).ravel()
- )
- return bytes_object
- def unpack(bytes_object):
- data = struct.unpack(fmt, bytes_object)
- scene_sn = data[0].decode("utf-8")
- camera_matrix = np.array(data[1:10]).reshape(3, 3)
- dist_coefs = np.array(data[10:18]).reshape(1, 8)
- rotation_matrix = np.array(data[18:27]).reshape(3, 3)
- return scene_sn, camera_matrix, dist_coefs, rotation_matrix
- if __name__ == "__main__":
- _scene_sn = "abcde"
- _camera_matrix = [
- [768.6506227400141, 0.0, 544.4086390822918],
- [0.0, 767.3984920290931, 542.8625702918421],
- [0.0, 0.0, 1.0],
- ]
- _dist_coefs = [
- [
- -0.12274814768315563,
- 0.09836418807524534,
- 0.0013970017965074415,
- -0.0002234252202650275,
- 0.022460546276536732,
- 0.20394056772660388,
- 0.008570320041593258,
- 0.07025679279405483,
- ]
- ]
- _rotation_matrix = [
- [-0.34290609741413736, -0.9252517728941283, -0.16224846721149222],
- [-0.3344758020769028, 0.28166226772991476, -0.8993288079241397],
- [0.8778048451570649, -0.2541171456110631, -0.4060580378779209],
- ]
- _bytes_object = pack(_scene_sn, _camera_matrix, _dist_coefs, _rotation_matrix)
- print(_bytes_object)
- print(unpack(_bytes_object))
- print(struct.calcsize(fmt))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement