資源簡介
自己做的基于VS2013+opencv2.4.10+kinect 2.0的深度圖和彩色圖的顯示以及二者的對齊(或配準(zhǔn)registration)。希望對大家有幫助。
代碼片段和文件信息
#include?“mykinect.h“
#include?
using?namespace?std;
using?namespace?cv;
///?Constructor?構(gòu)造函數(shù)
CMapBasics::CMapBasics()
{
sensor?=?NULL;
mapper?=?NULL;
reader?=?NULL;
dpoint?=?NULL;
//?create?heap?storage?for?color?pixel?data?in?RGBX?format??
m_pColorRGBX?=?new?RGBQUAD[cColorWidth?*?cColorHeight];
//?create?heap?storage?for?the?coorinate?mapping?from?color?to?depth??
dpoint?=?new?DepthSpacePoint[cColorWidth?*?cColorHeight];
//初始化OpenCV數(shù)組??
depthImg.create(cDepthHeight?cDepthWidth?CV_8UC1);
colorImg.create(cColorHeight?cColorWidth?CV_8UC3);
depthImg.setTo(0);?colorImg.setTo(0);
}
///?Destructor??析構(gòu)函數(shù)
CMapBasics::~CMapBasics()
{
if?(m_pColorRGBX)
{
delete[]?m_pColorRGBX;
m_pColorRGBX?=?NULL;
}
if?(dpoint)
{
delete[]?dpoint;
dpoint?=?NULL;
}
//?done?with?frame?reader??
SafeRelease(reader);
//?done?with?coordinate?mapper??
SafeRelease(mapper);
if?(sensor)
{
sensor->Close();
}
SafeRelease(sensor);
}
//?轉(zhuǎn)換depth圖像到Mat??
Mat?ConvertMat(const?UINT16*?pBuffer?int?nWidth?int?nHeight?USHORT?nMinDepth?USHORT?nMaxDepth)
{
Mat?img(nHeight?nWidth?CV_8UC1);
uchar*?p_mat?=?img.data;
const?UINT16*?pBufferEnd?=?pBuffer?+?(nWidth?*?nHeight);
while?(pBuffer? {
USHORT?depth?=?*pBuffer;
//方法1:將符合邊界條件的uint16去尾賦值給Mat,不符合邊界的置0
BYTE?intensity?=?static_cast(depth?>=?nMinDepth)?&&?(depth?<=?nMaxDepth)???depth?%?256?:?0;
//方法2:直接將uint16去尾賦值給Mat
//BYTE?intensity?=?depth?%?256;
*p_mat?=?intensity;
p_mat++;
++pBuffer;
}
return?img;
}
//轉(zhuǎn)換color圖像到Mat?
Mat?ConvertMat(const?RGBQUAD*?pBuffer?int?nWidth?int?nHeight)
{
Mat?img(nHeight?nWidth?CV_8UC3);
uchar*?p_mat?=?img.data;
const?RGBQUAD*?pBufferEnd?=?pBuffer?+?(nWidth?*?nHeight);
while?(pBuffer? {
*p_mat?=?pBuffer->rgbBlue;
p_mat++;
*p_mat?=?pBuffer->rgbGreen;
p_mat++;
*p_mat?=?pBuffer->rgbRed;
p_mat++;
++pBuffer;
}
return?img;
}
int?main()
{
CMapBasics?myKinect;
HRESULT?hr?=?myKinect.InitKinect();
if?(SUCCEEDED(hr)){
while?(1){
myKinect.Update();
}
}
else{
cout?<“kinect?initialization?failed!“?< system(“pause“);
}
}
HRESULT?CMapBasics::InitKinect()
{
HRESULT?hr;
hr?=?GetDefaultKinectSensor(&sensor);
if?(FAILED(hr))
{
return?hr;
}
if?(sensor)
{
hr?=?sensor->Open();
//?Initialize?the?Kinect?and?get?coordinate?mapper?and?the?frame?reader??
if?(SUCCEEDED(hr))
{
hr?=?sensor->get_CoordinateMapper(&mapper);
}
if?(SUCCEEDED(hr))
{
hr?=?sensor->OpenMultiSourceframeReader(
frameSourceTypes::frameSourceTypes_Depth?|?frameSourceTypes::frameSourceTypes_Color?&reader);
}
}
if?(!sensor?||?FAILED(hr))
{
return?E_FAIL;
}
return?hr;
}
void?CMapBasics::Update()
{
if?(!reader)
{
return;
}
HRESULT?hr?=?reader->AcquireLatestframe(&pMultiSourceframe);
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????1174??2016-05-21?16:05??registration\registration\mykinect.h
?????文件???????1346??2016-05-12?12:26??registration\registration\opencv2410x64.Debug.props
?????文件???????1247??2016-05-12?12:32??registration\registration\opencv2410x64.Release.props
?????文件??????41144??2016-05-12?15:18??registration\registration\PCLx64.Debug.props
?????文件???????7338??2016-05-20?11:17??registration\registration\registration.vcxproj
?????文件???????1065??2016-05-20?11:17??registration\registration\registration.vcxproj.filters
?????文件???????1912??2016-05-21?16:30??registration\registration\x64\Debug\registration.log
?????文件????????612??2016-05-21?16:30??registration\registration\x64\Debug\registration.tlog\cl.command.1.tlog
?????文件??????27268??2016-05-21?16:30??registration\registration\x64\Debug\registration.tlog\CL.read.1.tlog
?????文件????????488??2016-05-21?16:30??registration\registration\x64\Debug\registration.tlog\CL.write.1.tlog
?????文件???????2080??2016-05-21?16:30??registration\registration\x64\Debug\registration.tlog\li
?????文件???????5042??2016-05-21?16:30??registration\registration\x64\Debug\registration.tlog\li
?????文件????????480??2016-05-21?16:30??registration\registration\x64\Debug\registration.tlog\li
?????文件????????162??2016-05-21?16:30??registration\registration\x64\Debug\registration.tlog\registration.lastbuildstate
?????文件????1108992??2016-05-21?16:30??registration\registration\x64\Debug\vc120.idb
?????文件????1642496??2016-05-21?16:30??registration\registration\x64\Debug\vc120.pdb
?????文件?????331023??2016-05-21?16:30??registration\registration\x64\Debug\源.obj
?????文件???????1899??2016-05-22?13:43??registration\registration\x64\Release\registration.log
?????文件????????632??2016-05-22?13:43??registration\registration\x64\Release\registration.tlog\cl.command.1.tlog
?????文件??????27206??2016-05-22?13:43??registration\registration\x64\Release\registration.tlog\cl.read.1.tlog
?????文件????????366??2016-05-22?13:43??registration\registration\x64\Release\registration.tlog\cl.write.1.tlog
?????文件???????2116??2016-05-22?13:43??registration\registration\x64\Release\registration.tlog\li
?????文件???????5336??2016-05-22?13:43??registration\registration\x64\Release\registration.tlog\li
?????文件????????374??2016-05-22?13:43??registration\registration\x64\Release\registration.tlog\li
?????文件????????164??2016-05-22?13:43??registration\registration\x64\Release\registration.tlog\registration.lastbuildstate
?????文件????1249280??2016-05-22?13:43??registration\registration\x64\Release\vc120.pdb
?????文件????1401796??2016-05-22?13:43??registration\registration\x64\Release\源.obj
?????文件???????7069??2016-05-22?13:43??registration\registration\源.cpp
?????文件???45809664??2016-05-22?16:56??registration\registration.sdf
?????文件???????1336??2016-05-20?11:17??registration\registration.sln
............此處省略19個文件信息
- 上一篇:Cosmo Worlds
- 下一篇:增長秘籍3.0 終版
評論
共有 條評論