我正在尝试接收一个从Orbbec天文专业相机连接到Windows 10机器的深度图像。我已经安装了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()接到电话时,我收到的是:
C:\projects\opencv-python\opencv\modules\highgui\src\window_w32.cpp:1230:错误:(-215:断言失败)函数'cvShowImage‘中的dst.data == (uchar*)dst_ptr
我不知道如何将OpenNI帧转换为OpenCV mat数据结构,以及为什么cv2.imshow()拒绝显示图像。OpenNI似乎正确地初始化了,至少它打印openni2 ready..。我在这里做错什么了?
编辑
这似乎是我在这里报告的一个bug,https://github.com/skvark/opencv-python/issues/167
解决方案(某种)
将OpenCV版本降级为最新的3.x版本,使其工作起来!
pip install --upgrade opencv-python==3.4.5.20
发布于 2020-03-30 04:59:23
你试过:
frame.get_buffer_as_uint32()
img = np.frombuffer(frame_data, dtype=np.uint32)在opencv4中,由于某种原因,如果不使用特定的dtype,imshow将无法工作。
https://stackoverflow.com/questions/54336237
复制相似问题