资源简介
Kinect 2.0 骨骼显示及画出骨骼结合opencv 显示。
代码片段和文件信息
#include “myKinect.h“
#include
/// Initializes the default Kinect sensor
HRESULT CBodyBasics::InitializeDefaultSensor()
{
//用于判断每次读取操作的成功与否
HRESULT hr;
//搜索kinect
hr = GetDefaultKinectSensor(&m_pKinectSensor);
if (FAILED(hr)){
return hr;
}
//找到kinect设备
if (m_pKinectSensor)
{
// Initialize the Kinect and get coordinate mapper and the body reader
IBodyframeSource* pBodyframeSource = NULL;//读取骨架
IDepthframeSource* pDepthframeSource = NULL;//读取深度信息
IBodyIndexframeSource* pBodyIndexframeSource = NULL;//读取背景二值图
//打开kinect
hr = m_pKinectSensor->Open();
//coordinatemapper
if (SUCCEEDED(hr))
{
hr = m_pKinectSensor->get_CoordinateMapper(&m_pCoordinateMapper);
}
//bodyframe
if (SUCCEEDED(hr))
{
hr = m_pKinectSensor->get_BodyframeSource(&pBodyframeSource);
}
if (SUCCEEDED(hr))
{
hr = pBodyframeSource->OpenReader(&m_pBodyframeReader);
}
//depth frame
if (SUCCEEDED(hr)){
hr = m_pKinectSensor->get_DepthframeSource(&pDepthframeSource);
}
if (SUCCEEDED(hr)){
hr = pDepthframeSource->OpenReader(&m_pDepthframeReader);
}
//body index frame
if (SUCCEEDED(hr)){
hr = m_pKinectSensor->get_BodyIndexframeSource(&pBodyIndexframeSource);
}
if (SUCCEEDED(hr)){
hr = pBodyIndexframeSource->OpenReader(&m_pBodyIndexframeReader);
}
SafeRelease(pBodyframeSource);
SafeRelease(pDepthframeSource);
SafeRelease(pBodyIndexframeSource);
}
if (!m_pKinectSensor || FAILED(hr))
{
std::cout << “Kinect initialization failed!“ << std::endl;
return E_FAIL;
}
//skeletonImg用于画骨架、背景二值图的MAT
skeletonImg.create(cDepthHeight cDepthWidth CV_8UC3);
skeletonImg.setTo(0);
//depthImg用于画深度信息的MAT
depthImg.create(cDepthHeight cDepthWidth CV_8UC1);
depthImg.setTo(0);
return hr;
}
/// Main processing function
void CBodyBasics::Update()
{
//每次先清空skeletonImg
skeletonImg.setTo(0);
//如果丢失了kinect,则不继续操作
if (!m_pBodyframeReader)
{
return;
}
IBodyframe* pBodyframe = NULL;//骨架信息
IDepthframe* pDepthframe = NULL;//深度信息
IBodyIndexframe* pBodyIndexframe = NULL;//背景二值图
//记录每次操作的成功与否
HRESULT hr = S_OK;
//---------------------------------------获取背景二值图并显示---------------------------------
if (SUCCEEDED(hr)){
hr = m_pBodyIndexframeReader->AcquireLatestframe(&pBodyIndexframe);//获得背景二值图信息
}
if (SUCCEEDED(hr)){
BYTE *bodyIndexArray = new BYTE[cDepthHeight * cDepthWidth];//背景二值图是8为uchar,有人是黑色,没人是白色
pBodyIndexframe->CopyframeDataToArray(cDepthHeight * cDepthWidth bodyIndexArray);
//把背景二值图画到MAT里
uchar* skeletonData = (uchar*)skeletonImg.data;
for (int j = 0; j < cDepthHeight * cDepthWidth; ++j){
*skeletonData = bodyIndexArray[j]; ++skeletonData;
*skeletonData = bodyIndexArray[j]; ++skeletonData;
*skeletonData = bodyIndexArray[j]; ++skeletonData;
}
delete[] bodyIndexArray;
}
SafeRelease(pBodyIndexframe);//必须要释放,否则之后无法获得新的frame数据
//-----------------------获取深度数据并显示--------------------------
if (SUCCEEDED(hr)){
hr = m_pDepthframeReader->AcquireLat
- 上一篇:pic18系列单片机C语言程序例程
- 下一篇:基于C++的三帧差法
相关资源
- c语言小学生自然数四则运算测试程序
- TC2.0DOSBOX
- Kinect手势控制鼠标
- C++实现的蓝牙应用程序框架-BlueSolei
- USB2.0接口数据采集卡
- 基于CY7C68013A的USB2.0详细开发文档
- MFC垃圾清理器V2.0
- Microsoft Visual C++ 2013 Redistributable Pack
- kinect2.0数据采集及点云生成代码C++
- minix(1.0-2.0)源码
- Kinect c++试验版的切水果游戏
- Twisted-19.2.0-cp37-cp37m-win_amd64.whl
- MinGWStudioFullSetup-2.05r10-gcc4.rar
- 利用MFC的Picture控件显示图像和视频
- 支持国密的OpenSSL 2.0
- Quartus II 12.0 license完全破解文件
- Visual.Assist.X.V10.9.2302.0原版安装文件以
- 穿透版CTP综合交易平台接口V2.0-程序化
- 3D场景漫游2.0版程序源码 by浅墨
- cmake-3.12.0-win64-x64
- KinectV2 实现鼠标控制VS2013 C++版
- C++计算任意函数值 积分 线性方程组
- tdm64-gcc-9.2.0.exe
- MFC kinect 骨骼识别
- tesseract-3.02.02 c++开发用到的所有
-
《ob
jective-C2.0程序设计(原书第2版 - 箱子求解V2.0C++/MFC)
- GTK+2.0实现学生成绩管理系统
- 四国争霸 2.0.4.7 作蔽器&源代码
- KinectV2彩色图片尺寸变换代码变换后与
评论
共有 条评论