8 import pyrealsense2
as rs
13 pipeline = rs.pipeline()
17 pipeline_wrapper = rs.pipeline_wrapper(pipeline)
18 pipeline_profile = config.resolve(pipeline_wrapper)
19 device = pipeline_profile.get_device()
20 device_product_line =
str(device.get_info(rs.camera_info.product_line))
22 config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30)
24 if device_product_line ==
'L500':
25 config.enable_stream(rs.stream.color, 960, 540, rs.format.bgr8, 30)
27 config.enable_stream(rs.stream.color, 640, 480, rs.format.bgr8, 30)
30 pipeline.start(config)
36 frames = pipeline.wait_for_frames()
37 depth_frame = frames.get_depth_frame()
38 color_frame = frames.get_color_frame()
39 if not depth_frame
or not color_frame:
43 depth_image = np.asanyarray(depth_frame.get_data())
44 color_image = np.asanyarray(color_frame.get_data())
47 depth_colormap = cv2.applyColorMap(cv2.convertScaleAbs(depth_image, alpha=0.03), cv2.COLORMAP_JET)
49 depth_colormap_dim = depth_colormap.shape
50 color_colormap_dim = color_image.shape
53 if depth_colormap_dim != color_colormap_dim:
54 resized_color_image = cv2.resize(color_image, dsize=(depth_colormap_dim[1], depth_colormap_dim[0]), interpolation=cv2.INTER_AREA)
55 images = np.hstack((resized_color_image, depth_colormap))
57 images = np.hstack((color_image, depth_colormap))
60 cv2.namedWindow(
'RealSense', cv2.WINDOW_AUTOSIZE)
61 cv2.imshow(
'RealSense', images)