Kinect V2 开发专题(4)骨骼/深度/红外/摄像头数据获取





1、骨骼数据获取

前面的代码省略,从获取数据开始:

// 获取身体数据IBodyFrameSource* bodys = nullptr;bb->get_BodyFrameSource(&bodys); // Body 数据源INT32 nBodyNum = 0;bodys->get_BodyCount(&nBodyNum); // 获取body 个数,没用,一直是6printf("Body Num: %d\n", nBodyNum);IBodyFrameReader* bodyr = nullptr;bodys->OpenReader(&bodyr); // 准备读取body数据while (true){IBodyFrame* bodyf = nullptr;bodyr->AcquireLatestFrame(&bodyf); // 获取最近的一帧数据if ( !bodyf ){Sleep(100);printf(".");continue;}IBody* ppBodies[BODY_COUNT] = { 0 };bodyf->GetAndRefreshBodyData(BODY_COUNT, ppBodies); // 更新所有人身体数据for (int i = 0; i < BODY_COUNT; ++i){IBody* pBody = ppBodies[i]; // 轮询每个人的信息if (pBody){BOOLEAN bTracked = false;hr = pBody->get_IsTracked(&bTracked); // 检测是否被跟踪,即是否有这个人if (bTracked){Joint joints[JointType_Count];HandState leftHandState = HandState_Unknown;HandState rightHandState = HandState_Unknown;pBody->get_HandLeftState(&leftHandState); // 获取左手的状态pBody->get_HandRightState(&rightHandState); // 获取右手的状态hr = pBody->GetJoints(_countof(joints), joints); // 获取身体的骨骼信息,25点printf("Person %d : Joints[0].Z %.2f\n", i, joints[0].Position.Z); //简单的输出他的信息}}}for (int i = 0; i < BODY_COUNT; ++i){ppBodies[i]->Release();}bodyf->Release();}

2、深度数据获取

有了骨骼信息,深度数据就显得没太大的用处了。

/*Depth min: 500 max: 4500Frame: 424 512Buffer size: 217088*/int _tmain(int argc, _TCHAR* argv[]){printf("Hello, Wellcome to kinect world!\n");IKinectSensor* pKinect = nullptr;GetDefaultKinectSensor(&pKinect);if ( !pKinect){printf("Get Kinect failed!\n");goto endstop;}pKinect->Open();BOOLEAN bOpen = false;// 一直等待直到Kinect打开完成while (!bOpen){pKinect->get_IsOpen(&bOpen);Sleep(200);}IDepthFrameSource* depths = nullptr;pKinect->get_DepthFrameSource(&depths); // 获取深度数据源IDepthFrameReader* depthr = nullptr;depths->OpenReader(&depthr); // 打开深度解析器while (true){IDepthFrame* depthf = nullptr;depthr->AcquireLatestFrame(&depthf); // 获取最近的深度数据if ( !depthf ){Sleep(200);continue;}USHORT minds, maxds;depthf->get_DepthMinReliableDistance(&minds); // 获取最近的有效距离,500depthf->get_DepthMaxReliableDistance(&maxds); // 获取最远的有效距离,4500printf("Depth min: %d max: %d\n", minds, maxds);IFrameDescription* frameDs = nullptr;depthf->get_FrameDescription(&frameDs); // 获取深度信息的属性int height, width;frameDs->get_Height(&height);frameDs->get_Width(&width);printf("Frame: %d %d\n", height, width);UINT ncaps = 0;UINT16* buff = nullptr;depthf->AccessUnderlyingBuffer(&ncaps, &buff); // 获取深度数据的指针和大小//depthf->CopyFrameDataToArray(…); // 讲深度数据Copy到制定的buffer中printf("Buffer size: %d\n", ncaps);depthf->Release();frameDs->Release();Sleep(200);}pKinect->Close();endstop:system("pause");return 0;}

3、红外数据获取

Kinect的核心计算就是根据红外数据的,我们也来获取一下看看。其实,它和深度数据没啥区别,真的,,大小、用法也一摸一样。

/*Frame: 424 512Buffer size: 217088*/int _tmain(int argc, _TCHAR* argv[]){printf("Hello, Wellcome to kinect world!\n");IKinectSensor* pKinect = nullptr;GetDefaultKinectSensor(&pKinect);if ( !pKinect){printf("Get Kinect failed!\n");goto endstop;}pKinect->Open();BOOLEAN bOpen = false;// 一直等待直到Kinect打开完成while (!bOpen){pKinect->get_IsOpen(&bOpen);Sleep(200);}IInfraredFrameSource* infrareds = nullptr;pKinect->get_InfraredFrameSource(&infrareds); // 获取红外数据源IInfraredFrameReader* infraredr = nullptr;infrareds->OpenReader(&infraredr); // 打开红外解析器while (true){IInfraredFrame* infraredf = nullptr;infraredr->AcquireLatestFrame(&infraredf); // 获取最近的红外数据if (!infraredf){Sleep(200);continue;}IFrameDescription* frameDs = nullptr;infraredf->get_FrameDescription(&frameDs); // 获取红外信息的属性int height, width;frameDs->get_Height(&height);frameDs->get_Width(&width);printf("Frame: %d %d\n", height, width);UINT ncaps = 0;UINT16* buff = nullptr;infraredf->AccessUnderlyingBuffer(&ncaps, &buff); // 获取红外数据的指针和大小//depthf->CopyFrameDataToArray(…); // 将数据Copy到制定的buffer中printf("Buffer size: %d\n", ncaps);infraredf->Release();frameDs->Release();Sleep(200);}pKinect->Close();endstop:system("pause");return 0;}

4、摄像头数据获取

摄像头也很简单的,不用看也知道,和上面的差不多。直接上代码了。

当你开展的事业从事的行动穷途末路大势已去的时候,

Kinect V2 开发专题(4)骨骼/深度/红外/摄像头数据获取

相关文章:

你感兴趣的文章:

标签云: