from PIL import Image import warnings import numpy as np import struct import io __version__ = "1.4.0" def load(data, print_debug_information=False): def consume(n): nonlocal data out, data = data[:n], data[n:] if len(out) < n: raise ValueError(f'File is truncated, tried to read {n} bytes, but only {len(out)} bytes remain.') return out 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 # visible data. vis_jpg = Image.open(io.BytesIO(consume(jpeg_length))) elif model == 'other': if header[-2:] != bytes([0xac,0xca]): raise ValueError(f'Header end marker not found. Got header: {header[-2]:02x} {header[-1]:02x}') # 0.1 Kelvin steps fine_img = fine_img / 10 - 273.15 vis_jpg = Image.open(io.BytesIO(data)) else: fine_img = fine_img / 10 - 273.2 # In my example file, data now contains the JSON '{"roi":[]}' and no JPG. We ignore that. return coarse_img, fine_img, vis_jpg