我试图从一个连接到Windows 10机器的ORBEC阿斯特拉专业相机接收深度图像。我已经安装了Therfor
opencv-python 4.0.0.21
和
primesense 2.2.0.30.post5
这似乎是最新的稳定的python包。
这是我正在试验的代码片段:
import numpy as np
import cv2
from primesense import openni2
from primesense import _openni2 as c_api
openni2.initialize("./OpenNI-Windows-x64-2.3/Redist")
if openni2.is_initialized():
print('openni2 ready')
else:
print('openni2 not ready')
dev = openni2.Device.open_any()
depth_stream = dev.create_depth_stream()
depth_stream.set_video_mode(c_api.OniVideoMode(pixelFormat = c_api.OniPixelFormat.ONI_PIXEL_FORMAT_DEPTH_100_UM, resolutionX = 640, resolutionY = 480, fps = 30))
depth_stream.start()
while(True):
frame = depth_stream.read_frame()
frame_data = frame.get_buffer_as_uint16()
img = np.frombuffer(frame_data, dtype=np.uint16)
img.shape = (1, 480, 640)
img = np.concatenate((img, img, img), axis=0)
img = np.swapaxes(img, 0, 2)
img = np.swapaxes(img, 0, 1)
cv2.imshow("image", img)
cv2.waitKey(34)
depth_stream.stop()
openni2.unload()
然而当
cv2.imshow()
我接到的电话是:
cv2.错误:opencv(4.0.0)
C:\projects\opencv python\opencv\modules\highgui\src\window-w32.cpp:1230:
错误:(- 215:断言失败)dST.DATA=(UCHAR *)dSTY-PTR函数
'cvshowimage'
我不知道如何将openni框架转换为opencv mat数据结构,以及为什么
CV2.imSub()
拒绝显示图像。OpenNi似乎正确地初始化了,至少它打印出来了
openni2 ready
…我在这里做错什么了?
编辑
这似乎是我在这里报告的一个错误
https://github.com/skvark/opencv-python/issues/167
解决方案(种类)
将opencv版本降级到最新的3.x版本使其工作!
pip install --upgrade opencv-python==3.4.5.20