kinect深度图彩色图融合代码


kinect、通过Kinect v2.0+ VS2015+openCV将彩色帧映射到深度空间
这段程序是基于MapDepthPointToColorSpace实现配准的。
资源截图
代码片段和文件信息
#include “stdafx.h“
#include “kinect.h“

#include 
#include 
#include 
#include 
#include 
#include   
#include 
#include 
#include 
#include 
//#include “PracticalSocket.h“
#include 

using namespace cv;
using namespace std;
template      //函数模板
inline void SafeRelease(Interface *& pInterfaceToRelease)
{
if (pInterfaceToRelease != NULL)
{
pInterfaceToRelease->Release();
pInterfaceToRelease = NULL;
}
}
int main()
{

setUseOptimized(true);
int depthWidth = 512;
int depthHeight = 424;


HRESULT hResult = S_OK;

//ColorSpacePoint* pointsCloud = nullptr;
IKinectSensor* pSensor;
ICoordinateMapper* pCoordinateMapper;
hResult = GetDefaultKinectSensor(&pSensor);
if (FAILED(hResult)) { cerr << “Error:GetDefaultKinectSensor“ << endl; return -1; }


IMultiSourceframeReader* m_pMultiframeReader;
// IBodyframeSource* m_pBodyframeSource;
//IBodyframeReader* m_pBodyframeReader;

hResult = pSensor->Open();

//pSensor->get_BodyframeSource(&m_pBodyframeSource);
// 获取多数据源到读取器  
 pSensor->OpenMultiSourceframeReader(
frameSourceTypes::frameSourceTypes_Color |
frameSourceTypes::frameSourceTypes_Infrared |
frameSourceTypes::frameSourceTypes_Depth
&m_pMultiframeReader);
if (FAILED(hResult)) { cerr << “Error:IKinectSensor::Open()“ << endl; return -11; }

pSensor->get_CoordinateMapper(&pCoordinateMapper);

if (FAILED(hResult)) { cerr << “Error:IKinectSensor::get_DepthframeSource()“ << endl; return -1; }
// 三个数据帧及引用
IDepthframe* m_pDepthframe = NULL;
IColorframe* m_pColorframe = NULL;
IDepthframeReference* m_pDepthframeReference = NULL;
IColorframeReference* m_pColorframeReference = NULL;
ColorSpacePoint*        m_pColorCoordinates = NULL;
// CameraSpacePoint*        m_pCameraCoordinates = NULL;
IMultiSourceframe* m_pMultiframe = NULL;//多源数据帧初始化

//unsigned int bufferSize = depthWidth * depthHeight * sizeof(unsigned short);
//Mat bufferMat(depthHeight depthWidth CV_16SC1);
//Mat depthMat(depthHeight depthWidth CV_8UC1);
//Mat i_depthToRgb(424 512 CV_8UC4);
BYTE *bgraData = new BYTE[1080 * 1920 * 4];
UINT16 *depthData = new UINT16[424 * 512];
//m_pCameraCoordinates = new CameraSpacePoint[512 * 424];
m_pColorCoordinates = new ColorSpacePoint[512 * 424];
//Mat i_rgb(1080 1920 CV_8UC4);
//Mat bufferMat;
while (1)
{
//frame
//IDepthframe* pDepthframe = nullptr;
// 获取新的一个多源数据帧
hResult = m_pMultiframeReader->AcquireLatestframe(&m_pMultiframe);
//UINT16 *depthData = new UINT16[424 * 512];
if (SUCCEEDED(hResult))
hResult = m_pMultiframe->get_ColorframeReference(&m_pColorframeReference);
if (SUCCEEDED(hResult))
hResult = m_pColorframeReference->Acquireframe(&m_pColorframe);
if (SUCCEEDED(hResult))
hResult = m_pMultiframe->get_

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2017-09-15 14:00  mapTest.vs
     目录           0  2017-09-15 14:00  mapTest.vsmapTest
     目录           0  2017-09-15 14:00  mapTest.vsmapTestv14
     文件       34304  2017-10-09 20:45  mapTest.vsmapTestv14.suo
     目录           0  2017-09-15 14:04  mapTestDebug
     目录           0  2017-09-15 14:00  mapTestipch
     目录           0  2017-10-09 20:45  mapTestipchMAPTEST-998847d6
     文件     3538944  2017-09-15 14:00  mapTestipchMAPTEST-998847d6MAPTEST-42e9930a.ipch
     文件     3473408  2017-10-09 20:45  mapTestipchMAPTEST-998847d6MAPTEST-abf480e8.ipch
     文件    53018624  2017-10-09 20:45  mapTestmapTest.sdf
     文件        1303  2017-09-15 14:00  mapTestmapTest.sln
     文件    44785664  2017-09-25 15:13  mapTestmapTest.VC.db
     目录           0  2017-10-09 20:45  mapTestmapTest
     文件        7338  2017-10-09 20:45  mapTestmapTestmapTest.cpp
     文件        8036  2017-10-09 20:45  mapTestmapTestmapTest.vcxproj
     文件        1314  2017-09-16 11:42  mapTestmapTestmapTest.vcxproj.filters
     文件        1510  2017-09-15 14:00  mapTestmapTestReadMe.txt
     文件        7127  2017-09-15 16:50  mapTestmapTestshowCloud.cpp
     文件         211  2017-09-15 14:00  mapTestmapTeststdafx.cpp
     文件         234  2017-09-15 14:00  mapTestmapTeststdafx.h
     文件         240  2017-09-15 14:00  mapTestmapTest argetver.h
     目录           0  2017-09-15 15:00  mapTestmapTestx64
     目录           0  2017-09-16 11:45  mapTestmapTestx64Debug
     文件      500260  2017-09-15 15:51  mapTestmapTestx64DebugColor.obj
     文件      298561  2017-09-15 15:19  mapTestmapTestx64DebugDepth.obj
     文件         171  2017-09-16 11:45  mapTestmapTestx64DebugmapTest.log
     文件      524805  2017-09-16 11:45  mapTestmapTestx64DebugmapTest.obj
     文件     3407872  2017-09-15 15:06  mapTestmapTestx64DebugmapTest.pch
     目录           0  2017-09-16 11:45  mapTestmapTestx64DebugmapTest.tlog
     文件       16160  2017-09-16 11:45  mapTestmapTestx64DebugmapTest.tlogCL.command.1.tlog
     文件      150156  2017-09-16 11:45  mapTestmapTestx64DebugmapTest.tlogCL.read.1.tlog
............此处省略13个文件信息

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

发表评论

评论列表(条)