Skip to content

Commit

Permalink
minor
Browse files Browse the repository at this point in the history
  • Loading branch information
TimoStoff committed Jul 7, 2020
1 parent 4737afa commit b6d85be
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
10 changes: 10 additions & 0 deletions scripts/extract_all_images_MMP.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
input_folder="${1?"Usage: $0 <input/folder> <output/folder>"}"
output_base_folder="${2?"Usage: $0 <input/folder> <output/folder>"}"
for input in "$input_folder"/*/; do
sequence_name=$(basename "$input")
output_folder="${output_base_folder}/${sequence_name}"
python "${EVENT_CNN_BASE}/utils/extract_images_MMP.py" \
"${input}/memmaps" \
"$output_folder"
done
45 changes: 45 additions & 0 deletions utils/extract_images_MMP.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import argparse
import cv2
import os
import numpy as np
from util import setup_output_folder, append_timestamp
from os.path import join
from tqdm import tqdm


def load_data(data_path, timestamp_fname='timestamps.npy', image_fname='images.npy'):

assert os.path.isdir(data_path), '%s is not a valid data_pathectory' % data_path

data = {}
for subroot, _, fnames in sorted(os.walk(data_path)):
for fname in sorted(fnames):
path = os.path.join(subroot, fname)
if fname.endswith('.npy'):
if fname.endswith(timestamp_fname):
frame_stamps = np.load(path)
data['frame_stamps'] = frame_stamps
elif fname.endswith(image_fname):
data['images'] = np.load(path, mmap_mode='r') # N x H x W x C
return data


def save_images(data, output_folder, ts_path):
for i, (image, ts) in enumerate(zip(tqdm(data['images']), data['frame_stamps'])):
fname = 'frame_{:010d}.png'.format(i)
cv2.imwrite(join(output_folder, fname), image)
append_timestamp(ts_path, fname, ts)


def main(args):
data = load_data(args.data_path)
ts_path = setup_output_folder(args.output_folder)
save_images(data, args.output_folder, ts_path)


if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('data_path', type=str)
parser.add_argument('output_folder', type=str)
args = parser.parse_args()
main(args)
6 changes: 3 additions & 3 deletions utils/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ def torch2cv2(image):
return (image * 255).astype(np.uint8)


def append_timestamp(filename, image_rel_path, timestamp):
with open(filename, 'a') as f:
f.write('{} {:.15f}\n'.format(image_rel_path, timestamp))
def append_timestamp(path, description, timestamp):
with open(path, 'a') as f:
f.write('{} {:.15f}\n'.format(description, timestamp))


def setup_output_folder(output_folder):
Expand Down

0 comments on commit b6d85be

Please sign in to comment.