(一)Kinect2.0获取深度图像、RGB图像

本文是基于VS+opencv+Kinect2.0来获取深度图像、RGB图像并显示。
关于具体的工程配置请参考:VS+opencv+Kinect2.0工程配置

Kinect2.0能获取到6种数据源

1、ColorFrameSource 彩色图
2、InfraredFrameSource 红外图(16-bit)
3、DepthFrameSource 深度图(16-bit,单位:mm)
注意:kinect采的深度数据是short型,即每个像素深度占2个字节,但是16位中只有12位是有用的,2^12 = 4096,单位是毫米,所以范围是4m
4、BodyIndexFrameSource 人物索引图(用一个字节代表人体,最多支持6个人体)
5、BodyFrameSource 人体关节图
6、AudioSource 声音

声明:
因为我用C++风格写的代码,Kinect的一些初始化工作都放在构造函数里面了。下面的代码忽略了某些变量的定义,因为博主是做项目用到Kinect2.0,所以项目工程参杂了很多别的方面代码,就不在这里张贴出来了,如有某些代码的变量定义不清楚可在GitHub找找源码,或者留言。
GitHub链接:https://github.com/fyoomm/Kinect/tree/master/kinect

一、深度图像代码

bool AllTheKinect::GetAndShowDepthData()
{
	IDepthFrame* m_pDepthFrame = NULL;//深度信息数据
	while (m_pDepthFrame == NULL)
		hr = m_pDepthFrameReader->AcquireLatestFrame(&m_pDepthFrame);//读取深度数据
	m_pDepthFrame->get_FrameDescription(&depthFrameDescription);
	depthFrameDescription->get_Height(&nDepthHeight);
	depthFrameDescription->get_Width(&nDepthWidth);
	if (SUCCEEDED(hr))
		hr = m_pDepthFrame->CopyFrameDataToArray(nDepthHeight * nDepthWidth, reinterpret_cast<UINT16*>(MatDepth16.data));//把数据读取到Mat里面

	UINT16* depthData = new UINT16[512 * 424];
	hr = m_pDepthFrame->CopyFrameDataToArray(nDepthHeight * nDepthWidth, depthData);
	for (int i = 0; i < nDepthHeight * nDepthWidth; i++) {
		BYTE intensity = static_cast<BYTE>(depthData[i] / 256); //把16位数据归一化成8位数据,显示明显
		reinterpret_cast<BYTE*>(MatDepth8.data)[i] = intensity;
	}
	equalizeHist(MatDepth8, MatDepth8);//平滑处理
	
	imshow("MatDepth8", MatDepth8);//显示8位深度图
	imshow("MatDepth16", MatDepth16);//显示16位深度图
	m_pDepthFrame->Release();
	if (waitKey(1) == VK_ESCAPE)
		return false;
	delete[] depthData;
	return true;
}

效果如下:
没有

二、RGB图像代码

bool AllTheKinect::GetAndShowColorData()
{	
	IColorFrame* m_pColorFrame = NULL;//彩色信息数据
	while (m_pColorFrame == NULL)
		hr = m_pColorFrameReader->AcquireLatestFrame(&m_pColorFrame);//读取彩色数据
	m_pColorFrame->get_FrameDescription(&colorFrameDescription);
	colorFrameDescription->get_Height(&nColorHeight);
	colorFrameDescription->get_Width(&nColorWidth);
	UINT nColorBufferSize = nColorHeight * nColorWidth * 4;
	if (SUCCEEDED(hr))
		hr = m_pColorFrame->CopyConvertedFrameDataToArray(nColorBufferSize, reinterpret_cast<BYTE*>(MatRGB.data), ColorImageFormat::ColorImageFormat_Bgra);
	Mat MatRGB_resize = MatRGB.clone();       // 缩小方便看
	cv::resize(MatRGB_resize, MatRGB_resize, Size(960, 540));
	//putText(MatRGB_resize, "cdn", Point(100, 100), CV_FONT_HERSHEY_COMPLEX, 1, Scalar(0, 0, 0), 5, 8);
	imshow("MatRGB_resize", MatRGB_resize);
	if(waitKey(27) == VK_SPACE)
		imwrite("E:/abc.bmp", MatRGB_resize);//按下空格键保存图片到本地上
	m_pColorFrame->Release();
	return true;	
}

在这里插入图片描述
接下来会介绍人体索引数据、骨骼信息,皮肤阈值分割获取手部信息,svm训练分类等等,有兴趣的可以关注下,嘻嘻嘻🤭。

  • 12
    点赞
  • 79
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
使用Kinect2.0获取点云的过程可以通过以下步骤实现。首先,需要搭建相应的开发环境,包括安装Windows系统和Visual Studio 2019等软件。可以参考\[2\]中提供的源码和项目模板进行环境搭建。接下来,需要使用Kinect2.0相机进行点云图像的捕获。Kinect2.0是一款RGB-D相机,支持普通相机的拍摄和脉冲测量深度信息。可以参考\[1\]中提供的开发源码,了解Kinect2.0的原理和使用方法。在代码中,可以通过调用相应的函数获取相机的深度信息和RGB图像。最后,可以根据需要对获取的点云数据进行处理和拼接,实现三维点云的应用。 #### 引用[.reference_title] - *1* *2* [深度相机Kinect2.0三维点云拼接实验(四)](https://blog.csdn.net/qq_42144047/article/details/123449528)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [Kinect2.0点云数据获取](https://blog.csdn.net/weixin_42651748/article/details/112053649)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值