从uint8到NPY\u UINT16的PyArray\u simplenewfdata。适用于linux,但不适用于windows

2024-06-02 06:00:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用kinect 4 azure sdk和k4a python包装器。 深度的数据类型是uint16。它可以在Linux上工作,但不能在Windows上工作。 在Windows上,生成的图像似乎有锯齿。两个像素中有一个是黑色的。你知道吗

是什么使这些代码在linux和windows上的行为不同?你知道吗

这是包装器中的相关代码:

    uint8_t* buffer = k4a_image_get_buffer(depth_image);
    npy_intp dims[2];
    dims[0] = k4a_image_get_height_pixels(depth_image);
    dims[1] = k4a_image_get_width_pixels(depth_image);
    PyArrayObject* np_depth_image = (PyArrayObject*) 
    PyArray_SimpleNewFromData(2, (npy_intp*) dims, NPY_UINT16, buffer);
    return PyArray_Return(np_depth_image);

https://github.com/etiennedub/pyk4a/blob/master/pyk4a/pyk4a.cpp#L161

我试着改变第一行,就像我们在kinect 4 azure sdk中看到的那样

    uint16_t* buffer = (uint16_t*)(void*) k4a_image_get_buffer(depth_image);

https://github.com/microsoft/Azure-Kinect-Sensor-SDK/blob/82b850ba3c6c5fcebb3e74679896546029379dc5/examples/undistort/main.cpp#L237

这可能可以通过位转移或类似的方法来解决,但我更愿意理解为什么windows上的行为是不同的。你知道吗

有什么想法吗?你知道吗


Tags: 代码imagegetwindowsbuffersdkazuredepth