Azure Kinect 使用正文索引映射裁剪正文
Azure Kinect Crop Out Body Using Body Index Map
我正在使用Azure DK读取MKV文件,我可以在其中提取RGBA和每帧的相应深度图像。此后,我使用身体追踪器使用深度图像定位和跟踪人。目前,我能够生成身体索引图,甚至将其转换为彩色相机空间,如下所示。
k4a::image extract_body_index_map(tracker& object_tracker)
{
k4a::image body_index_map = k4a::image();
k4abt::frame body_frame = object_tracker.pop_result();
if (body_frame != nullptr)
{
uint32_t bodies = body_frame.get_num_bodies();
cout << "Bodies Found: " << bodies << "n";
for (uint32_t index = 0; index < bodies; ++index)
{
k4abt_body_t body = body_frame.get_body(index);
cout << "tPERSON: " << body.id << "n";
body_index_map = body_frame.get_body_index_map();
}
}
else { cerr << "ERROR: Body Pop Out Timeoutnn"; }
return body_index_map;
}
k4a::image convert_body_index_map_to_colour(k4a::image& body_index_map, k4a::image& depth, k4a::image& colour, k4a_transformation_t transformation)
{
k4a_image_t depth_image_in_colour_space = nullptr;
k4a_result_t result = k4a_image_create(K4A_IMAGE_FORMAT_DEPTH16,
colour.get_width_pixels(), colour.get_height_pixels(),
colour.get_width_pixels() * (int)sizeof(uint16_t), &depth_image_in_colour_space);
if (result == K4A_RESULT_FAILED)
{
cerr << "ERROR: Failed to create depth image in colour spacen";
return nullptr;
}
k4a_image_t body_index_in_colour_space = nullptr;
result = k4a_image_create(K4A_IMAGE_FORMAT_CUSTOM8,
colour.get_width_pixels(), colour.get_height_pixels(),
colour.get_width_pixels() * (int)sizeof(uint8_t), &body_index_in_colour_space);
if (result == K4A_RESULT_FAILED)
{
cerr << "ERROR: Failed to create body index map in colour spacen";
return nullptr;
}
result = k4a_transformation_depth_image_to_color_camera_custom(transformation, depth.handle(),
body_index_map.handle(), depth_image_in_colour_space, body_index_in_colour_space,
K4A_TRANSFORMATION_INTERPOLATION_TYPE_NEAREST, K4ABT_BODY_INDEX_MAP_BACKGROUND);
if (result == K4A_RESULT_FAILED)
{
cerr << "ERROR: Failed to transform body index map to colour spacen";
return nullptr;
}
return k4a::image(body_index_in_colour_space);
}
我目前被困在如何:
使用生成的身体索引图裁剪/分割/绘制彩色图像,以提取身体的视觉表示。我几乎希望复制这一点;带有 RGBA 图像的部分
将裁剪后的图像转换为 2D RGBA 图像
任何帮助将不胜感激:)
在搞砸之后,我终于设法解决了这个问题。我切换到OpenCV进行图像处理。
首先,我将body_index_in_colour_space
转换为OpenCVMat
Mat convertToMat(k4a::image kinect_image)
{
uint8_t* pixel_data = kinect_image.get_buffer();
if (pixel_data != nullptr) return Mat(kinect_image.get_height_pixels(), kinect_image.get_width_pixels(), CV_8UC4, (void*)pixel_data, Mat::AUTO_STEP);
return Mat();
}
我也以类似的方式将 kinect BGRA 图像转换为 OpenCV Mat,方法是将标志从CV_8UC1
更改为CV_8UC4
。此后,我只是在彩色图像的顶部绘制了索引图。
Mat drawIndexMapOnColourImage(Mat indexMap, Mat colour)
{
Mat result;
colour.copyTo(result);
//TODO: Not efficient, fix this
for(size_t row = 0; row < indexMap.rows; ++row)
for (size_t col = 0; col < indexMap.cols; ++col)
{
if ((int)indexMap.at<uchar>(row, col) == 255) continue; // ignore background
result.at<Vec4b>(row, col) = 150;
}
return result;
}
相关文章:
- 数组索引的值没有增加
- 芬威克树(BIT).找到具有给定累积频率的最小索引,单位为 O(logN)
- 查找最接近的大于当前数字的数字的索引
- 在C++中调整向量中的索引
- 重载元组索引运算符-C++
- 给定一个向量,如何找到该向量的所有子集和的原始索引
- 为std::string的某个索引赋值
- 并行用于C++17中数组索引范围内的循环
- 跟随整数索引列表的自定义类迭代器
- 如何在for循环中包含两个索引值的测试条件
- D3D11-将混合权重和索引传递到顶点着色器
- 将转换字符键入 int 以用作向量C++的索引
- 在 C++ 中访问数组负索引处的内存不会返回垃圾
- 如何为圆环创建索引
- 在子集化后将包含索引号的列表列表映射到标准索引序列
- 查找字符在两个索引之间出现的次数
- Azure Kinect 使用正文索引映射裁剪正文
- 如何查找哪个类对象位于数组的特定索引上(多态性)
- 数组索引重载错误
- 如何在 std::vector 中找到<bool>哪些索引是真的?