当前位置:网站首页>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);
结果
边栏推荐
- MySql报错:unblock with mysqladmin flush-hosts
- MySQL事务
- Oracle modifies tablespace names and data files
- C语言之做木桶
- [go practical basis] gin efficient artifact, how to bind parameters to structures
- 数构(C语言--代码有注释)——第二章、线性表(更新版)
- VIM操作命令大全
- Knife4j 2. Solution to the problem of file control without selection when uploading x version files
- Mathematics in machine learning -- point estimation (I): basic knowledge
- Amq6126 problem solving ideas
猜你喜欢

Microservice practice | fuse hytrix initial experience

Chrome user script manager tempermonkey monkey

From concept to method, the statistical learning method -- Chapter 3, k-nearest neighbor method

Learn combinelatest through a practical example

每天睡前30分钟阅读Day6_Day6_Date_Calendar_LocalDate_TimeStamp_LocalTime

Difference between redis serialization genericjackson2jsonredisserializer and jackson2jsonredisserializer
![[go practical basis] how to customize and use a middleware in gin](/img/fb/c0a4453b5d3fda845c207c0cb928ae.png)
[go practical basis] how to customize and use a middleware in gin

Operation and application of stack and queue

微服务实战|手把手教你开发负载均衡组件

微服务实战|Eureka注册中心及集群搭建
随机推荐
[go practical basis] gin efficient artifact, how to bind parameters to structures
Ora-12514 problem solving method
"Redis source code series" learning and thinking about source code reading
"Interview high frequency question" is 1.5/5 difficult, and the classic "prefix and + dichotomy" application question
Chrome浏览器插件-Fatkun安装和介绍
记录下对游戏主机配置的个人理解与心得
FragmentTabHost实现房贷计算器界面
Insight into cloud native | microservices and microservice architecture
I've taken it. MySQL table 500W rows, but someone doesn't partition it?
Number structure (C language -- code with comments) -- Chapter 2, linear table (updated version)
Data type case of machine learning -- using data to distinguish men and women based on Naive Bayesian method
How to use pyqt5 to make a sensitive word detection tool
Complete solution of servlet: inheritance relationship, life cycle, container, request forwarding and redirection, etc
自定义Redis连接池
Customize redis connection pool
Amq6126 problem solving ideas
Hystrix implements request consolidation
Matplotlib swordsman line - first acquaintance with Matplotlib
盘点典型错误之TypeError: X() got multiple values for argument ‘Y‘
hystrix 实现请求合并