4

我正在尝试从连接到 Windows 10 机器的 Orbbec Astra Pro 相机接收深度图像。我已经安装了它们opencv-python 4.0.0.21primesense 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.error: OpenCV(4.0.0) C:\projects\opencv-python\opencv\modules\highgui\src\window_w32.cpp:1230: 错误: (-215:Assertion failed) dst.data == (uchar* )dst_ptr 在函数 'cvShowImage'

我不知道如何将 OpenNI 帧转换为 OpenCV mat 数据结构以及为什么cv2.imshow()拒绝显示图像。OpenNI 似乎正确初始化,至少它打印出来openni2 ready......我在这里做错了什么?


编辑

这似乎是我在这里报告的一个错误https://github.com/skvark/opencv-python/issues/167


解决方案(种类)

将 OpenCV 版本降级到最新的 3.x 版本就可以了!

pip install --upgrade opencv-python==3.4.5.20

4

1 回答 1

0

你有没有尝试过:

frame.get_buffer_as_uint32()
img = np.frombuffer(frame_data, dtype=np.uint32)

在 opencv4 中,如果您不使用特定的 dtype,imshow 将无法工作

于 2020-03-30T04:59:23.077 回答