Compare commits
3 Commits
eaf7294d06
...
5290f60500
Author | SHA1 | Date | |
---|---|---|---|
|
5290f60500 | ||
|
f56d82487d | ||
|
e7ab3b6c80 |
28
decode.py
28
decode.py
|
@ -6,9 +6,7 @@ from tqdm import tqdm
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
import pcapng
|
import pcapng
|
||||||
from struct import unpack
|
from struct import unpack
|
||||||
import matplotlib.pyplot as plt
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
from PIL import Image, ImageDraw
|
|
||||||
import cv2
|
import cv2
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,6 +38,7 @@ def parse(data):
|
||||||
ret['data'] = data[hdr:]
|
ret['data'] = data[hdr:]
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
df = pd.DataFrame([parse(d) for d in raw])
|
df = pd.DataFrame([parse(d) for d in raw])
|
||||||
df2 = df[[c for c in df.columns if c != 'data']]
|
df2 = df[[c for c in df.columns if c != 'data']]
|
||||||
|
|
||||||
|
@ -60,23 +59,26 @@ def getframes(df):
|
||||||
|
|
||||||
|
|
||||||
def image16(frame, width, height, pixelformat='>H'):
|
def image16(frame, width, height, pixelformat='>H'):
|
||||||
return [Image.fromarray(np.frombuffer(frame, dtype=pixelformat).reshape(width, height)) for frame in frames if len(frame) == 2 * width * height]
|
return [
|
||||||
|
Image.fromarray(np.frombuffer(frame, dtype=pixelformat).reshape(width, height)) for frame in frames
|
||||||
|
if len(frame) == 2 * width * height
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
def showvideo(images):
|
def showvideo(images):
|
||||||
# wip
|
# wip
|
||||||
videodims = images[0].size
|
videodims = images[0].size
|
||||||
fourcc = cv2.VideoWriter_fourcc(*'avc1')
|
fourcc = cv2.VideoWriter_fourcc(*'avc1')
|
||||||
video = cv2.VideoWriter("test.mp4",fourcc, 60,videodims)
|
video = cv2.VideoWriter("test.mp4", fourcc, 60, videodims)
|
||||||
img = Image.new('RGB', videodims, color = 'darkred')
|
img = Image.new('RGB', videodims, color='darkred')
|
||||||
#draw stuff that goes on every frame here
|
# draw stuff that goes on every frame here
|
||||||
for i in range(0,60*60):
|
for i in range(0, 60*60):
|
||||||
imtemp = img.copy()
|
imtemp = img.copy()
|
||||||
# draw frame specific stuff here.
|
# draw frame specific stuff here.
|
||||||
video.write(cv2.cvtColor(np.array(imtemp), cv2.COLOR_RGB2BGR))
|
video.write(cv2.cvtColor(np.array(imtemp), cv2.COLOR_RGB2BGR))
|
||||||
video.release()
|
video.release()
|
||||||
|
|
||||||
#def shape(frames, width, height, mode='RGB'):
|
# def shape(frames, width, height, mode='RGB'):
|
||||||
# return [Image.frombytes('RGB', (width, height), frame) for frame in frames if len(frame) == width * height * 3]
|
# return [Image.frombytes('RGB', (width, height), frame) for frame in frames if len(frame) == width * height * 3]
|
||||||
|
|
||||||
|
|
||||||
|
@ -84,11 +86,11 @@ frames = getframes(df)
|
||||||
images = image16(frames, 384, 288)
|
images = image16(frames, 384, 288)
|
||||||
for i, img in enumerate(tqdm(images)):
|
for i, img in enumerate(tqdm(images)):
|
||||||
img.save(f'{i:04}.png')
|
img.save(f'{i:04}.png')
|
||||||
#frame = b''.join(df.iloc[:32]['data'])
|
# frame = b''.join(df.iloc[:32]['data'])
|
||||||
#Image.frombytes('RGB', (288, 256), frame).show()
|
# Image.frombytes('RGB', (288, 256), frame).show()
|
||||||
start_len = len(b'T=(-1.665884e-08)*X^4+(1.347094e-05)*X^3+(-4.396264e-03)*X^2+(9.506939e-01)*X+(-6.353247e+01)\r\n ')
|
start_len = len(b'T=(-1.665884e-08)*X^4+(1.347094e-05)*X^3+(-4.396264e-03)*X^2+(9.506939e-01)*X+(-6.353247e+01)\r\n')
|
||||||
# 250 bytes at start of frame
|
|
||||||
|
|
||||||
|
# 250 bytes at start of frame
|
||||||
equations = {x[:250].decode().strip() for x in df[df.part == 0]['data']}
|
equations = {x[:250].decode().strip() for x in df[df.part == 0]['data']}
|
||||||
# seen only a single equation on all packets
|
# seen only a single equation on all packets
|
||||||
assert len(equations) == 1
|
assert len(equations) == 1
|
||||||
|
@ -99,5 +101,5 @@ assert list(equations)[0] == 'T=(-1.665884e-08)*X^4+(1.347094e-05)*X^3+(-4.39626
|
||||||
assert df.shape[0] == 6372
|
assert df.shape[0] == 6372
|
||||||
|
|
||||||
# produce a video
|
# produce a video
|
||||||
system('ffmpeg -f image2 -framerate 25 -i %04d.png -s 288x384 thermal.mp4')
|
system('ffmpeg -f image2 -framerate 25 -i %04d.png -vf "transpose=1" -s 384x288 -vcodec libx264 -pix_fmt yuv420p thermal.mp4')
|
||||||
print('to play: ffplay thermal.mp4')
|
print('to play: ffplay thermal.mp4')
|
||||||
|
|
BIN
thermal.avi
BIN
thermal.avi
Binary file not shown.
BIN
thermal.mp4
BIN
thermal.mp4
Binary file not shown.
Loading…
Reference in New Issue
Block a user