首页 > 解决方案 > 如何从 opencv 矩阵转换为 k4a_image_t(Azure kinect sdk)

问题描述

我正在尝试将 cv::Mat(CV_16UC1) 转换为 k4a_image_t。我正在尝试使用此函数进行转换:k4a_image_create_from_buffer。

这是链接:https ://microsoft.github.io/Azure-Kinect-Sensor-SDK/master/group___functions_gaf84f2a271bcf6afae429bbccd47071b3.html#gaf84f2a271bcf6afae429bbccd47071b3

到目前为止,我已经创建了创建图像所需的缓冲区数据。

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;

但我不明白参数'buffer_release_cb_context'。

标签: c++opencvazurekinect

解决方案


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.


推荐阅读