最近在用Realsense L515做一个机器人的视觉部分。看到网上相关资料较少,和大家分享一下最近一周所学。
第一个例程比较简单,实现的功能也比较朴实。实现了什么功能呢?就是把从相机得到的深度信息通过控制台以ASCII码的形式流式输出。
部分代码含义如下所示:
# 首先实例化
pipeline = rs.pipeline()
# 然后配置相机参数 默认像素为640*480,30帧
config = rs.config()
config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30)
# 开启数据流
pipeline.start(config)
# 在调用 wait_for_frames(...)之前, get_frame_data(...) 和 get_frame_timestamp(...) 返回稳定值
frames = pipeline.wait_for_frames()
depth = frames.get_depth_frame()
if not depth: continue
# 将图像分成10*20的pixel regions,只保留深度1米内的数据的近似值
coverage = [0]*64
for y in range(480):
for x in range(640):
dist = depth.get_distance(x, y)
if 0 < dist and dist < 1:
coverage[x//10] += 1
if y%20 is 19:
line = ""
for c in coverage:
line += " .:nhBXWW"[c//25] # c的值是0-200
coverage = [0]*64
print(line)
这个例程的代码比较简单,下面上一张结果图~