我正在尝试使用OpenCV来处理来自kinect的深度图像。我使用Python和primesense的绑定(https://pypi.org/project/primesense/),但是我在显示从openNI获得的图像时遇到了很多麻烦。我在用
import numpy as np
import cv2
from primesense import openni2
openni2.initialize("./Redist") # can also accept the path of the OpenNI redistribution
dev = openni2.Device.open_any()
depth_stream = dev.create_color_stream()
depth_stream.start()
while(True):
frame = depth_stream.read_frame()
print(type(frame)) #prints <class 'primesense.openni2.VideoFrame'>
frame_data = frame.get_buffer_as_uint8()
print(frame_data) # prints <primesense.openni2.c_ubyte_Array_921600 object at 0x000002B3AF5F8848>
image = np.array(frame_data, dtype=np.uint8)
print(type(image)) #prints <class 'numpy.ndarray'>
print(image) #prints [12 24 3 ... 1 3 12], i guess this is the array that makes the image
cv2.imshow('image', image)
depth_stream.stop()
openni2.unload()
这是我得到的输出,只是一个没有图像的窗口:
根本没有关于如何使用这些绑定的文档,所以我在这里有一个盲点。我以为frame.get_buffer_as_uint8()
给了我一个可以打印的数组,但它只返回primesense.openni2.c_ubyte_Array_921600 object at 0x000002B3AF5F8848
。在
实际上,我查看了绑定的代码,发现了:
^{pr2}$有人用过这个绑定吗?你知道怎么让它们工作吗?提前谢谢你
我找到了解决办法:
您不必使用
image = np.array(frame_data, dtype=np.uint8)
来获取图像,而必须使用frame_data = frame.get_buffer_as_uint16()
。而且,我没有正确设置图像形状。在供将来参考
要使用OpenNI绑定Python从深度摄影机(并非只有Kinect)获取图像,并使用OpenCV处理该图像,下面的代码将完成以下操作:
要使用彩色照相机,可以使用
dev.create_color_stream()
。在相关问题 更多 >
编程相关推荐