21
21
# run perform_fps_test(sensor_profiles_array, [mode])
22
22
ALL_PERMUTATIONS = 1
23
23
ALL_PAIRS = 2
24
- ALL_SENSORS = 3
24
+ ALL_STREAMS = 3
25
25
26
26
# global variable used to count on all the sensors simultaneously
27
27
count_frames = False
@@ -46,18 +46,12 @@ def check_fps_pair(measured_fps, expected_fps):
46
46
47
47
def get_expected_fps (sensor_profiles_dict ):
48
48
"""
49
- For every sensor, find the expected fps according to its profiles
50
- Return a dictionary between the sensor and its expected fps
49
+ Returns a dictionary between each profile and its expected fps
51
50
"""
52
51
expected_fps_dict = {}
53
- # log.d(sensor_profiles_dict)
54
- for key in sensor_profiles_dict :
55
- avg = 0
56
- for profile in sensor_profiles_dict [key ]:
57
- avg += profile .fps ()
58
-
59
- avg /= len (sensor_profiles_dict [key ])
60
- expected_fps_dict [key ] = avg
52
+ for sensor , profiles in sensor_profiles_dict .items ():
53
+ for profile in profiles :
54
+ expected_fps_dict [profile .stream_name ()] = profile .fps ()
61
55
return expected_fps_dict
62
56
63
57
@@ -69,7 +63,7 @@ def should_test(mode, permutation):
69
63
If the mode is ALL_PAIRS return true only if there are exactly two streams to be tested
70
64
"""
71
65
return ((mode == ALL_PERMUTATIONS ) or
72
- (mode == ALL_SENSORS and all (v == 1 for v in permutation )) or
66
+ (mode == ALL_STREAMS and all (v == 1 for v in permutation )) or
73
67
(mode == ALL_PAIRS and permutation .count (1 ) == 2 ))
74
68
75
69
@@ -108,9 +102,9 @@ def get_time_est_string(num_profiles, modes):
108
102
# test_time = math.comb(num_profiles, 2) * time_per_test
109
103
test_time = choose (num_profiles , 2 ) * time_per_test
110
104
details_str += f"{ choose (num_profiles ,2 )} tests for all pairs"
111
- elif mode == ALL_SENSORS :
105
+ elif mode == ALL_STREAMS :
112
106
test_time = time_per_test
113
- details_str += f"1 test for all sensors on"
107
+ details_str += f"1 test for all streams on"
114
108
115
109
details_str += " + "
116
110
total_time += test_time
@@ -139,55 +133,56 @@ def get_tested_profiles_string(sensor_profiles_dict):
139
133
#############################################
140
134
def check_fps_dict (measured_fps , expected_fps ):
141
135
all_fps_ok = True
142
- for key in expected_fps :
143
- res = check_fps_pair (measured_fps [key ], expected_fps [key ])
136
+ for profile_name in expected_fps :
137
+ res = check_fps_pair (measured_fps [profile_name ], expected_fps [profile_name ])
144
138
if not res :
145
139
all_fps_ok = False
146
- log .d (f"Expected { expected_fps [key ]} fps, received { measured_fps [key ]} fps in sensor { key .name } "
140
+ log .d (f"Expected { expected_fps [profile_name ]} fps, received { measured_fps [profile_name ]} fps in profile"
141
+ f" { profile_name } "
147
142
f" { '(Pass)' if res else '(Fail)' } " )
148
143
return all_fps_ok
149
144
150
145
151
- def generate_functions (sensor_profiles_dict ):
146
+ def generate_functions (sensor_profiles_dict , profile_name_fps_dict , profile_name_lock_dict ):
152
147
"""
153
148
Creates callable functions for each sensor to be triggered when a new frame arrives
154
149
Used to count frames received for measuring fps
155
150
"""
156
- locks = {}
157
151
sensor_function_dict = {}
158
152
for sensor_key in sensor_profiles_dict :
159
- new_lock = threading .Lock ()
160
- locks [sensor_key ] = new_lock
161
-
162
- def on_frame_received (frame , key = sensor_key ):
153
+ def on_frame_received (frame ): # variables declared on generate_functions should not be used here
163
154
global count_frames
164
155
if count_frames :
165
- with locks [key ]:
166
- sensor_profiles_dict [key ] += 1
156
+ profile_name = frame .profile .stream_name ()
157
+ with profile_name_lock_dict [profile_name ]: # lock and count frame
158
+ profile_name_fps_dict [profile_name ] += 1
167
159
168
160
sensor_function_dict [sensor_key ] = on_frame_received
169
161
return sensor_function_dict
170
162
171
163
172
164
def measure_fps (sensor_profiles_dict ):
173
165
"""
174
- Given a dictionary of sensors and profiles to test, activate all sensors on the given profiles
166
+ Given a dictionary of sensors and profiles to test, activate all streams on the given profiles
175
167
and measure fps
176
- Return a dictionary of sensors and the fps measured for them
168
+ Return a dictionary of profiles and the fps measured for them
177
169
"""
178
170
global TIME_FOR_STEADY_STATE
179
171
global TIME_TO_COUNT_FRAMES
180
172
181
173
global count_frames
182
174
count_frames = False
183
175
184
- # initialize fps dict
185
- sensor_fps_dict = {}
186
- for key in sensor_profiles_dict :
187
- sensor_fps_dict [key ] = 0
176
+ # initialize fps and locks dict
177
+ profile_name_fps_dict = {}
178
+ profile_name_lock_dict = {}
179
+ for sensor , profiles in sensor_profiles_dict .items ():
180
+ for profile in profiles :
181
+ profile_name_fps_dict [profile .stream_name ()] = 0
182
+ profile_name_lock_dict [profile .stream_name ()] = threading .Lock ()
188
183
189
184
# generate sensor-callable dictionary
190
- funcs_dict = generate_functions (sensor_fps_dict )
185
+ funcs_dict = generate_functions (sensor_profiles_dict , profile_name_fps_dict , profile_name_lock_dict )
191
186
192
187
for sensor , profiles in sensor_profiles_dict .items ():
193
188
sensor .open (profiles )
@@ -200,27 +195,23 @@ def measure_fps(sensor_profiles_dict):
200
195
count_frames = False # Stop counting
201
196
202
197
for sensor , profiles in sensor_profiles_dict .items ():
203
- sensor_fps_dict [sensor ] /= len (profiles ) # number of profiles on the sensor
204
- sensor_fps_dict [sensor ] /= TIME_TO_COUNT_FRAMES
205
- # now for each sensor we have the average fps received
198
+ for profile in profiles :
199
+ profile_name_fps_dict [profile .stream_name ()] /= TIME_TO_COUNT_FRAMES
206
200
207
201
sensor .stop ()
208
202
sensor .close ()
209
203
210
- return sensor_fps_dict
204
+ return profile_name_fps_dict
211
205
212
206
213
- def get_test_details_str (sensor_profile_dict , expected_fps_dict ):
207
+ def get_test_details_str (sensor_profile_dict ):
214
208
s = ""
215
- for sensor_key in sensor_profile_dict :
216
- if len (sensor_profile_dict [sensor_key ]) > 1 :
217
- s += f"Expected average fps for { sensor_key .name } is { expected_fps_dict [sensor_key ]} :\n "
218
- for profile in sensor_profile_dict [sensor_key ]:
219
- s += f"Profile { profile .stream_name ()} expects { profile .fps ()} fps on { get_resolution (profile )} \n "
220
- else :
221
- s += (f"Expected fps for sensor { sensor_key .name } on profile "
222
- f"{ sensor_profile_dict [sensor_key ][0 ].stream_name ()} is { expected_fps_dict [sensor_key ]} "
223
- f" on { get_resolution (sensor_profile_dict [sensor_key ][0 ])} \n " )
209
+ for sensor , profiles in sensor_profile_dict .items ():
210
+ for profile in profiles :
211
+ s += (f"Expected fps for profile { profile .stream_name ()} on sensor "
212
+ f"{ sensor .name } is { profile .fps ()} "
213
+ f"on { get_resolution (profile )} \n " )
214
+
224
215
s = s .replace ("on (0, 0)" , "" ) # remove no resolution for Motion Module profiles
225
216
return s
226
217
@@ -243,7 +234,7 @@ def perform_fps_test(sensor_profiles_arr, modes):
243
234
partial_dict = get_dict_for_permutation (sensor_profiles_arr , perm )
244
235
test .start ("Testing" , get_tested_profiles_string (partial_dict ))
245
236
expected_fps = get_expected_fps (partial_dict )
246
- log .d (get_test_details_str (partial_dict , expected_fps ))
237
+ log .d (get_test_details_str (partial_dict ))
247
238
fps_dict = measure_fps (partial_dict )
248
239
test .check (check_fps_dict (fps_dict , expected_fps ))
249
240
test .finish ()
@@ -261,6 +252,9 @@ def get_profiles_by_resolution(sensor, resolution, fps=None):
261
252
if fps is None or p .fps () == fps :
262
253
# to avoid having a long run time, we don't choose the same stream more than once
263
254
if p .stream_type () not in stream_types_added :
255
+ if p .stream_type () == rs .stream .infrared :
256
+ if p .stream_index () != 1 :
257
+ continue # on some devices, using Infrared 1 seems to have better fps than IR/IR2
264
258
profiles .append (p )
265
259
stream_types_added .append (p .stream_type ())
266
260
return profiles
@@ -288,7 +282,7 @@ def get_mutual_resolution(sensor):
288
282
if len (profiles ) == len (stream_resolutions_dict ):
289
283
return profiles
290
284
291
- # if none found, try to find a resolution that all profiles have, on any fps (fps will be taken as an average later)
285
+ # if none found, try to find a resolution that all profiles have, on any fps
292
286
for option in possible_combinations :
293
287
profiles = get_profiles_by_resolution (sensor , option [0 ], None )
294
288
if len (profiles ) == len (stream_resolutions_dict ):
@@ -327,7 +321,7 @@ def get_sensors_and_profiles(device):
327
321
if TEST_ALL_COMBINATIONS :
328
322
test_modes = [ALL_PERMUTATIONS ]
329
323
else :
330
- test_modes = [ALL_PAIRS , ALL_SENSORS ]
324
+ test_modes = [ALL_PAIRS , ALL_STREAMS ]
331
325
332
326
perform_fps_test (sensor_profiles_array , test_modes )
333
327
0 commit comments