7 import pyrealsense2
as rs, os, time, tempfile, sys
8 from rspy
import devices, log, test
11 color_format = depth_format =
None 12 color_fps = depth_fps =
None 13 color_width = depth_width =
None 14 color_height = depth_height =
None 15 previous_depth_frame_number = -1
16 previous_color_frame_number = -1
19 dev = test.find_first_device_or_exit()
20 depth_sensor = dev.first_depth_sensor()
21 color_sensor = dev.first_color_sensor()
25 for p
in color_sensor.profiles:
26 if p.is_default()
and p.stream_type() == rs.stream.color:
27 color_format = p.format()
29 color_width = p.as_video_stream_profile().width()
30 color_height = p.as_video_stream_profile().height()
32 for p
in color_sensor.profiles:
33 if p.stream_type() == rs.stream.color
and p.format() == color_format
and \
34 p.fps() < color_fps
and\
35 p.as_video_stream_profile().width() == color_width
and \
36 p.as_video_stream_profile().height() == color_height:
38 for p
in depth_sensor.profiles:
39 if p.is_default()
and p.stream_type() == rs.stream.depth:
40 depth_format = p.format()
42 depth_width = p.as_video_stream_profile().width()
43 depth_height = p.as_video_stream_profile().height()
51 global previous_color_frame_number
53 test.check_frame_drops( frame, previous_color_frame_number )
54 previous_color_frame_number = frame.get_frame_number()
57 global previous_depth_frame_number
59 test.check_frame_drops( frame, previous_depth_frame_number )
60 previous_depth_frame_number = frame.get_frame_number()
64 You can't use the same profile twice, but we need the same profile several times. So this function resets the 65 profiles with the given parameters to allow quick profile creation 67 global cp, dp, color_sensor, depth_sensor
68 global color_format, color_fps, color_width, color_height
69 global depth_format, depth_fps, depth_width, depth_height
70 cp =
next( p
for p
in color_sensor.profiles
if p.fps() == color_fps
71 and p.stream_type() == rs.stream.color
72 and p.format() == color_format
73 and p.as_video_stream_profile().width() == color_width
74 and p.as_video_stream_profile().height() == color_height )
76 dp =
next( p
for p
in depth_sensor.profiles
if p.fps() == depth_fps
77 and p.stream_type() == rs.stream.depth
78 and p.format() == p.format() == depth_format
79 and p.as_video_stream_profile().width() == depth_width
80 and p.as_video_stream_profile().height() == depth_height )
86 except RuntimeError
as rte:
88 if str( rte ) !=
"stop() cannot be called before start()":
89 test.unexpected_exception()
91 test.unexpected_exception()
96 if sensor.get_active_streams():
99 except RuntimeError
as rte:
100 if str( rte ) !=
"stop_streaming() failed. UVC device is not streaming!":
101 test.unexpected_exception()
103 test.unexpected_exception()
109 temp_dir = tempfile.TemporaryDirectory( prefix=
'recordings_' )
110 file_name = temp_dir.name + os.sep +
'rec.bag' 113 test.start(
"Trying to record and playback using pipeline interface")
115 cfg = pipeline =
None 118 pipeline = rs.pipeline()
120 cfg.enable_record_to_file( file_name )
121 pipeline.start( cfg )
125 pipeline = rs.pipeline()
127 cfg.enable_device_from_file(file_name)
130 pipeline.wait_for_frames()
132 test.unexpected_exception()
140 test.start(
"Trying to record and playback using sensor interface")
142 recorder = depth_sensor = color_sensor = playback =
None 144 dev = test.find_first_device_or_exit()
145 recorder = rs.recorder( file_name, dev )
146 depth_sensor = dev.first_depth_sensor()
147 color_sensor = dev.first_color_sensor()
151 depth_sensor.open( dp )
152 depth_sensor.start(
lambda f:
None )
153 color_sensor.open( cp )
154 color_sensor.start(
lambda f:
None )
166 playback = ctx.load_device( file_name )
168 depth_sensor = playback.first_depth_sensor()
169 color_sensor = playback.first_color_sensor()
173 depth_sensor.open( dp )
174 depth_sensor.start( depth_frame_call_back )
175 color_sensor.open( cp )
176 color_sensor.start( color_frame_call_back )
182 test.check( got_frames )
184 test.unexpected_exception()
200 test.start(
"Trying to record and playback using sensor interface with syncer")
204 dev = test.find_first_device_or_exit()
205 recorder = rs.recorder( file_name, dev )
206 depth_sensor = dev.first_depth_sensor()
207 color_sensor = dev.first_color_sensor()
211 depth_sensor.open( dp )
212 depth_sensor.start( sync )
213 color_sensor.open( cp )
214 color_sensor.start( sync )
226 playback = ctx.load_device( file_name )
228 depth_sensor = playback.first_depth_sensor()
229 color_sensor = playback.first_color_sensor()
233 depth_sensor.open( dp )
234 depth_sensor.start( sync )
235 color_sensor.open( cp )
236 color_sensor.start( sync )
239 sync.wait_for_frames()
241 test.unexpected_exception()
257 test.print_results_and_exit()
def depth_frame_call_back(frame)
virtual frame finish(frame f)
void next(auto_any_t cur, type2type< T, C > *)
def stop_pipeline(pipeline)
def color_frame_call_back(frame)