Skip to content

Commit

Permalink
some arranging
Browse files Browse the repository at this point in the history
  • Loading branch information
AviaAv committed Oct 19, 2023
1 parent 2238f9d commit 9f0324f
Showing 1 changed file with 56 additions and 47 deletions.
103 changes: 56 additions & 47 deletions unit-tests/live/frames/test-fps-permutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def measure_fps(sensorsAndProfilesArr):
return fps


def overKill(profiles):
def test_all_combinations(profiles):
perms = list(itertools.product([0, 1], repeat=len(profiles)))

# Print permutations
Expand All @@ -106,36 +106,65 @@ def overKill(profiles):
print(fps)
print()

def get_sensors_and_profiles(dev):
""""
Returns a list of tuples of (sensor, profile) so that no profile is showing up twice
"""
streams = []
sensor_profile_arr = []
for sensor in dev.query_sensors():
# print(sensor.name)
# print(sorted(sensor.__dir__()))
for profile in sensor.get_stream_profiles():
# print(sorted(profile.__dir__()))
print(profile.stream_type(), profile.format(), profile.fps(), get_resolution(profile),
profile.stream_index())
if ((profile.stream_type() not in streams) and
(get_resolution(profile) == (1280, 720) or get_resolution(profile) == (0, 0))):
# note that in case of sensors with more than one of the same stream type (like ir)
# we don't add both profiles, need to decide if needed both or not
# also note that the resolution probably doesn't matter fps-wise, but if we activate two profiles on the
# same sensor, they must have the same resolution
streams.append(profile.stream_type())
sensor_profile_arr.append((sensor, profile))

# for p in sensor_profile_arr:
# print(p)
# print("\n\n\n\n")
return sensor_profile_arr


def test_all_pairs(sensor_profile_arr):
for i, (sensor, profile) in enumerate(sensor_profile_arr):
# print(i,sensor,profile)
for j in range(i + 1, len(sensor_profile_arr)):
sensor2 = sensor_profile_arr[j][0]
profile2 = sensor_profile_arr[j][1]
print(sensor.name, "/", profile.stream_type(), "+", sensor2.name, "/", profile2.stream_type())
if sensor == sensor2:
fps = measure_fps([(sensor, profile), (sensor2, profile2)])[0]
print(fps, "fps, expected is", profile.fps())
ok1 = check_fps_ok(fps, profile.fps()) # for now
ok2 = True
else:
fps_1, fps_2 = measure_fps(sensor, profile, sensor2, profile2)
ok1 = check_fps_ok(fps_1, profile.fps())
ok2 = check_fps_ok(fps_2, profile2.fps())
print(fps_1, "fps, expected is", profile.fps())
print(fps_2, "fps, expected is", profile2.fps())

print("ok" if ok1 and ok2 else "not ok")


streams = []
sensor_profile_arr = []
dev = test.find_first_device_or_exit()
# print(dev.query_sensors())
for sensor in dev.query_sensors():
# print(sensor.name)
# print(sorted(sensor.__dir__()))
first = True
for profile in sensor.get_stream_profiles():
# print(profile.stream_type(), profile.format(), profile.fps(), get_resolution(profile))
if ((profile.stream_type() not in streams) and
(get_resolution(profile) == (1280, 720) or get_resolution(profile) == (0,0))):

streams.append(profile.stream_type())
sensor_profile_arr.append((sensor, profile))
first = False
# print("\n\n\n\n")
print(streams)
for p in sensor_profile_arr: print(p)
print("\n\n\n\n")
overKill(sensor_profile_arr)
# print(measure_fps(sensor_profile_arr))

while True:
pass
# print(sensor_profile_arr) #there's got to be a better way
# print(measure_fps(dev.query_sensors()[0],sensor_profile_arr[1],dev.query_sensors()[1],sensor_profile_arr[2]))
sensor_profile_arr = get_sensors_and_profiles(dev)

overKill = True

if overKill:
test_all_combinations(sensor_profile_arr)
else:
test_all_pairs(sensor_profile_arr)


# product_line = dev.get_info(rs.camera_info.product_line)
Expand All @@ -144,27 +173,7 @@ def overKill(profiles):
# if ds.supports(rs.option.enable_auto_exposure):
# ds.set_option(rs.option.enable_auto_exposure, 1)

print("\n\n\n\n")

for i,(sensor,profile) in enumerate(sensor_profile_arr):
# print(i,sensor,profile)
for j in range(i+1,len(sensor_profile_arr)):
sensor2 = sensor_profile_arr[j][0]
profile2 = sensor_profile_arr[j][1]
print(sensor.name,"/",profile.stream_type(),"+",sensor2.name,"/",profile2.stream_type())
if (sensor == sensor2):
fps = measure_fps(sensor,profile,sensor2,profile2)[0]/2
print(fps, "fps, expected is", profile.fps())
ok1 = check_fps_ok(fps,profile.fps()) #for now
ok2 = True
else:
fps_1, fps_2 = measure_fps(sensor,profile,sensor2,profile2)
ok1 = check_fps_ok(fps_1,profile.fps())
ok2 = check_fps_ok(fps_2,profile2.fps())
print(fps_1,"fps, expected is",profile.fps())
print(fps_2,"fps, expected is",profile2.fps())

print("ok" if ok1 and ok2 else "not ok")

#####################################################################################################

Expand Down

0 comments on commit 9f0324f

Please sign in to comment.