-
Notifications
You must be signed in to change notification settings - Fork 6
/
play_cd_recording.m
73 lines (66 loc) · 2.19 KB
/
play_cd_recording.m
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
function mov = play_cd_recording(filename, width, height, framerate, acc_time)
% Function to replay of file of CD events
%
% mov = play_cd_recording(filename, width, height, framerate, acc_time)
% filename: path and name of the file to replay
% width, height: resolution of the sensor, defaults to 304 and 240
% framerate: framerate of the generated images in frames per second (defaults to 25)
% acc_time: time to leave the events in the frames in microseconds (defaults to 10000 us)
%
% returns a movie which can be used by the 'movie' command
if ~exist('width', 'var')
width = 304;
end
if ~exist('height', 'var')
height = 240;
end
if ~exist('framerate', 'var')
framerate = 25;
end
if ~exist('acc_time', 'var')
acc_time = 10000;
end
% Load data from the give file
cd_data = load_cd_events(filename);
% Make the pixel index start at 1 for compatibility for Matlab matrices
% indexes (in the files pixels coordinates start at 0)
cd_data.x = cd_data.x + 1;
cd_data.y = cd_data.y + 1;
% Compute internal parameters
frame_time = floor(1/framerate * 1e6); % in microseconds
% Initialize state storage
cd_img = 0.5*ones(height, width);
ts_img = zeros(height, width);
last_frame_ts = 0;
frame_idx = 1;
% Build a figure for movie display and store the first empty frame
figure();
image(cd_img);
colormap gray;
colormap_size = size(colormap, 1);
mov(frame_idx) = getframe(gcf);
frame_idx = frame_idx+1;
% Go through all events in file
for i=1:length(cd_data.ts)
% Get timestamp of current event
cur_ts = cd_data.ts(i);
% Check if images should be generated
while (cur_ts > last_frame_ts + frame_time)
% Update frame by removing old events
last_frame_ts = last_frame_ts + frame_time;
cd_img(ts_img < last_frame_ts - acc_time) = 0.5;
% scale and display image
image(colormap_size*cd_img);
mov(frame_idx) = getframe();
frame_idx = frame_idx+1;
end
% Add event to state
if cd_data.p(i) == 1
% Put a white dot for ON events
cd_img(cd_data.y(i), cd_data.x(i)) = 1;
else
% Put a black dot for OFF events
cd_img(cd_data.y(i), cd_data.x(i)) = 0;
end
ts_img(cd_data.y(i), cd_data.x(i)) = cur_ts;
end