From 176c1ccac2a2c758ac3a5d3922e05a1b936360e5 Mon Sep 17 00:00:00 2001 From: jaseg Date: Wed, 5 Feb 2025 20:27:59 +0100 Subject: Fix offset issues. This commit is tested against all test files I have available. We tried to parse the temperature array offset from the file to match that one Autel device, but that ended up breaking other stuff. It seems the offset is not explicitly recorded. TODO: Figure out if they are using 273.0 or 273.15 K. --- src/infiray_irg.py | 64 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 25 deletions(-) (limited to 'src/infiray_irg.py') diff --git a/src/infiray_irg.py b/src/infiray_irg.py index c6a583a..400febb 100644 --- a/src/infiray_irg.py +++ b/src/infiray_irg.py @@ -6,7 +6,7 @@ import io __version__ = "1.4.0" -def load(data): +def load(data, print_debug_information=False): def consume(n): nonlocal data out, data = data[:n], data[n:] @@ -14,7 +14,18 @@ def load(data): raise ValueError(f'File is truncated, tried to read {n} bytes, but only {len(out)} bytes remain.') return out - header = consume(128) + header = consume(4) + _magic, header_len = struct.unpack(' 0: # I have seen a file from an Autel Robotics Evo II Dual 640T V3 that looks like a C201 file, but lacks the @@ -66,20 +85,15 @@ def load(data): vis_jpg = Image.open(io.BytesIO(consume(jpeg_length))) elif model == 'other': - if header[-2:] != bytes([0xab,0xba]): + if header[-2:] != bytes([0xac,0xca]): raise ValueError(f'Header end marker not found. Got header: {header[-2]:02x} {header[-1]:02x}') - coarse_img = np.frombuffer(consume(coarse_section_length), dtype=np.uint8).reshape((y_res, x_res)) # 0.1 Kelvin steps - fine_img = np.frombuffer(consume(x_res*y_res*2), dtype=np.uint16).reshape((y_res, x_res)) - fine_img = fine_img / 10 - fine_temp_offset + fine_img = fine_img / 10 - 273.15 vis_jpg = Image.open(io.BytesIO(data)) else: - header += consume(128) - coarse_img = np.frombuffer(consume(coarse_section_length), dtype=np.uint8).reshape((y_res, x_res)) - fine_img = np.frombuffer(consume(x_res*y_res*2), dtype=np.uint16).reshape((y_res, x_res)) - fine_img = fine_img / 10 - fine_temp_offset + fine_img = fine_img / 10 - 273.2 # In my example file, data now contains the JSON '{"roi":[]}' and no JPG. We ignore that. -- cgit