-
Notifications
You must be signed in to change notification settings - Fork 0
/
realsense_depth.py
38 lines (29 loc) · 1.25 KB
/
realsense_depth.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import pyrealsense2 as rs
import numpy as np
import time
class DepthCamera:
def __init__(self):
# Configure depth and color streams
self.pipeline = rs.pipeline()
config = rs.config()
# Get device product line for setting a supporting resolution
pipeline_wrapper = rs.pipeline_wrapper(self.pipeline)
pipeline_profile = config.resolve(pipeline_wrapper)
device = pipeline_profile.get_device()
device_product_line = str(device.get_info(rs.camera_info.product_line))
config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30)
config.enable_stream(rs.stream.color, 640, 480, rs.format.bgr8, 30)
# Start streaming
self.pipeline.start(config)
def get_frame(self):
time.sleep(1)
frames = self.pipeline.wait_for_frames()
depth_frame = frames.get_depth_frame()
color_frame = frames.get_color_frame()
depth_image = np.asanyarray(depth_frame.get_data())
color_image = np.asanyarray(color_frame.get_data())
if not depth_frame or not color_frame:
return False, None, None
return True, depth_image, color_image
def release(self):
self.pipeline.stop()