thermalcam_decoder/test_rust.py

33 lines
947 B
Python
Raw Permalink Normal View History

2023-12-29 17:33:10 +02:00
#!/usr/bin/env python3
2023-12-29 17:05:44 +02:00
from pathlib import Path
from thermaldecoder import decode
import numpy as np
import subprocess
2023-12-29 17:05:44 +02:00
import matplotlib.pyplot as plt
# Create a directory to store the frames if it doesn't exist
2023-12-29 17:05:44 +02:00
root = Path('frames')
root.mkdir(exist_ok=True)
# Decode the frames from the pcap file
frames = list(decode('indesk.pcapng'))
# Iterate over the frames
for i, frame in enumerate(frames):
try:
# Convert the frame to an image file
img_path = root / f"frame_{i}.png"
f = np.array(frame)
f.shape = (384, 288)
plt.imshow(f)
plt.axis('off')
plt.savefig(img_path, bbox_inches='tight', pad_inches=0)
plt.close()
# Use ffmpeg to display the image
subprocess.run(['ffmpeg', '-i', str(img_path), '-vf', 'scale=800:600', '-framerate', '25', '-f', 'image2pipe', '-'], check=True)
except ValueError as e:
print(f"Error processing frame {i}: {e}")