資源簡介
在vs2013平臺下用c++實現(xiàn)的通過Kinect獲取場景點云數(shù)據(jù)并顯示的程序。獲取線程從Kinect中讀取深度數(shù)據(jù)與圖像數(shù)據(jù),經(jīng)坐標映射與融合后生成目標點云數(shù)據(jù),通過boost的信號槽機制傳輸?shù)街骶€程中并將其使用PCL提供的visualizer在窗口中加以顯示。編譯運行前需要配置PCL與Kinect2.0SDK兩個外部依賴庫。整體代碼簡單,思路清晰,適合剛?cè)腴T的新手學(xué)習(xí)。

代碼片段和文件信息
#include?“PointCloudGrabber.h“
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
PointCloudGrabber::PointCloudGrabber()
:?_sensor(nullptr)
?_mapper(nullptr)
?_colorSource(nullptr)
?_colorReader(nullptr)
?_depthSource(nullptr)
?_depthReader(nullptr)
?_result(S_OK)
?_colorWidth(1920)
?_colorHeight(1080)
?_colorBuffer()
?_depthWidth(512)
?_depthHeight(424)
?_depthPointCount(512?*?424)
?_depthBuffer(_depthPointCount)
?_colorSpacePoints(512?*?424)
?_cameraSpacePoints(512?*?424)
{
}
PointCloudGrabber::~PointCloudGrabber()
{
}
bool?PointCloudGrabber::OpenDevice()
{
//?Create?Sensor?Instance
_result?=?GetDefaultKinectSensor(&_sensor);
if?(FAILED(_result)){
throw?std::exception(“Exception?:?GetDefaultKinectSensor()“);
}
//?Open?Sensor
_result?=?_sensor->Open();
if?(FAILED(_result)){
throw?std::exception(“Exception?:?IKinectSensor::Open()“);
}
//?Retrieved?Coordinate?Mapper
_result?=?_sensor->get_CoordinateMapper(&_mapper);
if?(FAILED(_result)){
throw?std::exception(“Exception?:?IKinectSensor::get_CoordinateMapper()“);
}
//?Retrieved?Color?frame?Source
_result?=?_sensor->get_ColorframeSource(&_colorSource);
if?(FAILED(_result)){
throw?std::exception(“Exception?:?IKinectSensor::get_ColorframeSource()“);
}
//?Retrieved?Depth?frame?Source
_result?=?_sensor->get_DepthframeSource(&_depthSource);
if?(FAILED(_result)){
throw?std::exception(“Exception?:?IKinectSensor::get_DepthframeSource()“);
}
//?Retrieved?Color?frame?Size
iframeDescription*?colorDescription;
_result?=?_colorSource->get_frameDescription(&colorDescription);
if?(FAILED(_result)){
throw?std::exception(“Exception?:?IColorframeSource::get_frameDescription()“);
}
_result?=?colorDescription->get_Width(&_colorWidth);?//?1920
if?(FAILED(_result)){
throw?std::exception(“Exception?:?iframeDescription::get_Width()“);
}
_result?=?colorDescription->get_Height(&_colorHeight);?//?1080
if?(FAILED(_result)){
throw?std::exception(“Exception?:?iframeDescription::get_Height()“);
}
SafeRelease(colorDescription);
//?To?Reserve?Color?frame?Buffer
_colorBuffer.resize(_colorWidth?*?_colorHeight);
//?Retrieved?Depth?frame?Size
iframeDescription*?depthDescription;
_result?=?_depthSource->get_frameDescription(&depthDescription);
if?(FAILED(_result)){
throw?std::exception(“Exception?:?IDepthframeSource::get_frameDescription()“);
}
_result?=?depthDescription->get_Width(&_depthWidth);?//?512
if?(FAILED(_result)){
throw?std::exception(“Exception?:?iframeDescription::get_Width()“);
}
_result?=?depthDescription->get_Height(&_depthHeight);?//?424
if?(FAILED(_res
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2017-09-10?09:14??PointCloudScanner\
?????目錄???????????0??2017-09-10?09:14??PointCloudScanner\PointCloudScanner\
?????文件?????????997??2017-09-10?09:13??PointCloudScanner\PointCloudScanner.sln
?????文件???????27136??2017-09-10?09:14??PointCloudScanner\PointCloudScanner.v12.suo
?????文件????????7499??2017-09-09?21:51??PointCloudScanner\PointCloudScanner\PointCloudGrabber.cpp
?????文件????????1533??2017-09-09?21:47??PointCloudScanner\PointCloudScanner\PointCloudGrabber.h
?????文件????????1821??2017-09-10?09:06??PointCloudScanner\PointCloudScanner\PointCloudScanner.cpp
?????文件????????3532??2017-09-10?09:14??PointCloudScanner\PointCloudScanner\PointCloudScanner.vcxproj
?????文件????????1189??2017-09-10?09:14??PointCloudScanner\PointCloudScanner\PointCloudScanner.vcxproj.filters
評論
共有 條評論