-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnoise_injection.py
196 lines (140 loc) · 6.33 KB
/
noise_injection.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
import numpy as np
import tables
import stl
def create_labelled_data_file(f_name='./data/labelled.h5'):
f = tables.open_file(f_name, mode='w')
f_timestamp = f.create_earray(f.root, 'timestamp', tables.atom.UInt64Atom(), (0,))
f_polarity = f.create_earray(f.root, 'polarity', tables.atom.BoolAtom(), (0,))
f_x = f.create_earray(f.root, 'x', tables.atom.UInt16Atom(), (0,))
f_y = f.create_earray(f.root, 'y', tables.atom.UInt16Atom(), (0,))
f_label = f.create_earray(f.root, 'label', tables.atom.UInt8Atom(), (0,))
f.close()
def projection():
test_name = 'noise'
test_number = 1
#record_seconds = 3
record_seconds = 10
#record_seconds = 100
record_time = record_seconds * 1000000
#vicon_usec_offset = 183000
#vicon_usec_offset = 157000
#vicon_usec_offset = 69000000
vicon_usec_offset = 3030000
#vicon_usec_offset = 0
distinguish_dv_event_polarity = False
dv_camera_matrix = np.load('./calibration/camera_matrix.npy')
dv_distortion_coefficients = np.load('./calibration/camera_distortion_coefficients.npy')
f_labelled_name = f'./data/labelled_{test_name}_{test_number:04}.h5'
f_dv_event_name = f'./data/dv_event_{test_name}_{test_number:04}.h5'
f_dv_frame_name = f'./data/dv_frame_{test_name}_{test_number:04}.h5'
f_vicon_name = f'./data/vicon_{test_name}_{test_number:04}.h5'
f_noise_event_name = f'./data/noise_event_{test_name}_{test_number:04}.h5'
f_event_image_video = f'./data/event_image_video_{test_name}_{test_number:04}.avi'
f_frame_image_video = f'./data/frame_image_video_{test_name}_{test_number:04}.avi'
#################### noise injection #############################
def get_next_dv_event(f_timestamp, f_polarity, f_x, f_y, usec_offset=0):
timestamp = np.uint64(next(f_timestamp) + usec_offset)
polarity = next(f_polarity)
x = next(f_x)
y = next(f_y)
return timestamp, polarity, x, y
def get_next_noise_event(f_timestamp, f_polarity, f_x, f_y, usec_offset=0):
timestamp = np.uint64(next(f_timestamp) + usec_offset)
polarity = next(f_polarity)
x = next(f_x)
y = next(f_y)
return timestamp, polarity, x, y
def create_labelled_data_file(f_name='./data/labelled.h5'):
f = tables.open_file(f_name, mode='w')
f_timestamp = f.create_earray(f.root, 'timestamp', tables.atom.UInt64Atom(), (0,))
f_polarity = f.create_earray(f.root, 'polarity', tables.atom.BoolAtom(), (0,))
f_x = f.create_earray(f.root, 'x', tables.atom.UInt16Atom(), (0,))
f_y = f.create_earray(f.root, 'y', tables.atom.UInt16Atom(), (0,))
f_label = f.create_earray(f.root, 'label', tables.atom.UInt8Atom(), (0,))
f.close()
#open dv events and noise events, write a new file with noise events plus dv events
dv_event = tables.open_file(f_dv_event_name, mode='r')
dv_event_timestamp = dv_event.root.timestamp.iterrows()
dv_event_polarity = dv_event.root.polarity.iterrows()
dv_event_x = dv_event.root.x.iterrows()
dv_event_y = dv_event.root.y.iterrows()
noise_event = tables.open_file('./data/noise_event.h5', mode='r')
noise_event_timestamp = noise_event.root.timestamp.iterrows()
noise_event_polarity = noise_event.root.polarity.iterrows()
noise_event_x = noise_event.root.x.iterrows()
noise_event_y = noise_event.root.y.iterrows()
create_labelled_data_file(f_name='./data/combo_event.h5')
f = tables.open_file('./data/combo_event.h5', mode='a')
f_timestamp = f.root.timestamp
f_x = f.root.x
f_y = f.root.y
f_polarity = f.root.polarity
#n_offset = 1626270537204981
n_offset = 1626268040902733
#n_offset = 0
print('noise:')
n_timestamp = (next(noise_event_timestamp)+ n_offset)
print(n_timestamp)
n_timestamp = (next(noise_event_timestamp)+ n_offset)
print(n_timestamp)
print('dv:')
dv_timestamp = next(dv_event_timestamp)
print(dv_timestamp)
dv_timestamp = next(dv_event_timestamp)
print(dv_timestamp)
n_polarity = next(noise_event_polarity)
#print(n_polarity)
dv_polarity = next(dv_event_polarity)
#print(dv_polarity)
n_x = next(noise_event_x)
#print(n_x)
dv_x = next(dv_event_x)
#print(dv_x)
n_y = next(noise_event_y)
#print(n_y)
dv_y = next(dv_event_y)
#print(dv_y)
#xit(0)
while True:
try:
if n_timestamp <= dv_timestamp:
if n_timestamp == dv_timestamp and n_x == dv_x and n_y == dv_y:
print('same' * 10)
f_timestamp.append([dv_timestamp])
f_polarity.append([dv_polarity])
f_x.append([dv_x])
f_y.append([dv_y])
dv_timestamp = next(dv_event_timestamp)
dv_polarity = next(dv_event_polarity)
dv_x = next(dv_event_x)
dv_y = next(dv_event_y)
else:
f_timestamp.append([n_timestamp])
f_polarity.append([n_polarity])
f_x.append([n_x])
f_y.append([n_y])
#print('noise event appended'*4)
#print(n_timestamp, 'x: ', n_x, 'y: ', n_y, 'p: ', n_polarity)
n_timestamp = (next(noise_event_timestamp) + n_offset)
n_polarity = next(noise_event_polarity)
n_x = next(noise_event_x)
n_y = next(noise_event_y)
else:
f_timestamp.append([dv_timestamp])
print('dv_event_appended')
print(dv_timestamp)
f_polarity.append([dv_polarity])
f_x.append([dv_x])
f_y.append([dv_y])
dv_timestamp = next(dv_event_timestamp)
dv_polarity = next(dv_event_polarity)
dv_x = next(dv_event_x)
dv_y = next(dv_event_y)
except StopIteration:
break
f.close()
dv_event.close()
noise_event.close()
return
if __name__ == '__main__':
projection()