赞
踩
由于在win系统下配置openni比较麻烦,而在linux下相对容易,因此我便尝试在linux下安装openni并编写python脚本获取astra pro深度相机的深度图像和RGB图像,操作非常方便,步骤如下:
下载地址:https://download.csdn.net/download/weixin_43387635/85565534
arch
查看自己电脑处理器架构,并解压对应的zip文件。sudo chmod +x install.sh
./install.sh
source ~/astrapro/Linux/OpenNI-Linux-x64-2.3/OpenNIDevEnvironment
pip install openni
import sys from openni import openni2 import numpy as np import cv2 # 鼠标双击,打印深度消息 def mousecallback(event,x,y,flags,param): if event==cv2.EVENT_LBUTTONDBLCLK: print(y, x, dpt[y,x]) if __name__ == "__main__": openni2.initialize() # openni初始化 dev = openni2.Device.open_any() # 打开相机设备 print(dev.get_device_info()) depth_stream = dev.create_depth_stream() # 创建深度图数据流 depth_stream.start() # 开始获取数据流 cap = cv2.VideoCapture(1) # 视频抽帧,视频图像化,“1”即astra摄像头 cv2.namedWindow('depth') cv2.setMouseCallback('depth',mousecallback) while True: frame = depth_stream.read_frame() # 获取一帧深度图 dframe_data = np.array(frame.get_buffer_as_triplet()).reshape([480, 640, 2]) dpt1 = np.asarray(dframe_data[:, :, 0], dtype='float32') dpt2 = np.asarray(dframe_data[:, :, 1], dtype='float32') # 获取深度图 dpt2 *= 255 dpt = dpt1 + dpt2 # 展示深度图和RGB图 cv2.imshow('depth', dpt) ret,frame = cap.read() cv2.imshow('color', frame) key = cv2.waitKey(1) if int(key) == ord('q'): break # 最后记得结束,并关闭 depth_stream.stop() dev.close()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。