Skip to content

Instantly share code, notes, and snippets.

@etienne87
Created July 4, 2019 07:52
Show Gist options
  • Save etienne87/2152a339178f6ef06b9b1e244e8f060c to your computer and use it in GitHub Desktop.
Save etienne87/2152a339178f6ef06b9b1e244e8f060c to your computer and use it in GitHub Desktop.
viz_ts.py
from __future__ import print_function
import time
import numpy as np
import cv2
from prophesee_utils.td_video import ChronoVideo
if __name__ == '__main__':
delay = 1
base_delay = 1
stop = False
tau = 1e6
mu = 1e5
std = 1e5
tmax = 100000
path = '/home/eperot/workspace/data/videos/mercredi_moorea_0_0_td.dat'
video = ChronoVideo(path)
height, width = video.get_size()
video.seek_time(1e6)
scale = 1
ts = np.zeros((height, width, 2), dtype=np.float32)
ts_debug = np.zeros((height, width, 2), dtype=np.float32)
viz = np.zeros((height, width, 3), dtype=np.float32)
hsvImg = np.zeros((height, width, 3), dtype=np.uint8)
def nothing(x): pass
cv2.namedWindow('ts')
cv2.createTrackbar('tau', 'ts', 2, 10, nothing)
cv2.setTrackbarPos('tau', 'ts', 6)
while not video.done:
if not stop:
try:
xypt = video.load_delta_t(tmax)
except BaseException:
break
start = time.time()
x = xypt['x']
y = xypt['y']
p = xypt['p']
t = xypt['ts']
last_time = t[-1]
ts[y, x, p] = t # magic hack
tsp = ts.reshape(height / scale, scale, width / scale, scale, 2)
tsm = np.mean(tsp, axis=(1, 3))
max_ts = tsm.max(axis=(0, 1))[None, None, :]
delta = (tsm - max_ts) / tau
expdelta = np.exp(delta)
# max_ts = np.max(ts, axis=(0,1))
# expdelta = ts / max_ts * tau
min_ed = expdelta.min(axis=(0, 1))[None, None, :]
max_ed = expdelta.max(axis=(0, 1))[None, None, :]
img = (expdelta - min_ed) / (max_ed - min_ed + 1e-7)
# print(img.min(), img.max(), img.mean())
img = cv2.resize(img, (width, height), interpolation=cv2.INTER_NEAREST)
viz[...] = 0
viz[..., :2] = img
cv2.imshow('ts', viz)
key = cv2.waitKey(10)
if key & 0xFF == ord('a'):
next_time = video.current_time - 1e7
video.seek_time(next_time)
tracks = []
print('current time = ', video.current_time * 1e-6)
if key & 0xFF == ord('z'):
next_time = video.current_time + 1e7
video.seek_time(next_time)
tracks = []
print('current time = ', video.current_time * 1e-6)
if key & 0xFF == ord('p'):
stop = 1 - stop
tau_ = cv2.getTrackbarPos('tau', 'ts')
tau = 10**tau_
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment