资源简介
kinect获取彩色数据并用图片形式进行保存
代码片段和文件信息
#include“opencv2\opencv.hpp“
#include
#include//Kinect Header files
#pragma comment(lib“kinect20.lib“)
using namespace cv;
//Safe release for interfaces
template
inline void SafeRelease(Interface *& pInterfaceToRelease)
{
if (pInterfaceToRelease !=NULL)
{
pInterfaceToRelease->Release();
pInterfaceToRelease=NULL;
}
}
class Kinect
{
public:
static const int cColorWidth=1920;
static const int cColorHeight=1080;
int i;
Kinect();
~Kinect();
HRESULT InitKinect();//初始化Kinect
void Update();//更新数据
void ProcessColor(RGBQUAD* pBufferint nWidthint nHeight);//处理得到的数据
private:
IKinectSensor* m_pKinectSensor;//Current Kinect
IColorframeReader* m_pColorframeReader;//Color reader
RGBQUAD* m_pColorRGBX;
};
Kinect::Kinect()
{
i = 0;
m_pKinectSensor=NULL;
m_pColorframeReader=NULL;
m_pColorRGBX=new RGBQUAD[cColorWidth * cColorHeight];//create heap storage for colorin
} // pixel data in RGBX format
Kinect::~Kinect()
{
if (m_pColorRGBX)
{
delete [] m_pColorRGBX;
m_pColorRGBX=NULL;
}
SafeRelease(m_pColorframeReader);//done with color frame reader
if (m_pKinectSensor)
{
m_pKinectSensor->Close();//close the Kinect Sensor
}
SafeRelease(m_pKinectSensor);
}
HRESULT Kinect::InitKinect()
{
HRESULT hr;
hr=GetDefaultKinectSensor(&m_pKinectSensor);
if (FAILED(hr))
{
return hr;
}
if (m_pKinectSensor)
{
//Initialize the Kinect and get the color reader
IColorframeSource* pColorframeSource=NULL;
hr=m_pKinectSensor->Open();
if (SUCCEEDED(hr))
{
hr=m_pKinectSensor->get_ColorframeSource(&pColorframeSource);
}
if (SUCCEEDED(hr))
{
hr=pColorframeSource->OpenReader(&m_pColorframeReader);
}
SafeRelease(pColorframeSource);
}
if (!m_pKinectSensor||FAILED(hr))
{
printf(“No ready Kinect found!\n“);
return E_FAIL;
}
return hr;
}
void Kinect::Update()
{
if (!m_pColorframeReader)
{
return;
}
IColorframe* pColorframe=NULL;
HRESULT hr=m_pColorframeReader->AcquireLatestframe(&pColorframe);
if (SUCCEEDED(hr))
{
iframeDescription* pframeDescription=NULL;
int nWidth=0;
int nHeight=0;
ColorImageFormat imageFormat=ColorImageFormat_None;
UINT nBufferSize=0;
RGBQUAD* pBuffer=NULL;
if (SUCCEEDED(hr))
{
hr=pColorframe->get_frameDescription(&pframeDescription);
}
if (SUCCEEDED(hr))
{
hr=pframeDescription->get_Width(&nWidth);
}
if (SUCCEEDED(hr))
{
hr=pframeDescription->get_Height(&nHeight);
}
if (SUCCEEDED(hr))
{
hr=pColorframe->get_RawColorImageFormat(&imageFormat);
}
if (SUCCEEDED(hr))
{
if (imageFormat==ColorImageFormat_Bgra)
{
hr=pColorframe->AccessRawUnderlyingBuffer(&nBufferSizereinterpret_cast(&pBuffer));
}
else if (m_pColorRGBX)
{
pBuffer=m_pColorRGBX;
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 4077 2015-12-11 10:30 kinect获取彩色数据并用图片形式进行保存\m.cpp
文件 401 2015-12-11 10:47 kinect获取彩色数据并用图片形式进行保存\readMe.txt
目录 0 2015-12-11 10:36 kinect获取彩色数据并用图片形式进行保存
----------- --------- ---------- ----- ----
4478 3
- 上一篇:高数据率水声通信研究进展
- 下一篇:数字电子技术康华光第五版答案
相关资源
- KinectV2结合Processing调试驱动安装文档
- Kinect控制ppt播放.rar
- 修改后的KinectWrapper
- KinectSDK2.0面部获取
- Kinect2.0入门教程(含unity结合)
- Kinect v2 Examples with MS-SDK 2017年6月最新
- Kinect介绍以及与unity结合使用
- Kinect骨骼关节火柴人程序
- Unity Kinect 2.13package
- Kinect2+Opencv显示骨架
- KinectSDK2.0基本Fusion
- 解觉opencv中videocapture不能打开kinect的
- kinect 骨骼位置信息输出
- 基于Kinect和opencv的人脸识别
- KinectSDK2.0面部模型3D
评论
共有 条评论