forked from uzh-rpg/rpg_timelens
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_loader.py
43 lines (31 loc) · 1.24 KB
/
test_loader.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
import argparse
from os.path import join
import numpy as np
import cv2
import matplotlib.pyplot as plt
def render(events, image):
H, W, _ = image.shape
x = events['x'].astype("int")
y = events['y'].astype("int")
p = events['p']
mask = (x <= W-1) & (y <= H-1) & (x >= 0) & (y >= 0)
x_ = x[mask]
y_ = y[mask]
p_ = p[mask]
image[y_,x_,:] = 0
image[y_,x_,p_] = 255
return image
if __name__ == "__main__":
parser = argparse.ArgumentParser("Example Loader for a sample")
parser.add_argument("--dataset_root", default="")
parser.add_argument("--dataset_type", default="close")
parser.add_argument("--sequence", default="fountain_schaffhauserplatz_02")
parser.add_argument("--sample_index", type=int, default=200)
args = parser.parse_args()
event_file = join(args.dataset_root, "%s/test/%s/events_aligned/%06d.npz" % (args.dataset_type, args.sequence, args.sample_index))
image_file = join(args.dataset_root, "%s/test/%s/images_corrected/%06d.png" % (args.dataset_type, args.sequence, args.sample_index))
image = cv2.imread(image_file)[...,::-1]
events = np.load(event_file)
rendered_image = render(events, image)
plt.imshow(rendered_image)
plt.show()