Q:

how to convert from opencv matrix to k4a_image_t (Azure kinect sdk)

I am trying to convert cv::Mat(CV_16UC1) to k4a_image_t. I am trying to do the conversion using this function this function: k4a_image_create_from_buffer.
here is the link: https://microsoft.github.io/Azure-Kinect-Sensor-SDK/master/group___functions_gaf84f2a271bcf6afae429bbccd47071b3.html#gaf84f2a271bcf6afae429bbccd47071b3
so far I have created the buffer data needed to create the image.
std::vector<uchar> array;
if (depth_im.isContinuous())
{
    array.assign(depth_im.data, depth_im.data + depth_im.total());
}
else
{
    for (int i = 0; i < depth_im.rows; ++i)
{
    array.insert(array.end(), depth_im.ptr<uint16_t>(i), 
        depth_im.ptr<uint16_t>(i) + depth_im.cols);
}
}

uint8_t* b_data = reinterpret_cast<uint8_t*>(&array[0]);
k4a_image_t new_depth_im = NULL;

But I do not understand the parameter 'buffer_release_cb_context'.

A:

Think of it as a pointer to an object that you need when the buffer_release_cb function is called. If you can write that function and free the memory simply based on buffer pointer being passed in then great, you don't need to pass in anything for buffer_release_cb_context and can use NULL instead. Bug if you need the original cv::Mat object, then you should pass that in for buffer_release_cb_context and know that you will get it back as *context in your buffer_release_cb() call.
We would love feedback on how to make the documentation clearer, so feel free to comment on this if you have suggestions.

