当前位置:网站首页>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);
结果
边栏推荐
- 破茧|一文说透什么是真正的云原生
- View the port of the application published by was
- The channel cannot be viewed when the queue manager is running
- Demand delineation executive summary
- 盘点典型错误之TypeError: X() got multiple values for argument ‘Y‘
- Matplotlib剑客行——容纳百川的艺术家教程
- CKEditor 4.10.1 上传图片提示“不正确的服务器响应” 问题解决
- Operation and application of stack and queue
- 记录下对游戏主机配置的个人理解与心得
- Bold prediction: it will become the core player of 5g
猜你喜欢

idea查看字节码配置

Flink - use the streaming batch API to count the number of words
![[go practical basis] how to install and use gin](/img/0d/3e899bf69abf4e8cb7e6a0afa075a9.png)
[go practical basis] how to install and use gin

Jd.com interviewer asked: what is the difference between using on or where in the left join association table and conditions

西瓜书--第五章.神经网络

数构(C语言)——第四章、矩阵的压缩存储(下)

Redis 序列化 GenericJackson2JsonRedisSerializer和Jackson2JsonRedisSerializer的区别

Complete solution of servlet: inheritance relationship, life cycle, container, request forwarding and redirection, etc

互联网API接口幂等设计

聊聊消息队列高性能的秘密——零拷贝技术
随机推荐
[staff] time mark and note duration (staff time mark | full note rest | half note rest | quarter note rest | eighth note rest | sixteenth note rest | thirty second note rest)
[go practical basis] how to customize and use a middleware in gin
Number structure (C language) -- Chapter 4, compressed storage of matrices (Part 2)
《统计学习方法》——第五章、决策树模型与学习(上)
Flink - use the streaming batch API to count the number of words
ClassFile - Attributes - Code
I've taken it. MySQL table 500W rows, but someone doesn't partition it?
zk配置中心---Config Toolkit配置与使用
Supplier selection and prequalification of Oracle project management system
JDBC回顾
How to install PHP in CentOS
C语言之到底是不是太胖了
Say goodbye to 996. What are the necessary plug-ins in idea?
记录下对游戏主机配置的个人理解与心得
How to choose between efficiency and correctness of these three implementation methods of distributed locks?
概念到方法,绝了《统计学习方法》——第三章、k近邻法
C语言之做木桶
互联网API接口幂等设计
MySQL multi column in operation
Typeerror: X () got multiple values for argument 'y‘