-
Notifications
You must be signed in to change notification settings - Fork 3
/
play_images.py
79 lines (67 loc) · 2.8 KB
/
play_images.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#
# This file is part of wganvo.
# This file is based on a file from https://github.com/ori-mrg/robotcar-dataset-sdk
# (see original license below)
#
# Modifications copyright (C) 2019 Javier Cremona (CIFASIS-CONICET)
# For more information see <https://github.com/CIFASIS/wganvo>
#
# This file is licensed under the Creative Commons
# Attribution-NonCommercial-ShareAlike 4.0 International License.
# To view a copy of this license, visit
# http://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to
# Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.
#
################################################################################
#
# Copyright (c) 2017 University of Oxford
# Authors:
# Geoff Pascoe ([email protected])
#
# This work is licensed under the Creative Commons
# Attribution-NonCommercial-ShareAlike 4.0 International License.
# To view a copy of this license, visit
# http://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to
# Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.
#
################################################################################
import argparse
import os
import re
import matplotlib.pyplot as plt
from datetime import datetime as dt
from image import load_image
from camera_model import CameraModel
parser = argparse.ArgumentParser(description='Play back images from a given directory')
parser.add_argument('dir', type=str, help='Directory containing images.')
parser.add_argument('--models_dir', type=str, default=None, help='(optional) Directory containing camera model. If supplied, images will be undistorted before display')
parser.add_argument('--scale', type=float, default=1.0, help='(optional) factor by which to scale images before display')
args = parser.parse_args()
camera = re.search('(stereo|mono_(left|right|rear))', args.dir).group(0)
timestamps_path = os.path.join(os.path.join(args.dir, os.pardir, camera + '.timestamps'))
if not os.path.isfile(timestamps_path):
timestamps_path = os.path.join(args.dir, os.pardir, os.pardir, camera + '.timestamps')
if not os.path.isfile(timestamps_path):
raise IOError("Could not find timestamps file")
model = None
if args.models_dir:
model = CameraModel(args.models_dir, args.dir)
current_chunk = 0
timestamps_file = open(timestamps_path)
for line in timestamps_file:
tokens = line.split()
datetime = dt.utcfromtimestamp(int(tokens[0])/1000000)
chunk = int(tokens[1])
filename = os.path.join(args.dir, tokens[0] + '.png')
if not os.path.isfile(filename):
if chunk != current_chunk:
print("Chunk " + str(chunk) + " not found")
current_chunk = chunk
continue
current_chunk = chunk
img = load_image(filename, model)
plt.imshow(img)
plt.xlabel(datetime)
plt.xticks([])
plt.yticks([])
plt.pause(0.01)