test-frame-filter.py
Go to the documentation of this file.
1 # License: Apache 2.0. See LICENSE file in root directory.
2 # Copyright(c) 2020 Intel Corporation. All Rights Reserved.
3 
4 #test:device L500*
5 
6 import pyrealsense2 as rs
7 from rspy.timer import Timer
8 from rspy import test
9 import time
10 
11 # The L515 device opens the IR stream with the depth stream even if the user did not ask for it (for improving the depth quality),
12 # The frame-filter role is to make sure only requested frames will get to the user.
13 # This test is divided into 2 tests.
14 # 1. User ask for depth only - make sure he gets depth only frames
15 # 2. User ask for depth + IR - make sure he gets depth + IR frames
16 
17 MAX_TIME_TO_WAIT_FOR_FRAMES = 10 # [sec]
18 NUMBER_OF_FRAMES_BEFORE_CHECK = 50
19 
20 devices = test.find_devices_by_product_line_or_exit(rs.product_line.L500)
21 device = devices[0]
22 depth_sensor = device.first_depth_sensor()
23 
24 dp = next(p for p in depth_sensor.profiles if p.stream_type() == rs.stream.depth
25  and p.fps() == 30)
26 irp = next(p for p in depth_sensor.profiles if p.stream_type() == rs.stream.infrared
27  and p.fps() == 30)
28 
29 n_depth_frame = 0
30 n_ir_frame = 0
31 
32 
33 def frames_counter(frame):
34  if frame.get_profile().stream_type() == rs.stream.depth:
35  global n_depth_frame
36  n_depth_frame += 1
37  elif frame.get_profile().stream_type() == rs.stream.infrared:
38  global n_ir_frame
39  n_ir_frame += 1
40 
41 wait_frames_timer = Timer(MAX_TIME_TO_WAIT_FOR_FRAMES)
42 
43 # Test Part 1
44 test.start("Ask for depth only - make sure only depth frames arrive")
45 
46 depth_sensor.open(dp)
47 depth_sensor.start(frames_counter)
48 wait_frames_timer.start()
49 
50 # we wait for first NUMBER_OF_FRAMES_BEFORE_CHECK frames OR MAX_TIME_TO_WAIT_FOR_FRAMES seconds
51 while (not wait_frames_timer.has_expired()
52  and n_depth_frame + n_ir_frame < NUMBER_OF_FRAMES_BEFORE_CHECK):
53  time.sleep(1)
54 
55 if wait_frames_timer.has_expired():
56  print(str(NUMBER_OF_FRAMES_BEFORE_CHECK) + " frames did not arrived at "+ str(MAX_TIME_TO_WAIT_FOR_FRAMES) + " seconds , abort...")
57  test.fail()
58 else:
59  test.check(n_depth_frame >= NUMBER_OF_FRAMES_BEFORE_CHECK)
60  test.check_equal(n_ir_frame, 0)
61 
62 depth_sensor.stop()
63 depth_sensor.close()
64 
65 time.sleep(1) # Allow time to ensure no more frame callbacks after stopping sensor
66 
68 
69 n_depth_frame = 0
70 n_ir_frame = 0
71 
72 # Test Part 2
73 test.start("Ask for depth+IR - make sure both frames arrive")
74 
75 depth_sensor.open([dp, irp])
76 depth_sensor.start(frames_counter)
77 wait_frames_timer.start()
78 
79 # we wait for first NUMBER_OF_FRAMES_BEFORE_CHECK frames OR MAX_TIME_TO_WAIT_FOR_FRAMES seconds
80 while (not wait_frames_timer.has_expired()
81  and (n_depth_frame == 0 or n_ir_frame == 0)):
82  time.sleep(1)
83 
84 if wait_frames_timer.has_expired():
85  print(str(NUMBER_OF_FRAMES_BEFORE_CHECK) + " frames did not arrived at "+ str(MAX_TIME_TO_WAIT_FOR_FRAMES) + " seconds , abort...")
86  test.fail()
87 else:
88  test.check(n_depth_frame != 0)
89  test.check(n_ir_frame != 0)
90 
91 depth_sensor.stop()
92 depth_sensor.close()
93 
95 
96 test.print_results_and_exit()
def frames_counter(frame)
static std::string print(const transformation &tf)
virtual frame finish(frame f)
void next(auto_any_t cur, type2type< T, C > *)
Definition: foreach.hpp:757


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:50:11