Search code examples
pythonc++numpykinect

PyArray_SimpleNewFromData from uint8_t to NPY_UINT16. Works on linux but not on windows


I am using the kinect 4 azure sdk with the k4a python wrapper. The dtype for the depth is uint16. It works on Linux but not on Windows. On Windows, the resulting image seems aliased. One pixel out of two is black.

What could make this code behave differently on linux vs windows?

This is the relevant code in the wrapper:

    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

I tried changing the first line like we see in the 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

This could probably be solved by bitshifting or similar but I would prefer to understand why the behavior is different on windows.

Any ideas?


Solution

  • Had to update gpu drivers of Surface Pro device. https://github.com/microsoft/Azure-Kinect-Sensor-SDK/issues/840