当前位置:网站首页>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 implements request consolidation
- 西瓜书--第五章.神经网络
- Talk about the secret of high performance of message queue -- zero copy technology
- MySQL error: unblock with mysqladmin flush hosts
- MySQL multi column in operation
- Redis sorted set data type API and application scenario analysis
- [go practical basis] how to verify request parameters in gin
- 每天睡觉前30分钟阅读_day3_Files
- Insight into cloud native | microservices and microservice architecture
- Supplier selection and prequalification of Oracle project management system
猜你喜欢

Mysql默认事务隔离级别及行锁

Matplotlib swordsman - a stylist who can draw without tools and code

攻防世界-Web进阶区-unserialize3

Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedd
![[staff] time sign and note duration (full note | half note | quarter note | eighth note | sixteenth note | thirty second note)](/img/bf/2b0b9c640bdad2c55293f905a22055.jpg)
[staff] time sign and note duration (full note | half note | quarter note | eighth note | sixteenth note | thirty second note)

Mysql 多列IN操作

Enterprise level SaaS CRM implementation

Break the cocoon | one article explains what is the real cloud primordial

Difference between redis serialization genericjackson2jsonredisserializer and jackson2jsonredisserializer

微服务实战|声明式服务调用OpenFeign实践
随机推荐
Cloudreve自建云盘实践,我说了没人能限制得了我的容量和速度
Chrome user script manager tempermonkey monkey
How to install PHP in CentOS
Complete solution of servlet: inheritance relationship, life cycle, container, request forwarding and redirection, etc
西瓜书--第六章.支持向量机(SVM)
AMQ 4043 solution for errors when using IBM MQ remote connection
What are the differences between TP5 and laravel
View the port of the application published by was
VIM操作命令大全
盘点典型错误之TypeError: X() got multiple values for argument ‘Y‘
MySQL error: unblock with mysqladmin flush hosts
Statistical learning methods - Chapter 5, decision tree model and learning (Part 1)
Jingdong senior engineer has developed for ten years and compiled "core technology of 100 million traffic website architecture"
每天睡觉前30分钟阅读_day3_Files
zk配置中心---Config Toolkit配置与使用
知识点很细(代码有注释)数构(C语言)——第三章、栈和队列
web安全与防御
破茧|一文说透什么是真正的云原生
Ora-12514 problem solving method
JVM指令助记符