-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrs_help002.py
More file actions
70 lines (57 loc) · 1.87 KB
/
rs_help002.py
File metadata and controls
70 lines (57 loc) · 1.87 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
"""
AGVT COMPUTER VISION FUNCTIONS
"""
import pyrealsense2 as rs
import numpy as np
class Realsense435:
def __init__(self):
self.pipe = rs.pipeline()
self.config = rs.config()
self.w = 640
self.h = 480
self.fr = 30
self.buf = 10
self.color = None
self.depth = None
def configure_rs(self):
# save Depth data as z16 (depth data type)
self.config.enable_stream(rs.stream.depth,
self.w,
self.h,
rs.format.z16,
self.fr)
# Save Color data as RGB
self.config.enable_stream(rs.stream.color,
self.w,
self.h,
rs.format.rgb8,
self.fr)
def open_pipeline(self):
self.pipe.start(self.config)
def buffer(self, buf):
for x in range(buf):
self.pipe.wait_for_frames()
def stop_pipe(self):
self.pipe.stop()
def get_frames(self):
"""
Will allign, update and retrieve np frames
:return:
RBG Numpy arrays with frames
Z16 Depth frames
"""
frame_set = self.pipe.wait_for_frames()
# create alignment primitive
align = rs.align(rs.stream.color)
frame_set = align.process(frame_set)
# get frames
color = frame_set.get_color_frame()
depth = frame_set.get_depth_frame()
# convert to np arrays
color = np.asarray(color.get_data())
depth = np.asarray(depth.get_data())
return color, depth
def start_rs(self):
self.configure_rs()
self.open_pipeline()
self.buffer(self.buf)