diff --git a/run_tests.py b/run_tests.py new file mode 100644 index 0000000..03a358a --- /dev/null +++ b/run_tests.py @@ -0,0 +1,30 @@ +from pathlib import Path + +import infiray_irg + +test_files = sorted(Path('test_pictures').glob('*.irg')) + +for f in test_files: + try: + coarse, fine, vis = infiray_irg.load(f.read_bytes(), print_debug_information=True) + print('\033[93m', f'{f.name:>20}', 'Coldest pixel:', fine.min(), 'C', 'Hottest pixel:', fine.max(), 'C', '\033[0m') + except Exception as e: + print(f'Error parsing {f}') + raise e + +print() +print('Header diffs:') + +for offset, legend in { + 0: 'magc hlen coars_len yres xres flg0 unk1 zero fine unk2 jpeg_len_ yres xres emissivit fine_off1 fine_off2 distance_', + 64: ' unit gain'}.items(): + print(f'{" ":>20}', legend) + test_headers = {f: f.read_bytes()[offset:offset+64] for f in test_files} + header_idx_diffs = [len(set(header[i] for header in test_headers.values())) > 1 for i in range(64)] + for f, header in test_headers.items(): + print(f'{str(f.name):>20}', ' '.join( + ''.join( + (f'\033[91m{header[i]:02x}' if header_idx_diffs[i] else f'\033[0m{header[i]:02x}') + for i in range(chunk, chunk+2)) + for chunk in range(0, 64, 2) + )+'\033[0m') 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.