当前位置:网站首页>kinect dk 获取CV::Mat格式的彩色RGB图像(openpose中使用)
kinect dk 获取CV::Mat格式的彩色RGB图像(openpose中使用)
2022-07-02 06:34:00 【懵懂的梦花火】
本篇博客解决的主要问,获取Kinect dk中彩色图,并将彩色图放入openpose中,得到手部骨骼点。然后从kinect dk的深度图中获取每个骨骼点对应到的深度值,从而得到三维骨骼点。如下是其中遇到的问题,和对应的解决方案:
问题1:k4a::image转CV::Mat
使用cv::Mat的有参构造函数进行转化
k4a::capture capture;
cv::Mat m_colorMat;
if (m_device.get_capture(&capture)) {
k4a::image m_colorImage = capture.get_color_image();
cv_rgbImage_with_alpha = cv::Mat(m_colorImage.get_height_pixels(), m_colorMat.get_width_pixels(), CV_8UC4,
(void *)m_colorImage.get_buffer(), cv::Mat::AUTO_STEP);
cv::imshow("color", m_colorMat);
}
问题2:CV::Mat中的RGBA转RGB
step[0]是矩阵中一行元素的字节数
step[1]是矩阵中一个元素的字节数
Openpose中想要的格式是RGB(默认相机获取的图片是可以正常识别的,参考其格式)
直接获取到的是RGBA
操作:转换Mat的图像类型
cv::cvtColor(m_colorMat, m_colorMat, cv::COLOR_BGRA2BGR); // 转换
问题3:图片输入到openpose中无法正常检测
分析原因Mat.data中的数据格式有问题
k4a::image中的数据存储用的是uint8_t,opencv里面用的是uchar,使用cv::imshow也可正常显示(问题1中的代码将k4a::image转化为cv::Mat后)
openpose的数据数据cvInputData,要求uchar format
思路:先将数据有uint_t转为uchar,再将k4a::image转化为cv::Mat
// 数据转化
std::vector<uchar> pos; // 点
int width = m_colorImage.get_width_pixels();
int height = m_colorImage.get_height_pixels();
pos.resize(width * height * 4);
auto depth = m_colorImage.get_buffer();
memcpy(pos.data(), depth, width * height * sizeof(uchar) * 4);
// 得到Mat
m_colorMat= cv::Mat(m_colorImage.get_height_pixels(), m_colorImage.get_width_pixels(), CV_8UC4,
(void *)pos.data(), cv::Mat::AUTO_STEP); // m_colorImage.get_buffer()
// RGBA转RGB
cv::cvtColor(m_colorMat, m_colorMat, cv::COLOR_BGRA2BGR);
std::move(pos);
结果
边栏推荐
- hystrix 实现请求合并
- Machine learning practice: is Mermaid a love movie or an action movie? KNN announces the answer
- Programmers with ten years of development experience tell you, what core competitiveness do you lack?
- idea查看字节码配置
- A detailed explanation takes you to reproduce the statistical learning method again -- Chapter 2, perceptron model
- Attributes of classfile
- 自定义Redis连接池
- Matplotlib剑客行——没有工具用代码也能画图的造型师
- Taking the upgrade of ByteDance internal data catalog architecture as an example, talk about the performance optimization of business system
- 西瓜书--第六章.支持向量机(SVM)
猜你喜欢
概念到方法,绝了《统计学习方法》——第三章、k近邻法
西瓜书--第六章.支持向量机(SVM)
[staff] the lines and spaces of the staff (the nth line and the nth space in the staff | the plus N line and the plus N space on the staff | the plus N line and the plus N space below the staff | the
Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedd
Supplier selection and prequalification of Oracle project management system
Solutions to Chinese garbled code in CMD window
From concept to method, the statistical learning method -- Chapter 3, k-nearest neighbor method
洞见云原生|微服务及微服务架构浅析
hystrix 实现请求合并
Typeerror: X () got multiple values for argument 'y‘
随机推荐
Oracle delete tablespace and user
[go practical basis] how to bind and use URL parameters in gin
Matplotlib swordsman line - first acquaintance with Matplotlib
别找了,Chrome浏览器必装插件都在这了
概念到方法,绝了《统计学习方法》——第三章、k近邻法
Redis installation and deployment (windows/linux)
[go practical basis] how to verify request parameters in gin
Matplotlib swordsman - a stylist who can draw without tools and code
Talk about the secret of high performance of message queue -- zero copy technology
Jingdong senior engineer has developed for ten years and compiled "core technology of 100 million traffic website architecture"
Difference between redis serialization genericjackson2jsonredisserializer and jackson2jsonredisserializer
告别996,IDEA中必装插件有哪些?
Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedd
CKEditor 4.10.1 上传图片提示“不正确的服务器响应” 问题解决
微服务实战|熔断器Hystrix初体验
Alibaba /热门json解析开源项目 fastjson2
Number structure (C language -- code with comments) -- Chapter 2, linear table (updated version)
Don't look for it. All the necessary plug-ins for Chrome browser are here
Typora安装包分享
Discussion on improving development quality and reducing test bug rate