diff --git a/research/.gitignore b/research/.gitignore new file mode 100644 index 0000000..3af0ccb --- /dev/null +++ b/research/.gitignore @@ -0,0 +1 @@ +/data diff --git a/research/extract-frames.py b/research/extract-frames.py new file mode 100755 index 0000000..87f4929 --- /dev/null +++ b/research/extract-frames.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python3 + +import os +import sys +import json +import base64 + +def save_image(data_url, fn): + pref = "data:image/jpeg;base64," + if data_url.startswith(pref): + b = base64.b64decode(data_url[len(pref):]) + ext = 'jpg' + pref = "data:image/png;base64," + if data_url.startswith(pref): + b = base64.b64decode(data_url[len(pref):]) + ext = 'png' + fn = f'{fn}.{ext}' + with open(fn, 'wb') as fd: + fd.write(b) + return fn + +for r, ds, fs in os.walk('raw/camera-frame'): + for f in fs: + fn = os.path.join(r, f) + with open(fn, 'r') as fd: + data = json.load(fd) + phone_model = data.get('phone_model', 'unknown') + session_id = data.get('session_id', 'unknown') + seq_num = data.get('seq_num', 'unknown') + fn = os.path.join('data/frames', f'{phone_model}-{session_id}-{seq_num}') + fn = save_image(data['image_data_url'], fn) + print(fn) diff --git a/research/fetch-all.sh b/research/fetch-all.sh new file mode 100755 index 0000000..19cd112 --- /dev/null +++ b/research/fetch-all.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +rsync -arP zy:/data/emblem-research/ raw \ No newline at end of file