Skip to content
Snippets Groups Projects
Commit 85a07a96 authored by Sebastian Hahta's avatar Sebastian Hahta
Browse files

python: msgpack calibration (read support)

parent 013fbdc0
No related branches found
No related tags found
1 merge request!200python ftl-file v3
Pipeline #17176 passed
...@@ -12,8 +12,6 @@ from . misc import is_iframe ...@@ -12,8 +12,6 @@ from . misc import is_iframe
from . import ftltypes as ftl from . import ftltypes as ftl
from . import libde265 from . import libde265
_calib_fmt = "@ddddIIdddd"
try: try:
import cv2 as cv import cv2 as cv
...@@ -44,10 +42,10 @@ except ImportError: ...@@ -44,10 +42,10 @@ except ImportError:
return rgb.round().astype(np.uint8) return rgb.round().astype(np.uint8)
class FTLStreamWriter: class FTLStreamWriter:
def __init__(self, file): def __init__(self, file, version=2):
self._file = open(file, "wb") self._file = open(file, "wb")
self._file.write(bytes(ord(c) for c in "FTLF")) # magic self._file.write(bytes(ord(c) for c in "FTLF")) # magic
self._file.write(bytes([2])) # version self._file.write(bytes([version])) # version
self._file.write(bytes([0]*64)) # reserved self._file.write(bytes([0]*64)) # reserved
self._packer = msgpack.Packer(strict_types=False, use_bin_type=True) self._packer = msgpack.Packer(strict_types=False, use_bin_type=True)
...@@ -134,7 +132,8 @@ class FTLStreamWriter: ...@@ -134,7 +132,8 @@ class FTLStreamWriter:
raise NotImplementedError("todo") raise NotImplementedError("todo")
def add_calibration(self, timestamp, source, data): def add_calibration(self, timestamp, source, data):
struct.pack(_calib_fmt, *data) # todo: Use msgpack format instead (ftlf v3+)
struct.pack("@ddddIIdddd", *data)
raise NotImplementedError("todo") raise NotImplementedError("todo")
class FTLStreamReader: class FTLStreamReader:
...@@ -180,9 +179,18 @@ class FTLStreamReader: ...@@ -180,9 +179,18 @@ class FTLStreamReader:
def _update_calib(self, sp, p): def _update_calib(self, sp, p):
''' Update calibration. ''' ''' Update calibration. '''
calibration = struct.unpack(_calib_fmt, p.data[:(4*8+2*4+4*8)])
if p.codec == ftl.codec_t.MSGPACK:
# TODO: What is in (unpacked) p.data[1:]? Contents discarded at the moment
self._calibration[sp.streamID] = ftl.Camera._make(msgpack.unpackb(p.data)[0])
elif p.codec == ftl.codec_t.CALIBRATION:
calibration = struct.unpack("@ddddIIdddd", p.data[:(4*8+2*4+4*8)])
self._calibration[sp.streamID] = ftl.Camera._make(calibration) self._calibration[sp.streamID] = ftl.Camera._make(calibration)
else:
raise Exception("Unknown codec %i for calibration" % p.codec)
def _update_pose(self, sp, p): def _update_pose(self, sp, p):
''' Update pose ''' ''' Update pose '''
pose = np.asarray(struct.unpack("@16d", p.data[:(16*8)]), pose = np.asarray(struct.unpack("@16d", p.data[:(16*8)]),
...@@ -268,16 +276,15 @@ class FTLStreamReader: ...@@ -268,16 +276,15 @@ class FTLStreamReader:
if self._p.block_total != 1 or self._p.block_number != 0: if self._p.block_total != 1 or self._p.block_number != 0:
raise Exception("Unsupported block format (todo)") raise Exception("Unsupported block format (todo)")
if self._p.codec == ftl.codec_t.JSON: if self._sp.channel == ftl.Channel.Calibration:
self._process_json(self._sp, self._p)
elif self._p.codec == ftl.codec_t.CALIBRATION:
self._update_calib(self._sp, self._p) self._update_calib(self._sp, self._p)
elif self._p.codec == ftl.codec_t.POSE: elif self._sp.channel == ftl.Channel.Pose:
self._update_pose(self._sp, self._p) self._update_pose(self._sp, self._p)
elif self._p.codec == ftl.codec_t.HEVC: elif self._sp.channel in (ftl.Channel.Left,ftl.Channel.Left):
# Decode Left/Right
if self._p.codec == ftl.codec_t.HEVC:
self._decode_hevc(self._sp, self._p) self._decode_hevc(self._sp, self._p)
elif self._p.codec == ftl.codec_t.PNG: elif self._p.codec == ftl.codec_t.PNG:
...@@ -286,9 +293,6 @@ class FTLStreamReader: ...@@ -286,9 +293,6 @@ class FTLStreamReader:
elif self._p.codec == ftl.codec_t.JPG: elif self._p.codec == ftl.codec_t.JPG:
self._decode_opencv(self._sp, self._p) self._decode_opencv(self._sp, self._p)
else:
raise Exception("unkowno codec %i" % self._p.codec)
return True return True
def get_packet_count(self): def get_packet_count(self):
......
...@@ -65,7 +65,9 @@ class codec_t(IntEnum): ...@@ -65,7 +65,9 @@ class codec_t(IntEnum):
JSON = 100 JSON = 100
CALIBRATION = 101 CALIBRATION = 101
POSE = 102 POSE = 102
RAW = 103 MSGPACK = 103,
STRING = 104,
RAW = 105
definition_t = { definition_t = {
0 : (7680, 4320), 0 : (7680, 4320),
...@@ -85,4 +87,3 @@ def get_definition(shape): ...@@ -85,4 +87,3 @@ def get_definition(shape):
return k return k
return 7 # (None) return 7 # (None)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment