def show_em(self):
"""Displays the EM events (grayscale ATIS events)"""
frame_length = 24e3
t_max = self.data.ts[-1]
frame_start = self.data[0].ts
frame_end = self.data[0].ts + frame_length
max_val = 1.16e5
min_val = 1.74e3
val_range = max_val - min_val
thr = np.rec.array(None, dtype=[('valid', np.bool_), ('low', np.uint64), ('high', np.uint64)], shape=(self.height, self.width))
thr.valid.fill(False)
thr.low.fill(frame_start)
thr.high.fill(0)
def show_em_frame(frame_data):
"""Prepare and show a single frame of em data to be shown"""
for datum in np.nditer(frame_data):
ts_val = datum['ts'].item(0)
thr_data = thr[datum['y'].item(0), datum['x'].item(0)]
if datum['p'].item(0) == 0:
thr_data.valid = 1
thr_data.low = ts_val
elif thr_data.valid == 1:
thr_data.valid = 0
thr_data.high = ts_val - thr_data.low
img = 255 * (1 - (thr.high - min_val) / (val_range))
#thr_h = cv2.adaptiveThreshold(thr_h, 255,
#cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 3, 0)
img = np.piecewise(img, [img <= 0, (img > 0) & (img < 255), img >= 255], [0, lambda x: x, 255])
img = img.astype('uint8')
cv2.imshow('img', img)
cv2.waitKey(1)
while frame_start < t_max:
#with timer.Timer() as em_playback_timer:
frame_data = self.data[(self.data.ts >= frame_start) & (self.data.ts < frame_end)]
show_em_frame(frame_data)
frame_start = frame_end + 1
frame_end += frame_length + 1
#print 'showing em frame took %s seconds' %em_playback_timer.secs
cv2.destroyAllWindows()
return
评论列表
文章目录