参考文章:Orbbec-Astra相机windows系统下Python配置使用
环境配置:Astra S 、Windows 10、python3.9、pycharm
工程文件夹如下:
箭头指向的两个文件在下载的OpenNI SDK里面的。
打开彩色摄像头代码:
from openni import openni2
import cv2
import numpy as np
if __name__ == "__main__":
openni2.initialize()
dev = openni2.Device.open_any()
print(dev.get_device_info())
color_stream = dev.create_color_stream()
color_stream.start()
cv2.namedWindow('color')
while True:
colorTemplateframe = color_stream.read_frame()
# colorTemplateframe是VideoFrame类型,所以需要转换为np.ndarry类型。
cframe_data = np.array(colorTemplateframe.get_buffer_as_uint8()).reshape([480,640,3])
# 通道转换:RGB转为BGR
cframe = cv2.cvtColor(cframe_data,cv2.COLOR_RGB2BGR)
cv2.imshow("color",cframe)
key = cv2.waitKey(1)
if int(key) == ord('q'):
break
color_stream.stop()
dev.close()
图像如下图所示:
打开RGB摄像头后就可以进行OpenCV的开发了。
祝各位玩得愉快!