Intel Realsense d435 使用python对深度图进行预处理
本文中主要翻译一下一篇关于深度图预处理过滤器的内容,后面还会有关于距离测量的。
原文中的图像显示,是使用matplotlib.pyplot工具,在本文中,使用opencv来显示深度图》
首先常规操作导入包:
import cv2
import numpy as np
import pyrealsense2 as rs
获取我们所需要的图像,通过摄像头或者本地都可以
pipe = rs.pipeline()
cfg = rs.config()
cfg.enable_stream(rs.stream.depth,640,480,rs.format.z16,30)
cfg.enable_stream(rs.stream.color,640,480,rs.format.bgr8,30)
profile = pipe.start(cfg)
try:
while True:
frame = pipe.wait_for_frames()
depth_frame = frame.get_depth_frame()
print('capture success')
if cv2.waitKey(10)&0xff == ord('q'):
break
finally:
pipe.stop()
获取成功,在终端打印信息
一、深度图像的可视化
使用pyrealsense2库中提供的colorizer来将图像中的深度值转为可以显示的形式:
colorizer = rs.colorizer()
colorizer_depth = np.asanyarray(colorizer.colorize(depth_frame).get_data()