-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdvs-play.py
68 lines (48 loc) · 1.48 KB
/
dvs-play.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
"""
Play DVS events in real time
TODO: deal with looping event times for recordings > 65 s
"""
import numpy as np
import matplotlib.pyplot as plt
import dvs
def close(a, b, atol=1e-8, rtol=1e-5):
return np.abs(a - b) < atol + rtol * b
def imshow(image, ax=None):
ax = plt.gca() if ax is None else ax
ax.imshow(image, vmin=-1, vmax=1, cmap='gray', interpolation=None)
def add_to_image(image, events):
for x, y, s, _ in events:
image[y, x] += 1 if s else -1
def as_image(events):
image = np.zeros((128, 128), dtype=float)
add_to_image(image, events)
return image
# filename = 'dvs.npz'
filename = 'dvs-ball-10ms.npz'
events = dvs.load(filename, dt_round=True)
udiffs = np.unique(np.diff(np.unique(events['t'])))
assert np.allclose(udiffs, 0.01)
plt.figure(1)
plt.clf()
times = [0.2, 0.3, 0.4, 0.5, 0.6, 0.7]
for i in range(6):
plt.subplot(2, 3, i+1)
imshow(as_image(events[close(events['t'], times[i])]))
plt.title("t = %0.3f" % times[i])
# plt.figure(1)
# plt.clf()
# image = np.zeros((128, 128), dtype=float)
# plt_image = plt.imshow(image, vmin=-1, vmax=1, cmap='gray', interpolation=None)
# plt.gca().invert_yaxis()
# while t0 < t_max:
# time.sleep(0.001)
# t1 = time.time() - t_world
# new_events = events[(ts > t0) & (ts < t1)]
# dt = t1 - t0
# image *= np.exp(-dt / 0.01)
# for x, y, s, _ in new_events:
# image[y, x] += 1 if s else -1
# plt_image.set_data(image)
# plt.draw()
# t0 = t1
plt.show()