資源簡介
用的xtion(kinect也相同)和openni獲取深度數(shù)據(jù),轉(zhuǎn)換為三維點云后在opengl中表示(用彩色數(shù)據(jù)作紋理),可用鼠標和鍵盤對三維點云進行旋轉(zhuǎn)與縮放。

代碼片段和文件信息
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
using?namespace?std;
using?namespace?openni;
using?namespace?cv;
float?xyzdata[480][640][3];
float?texture[480][640][3];
void?showdevice(){
//?獲取設(shè)備信息??
Array?aDeviceList;
OpenNI::enumerateDevices(&aDeviceList);
cout?<“電腦上連接著?“?<
for?(int?i?=?0;?i? {
cout?<“設(shè)備?“?< const?DeviceInfo&?rDevInfo?=?aDeviceList[i];
cout?<“設(shè)備名:?“?< cout?<“設(shè)備Id:?“?< cout?<“供應(yīng)商名:?“?< cout?<“供應(yīng)商Id:?“?< cout?<“設(shè)備URI:?“?<
}
}
void*?GetDataFromXtion(void?*p)
{
Status?rc?=?STATUS_OK;
//?初始化OpenNI環(huán)境
OpenNI::initialize();
showdevice();
//?聲明并打開Device設(shè)備。
Device?xtion;
const?char?*?deviceURL?=?openni::ANY_DEVICE;??//設(shè)備名
rc?=?xtion.open(deviceURL);
//?創(chuàng)建深度數(shù)據(jù)流
VideoStream?streamDepth;
rc?=?streamDepth.create(xtion?SENSOR_DEPTH);
if?(rc?==?STATUS_OK)
{
//?設(shè)置深度圖像視頻模式
VideoMode?mModeDepth;
//?分辨率大小
mModeDepth.setResolution(640?480);
//?每秒30幀
mModeDepth.setFps(30);
//?像素格式
mModeDepth.setPixelFormat(PIXEL_FORMAT_DEPTH_1_MM);
streamDepth.setVideoMode(mModeDepth);
streamDepth.setMirroringEnabled(false);
//?打開深度數(shù)據(jù)流
rc?=?streamDepth.start();
if?(rc?!=?STATUS_OK)
{
cerr?<“無法打開深度數(shù)據(jù)流:“?< streamDepth.destroy();
}
}
else
{
cerr?<“無法創(chuàng)建深度數(shù)據(jù)流:“?< }
//?創(chuàng)建彩色圖像數(shù)據(jù)流
VideoStream?streamColor;
rc?=?streamColor.create(xtion?SENSOR_COLOR);
if?(rc?==?STATUS_OK)
{
//?同樣的設(shè)置彩色圖像視頻模式
VideoMode?mModeColor;
mModeColor.setResolution(320?240);
mModeColor.setFps(30);
mModeColor.setPixelFormat(PIXEL_FORMAT_RGB888);
streamColor.setVideoMode(mModeColor);
//?解決鏡像問題
streamColor.setMirroringEnabled(false);
//?打開彩色圖像數(shù)據(jù)流
rc?=?streamColor.start();
if?(rc?!=?STATUS_OK)
{
cerr?<“無法打開彩色圖像數(shù)據(jù)流:“?< streamColor.destroy();
}
}
else
{
cerr?<“無法創(chuàng)建彩色圖像數(shù)據(jù)流:“?< }
if?(!streamColor.isValid()?||?!streamDepth.isValid())
{
cerr?<“數(shù)據(jù)流不合法“?< OpenNI::shutdown();
return?NULL;
}
//?圖像模式注冊彩色圖與深度圖對齊
if?(xtion.isImageRegistrationModeSupported(
IMAGE_REGISTRATION_DEPTH_TO_COLOR))
{
xtion.setImageRegistrationMode(IMAGE_REGISTRATION_DEPTH_TO_COLOR);
}
//?創(chuàng)建OpenCV圖像窗口
namedWindow(“Depth?Image“?CV_WINDOW_AUTOSIZE);
namedWindow(“Color?Image“?CV_WINDOW_AUTOSIZE);
//?獲得最大深度值
int?iMaxDepth?=?streamDepth.getMaxPixelValue();????//iMaxDepth一般
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????4606??2015-11-03?19:34??3D_Cloud_Points\3D_Cloud_Points\3D_Cloud_Points.vcxproj
?????文件????????944??2015-11-03?15:57??3D_Cloud_Points\3D_Cloud_Points\3D_Cloud_Points.vcxproj.filters
?????文件???????1905??2015-11-12?16:13??3D_Cloud_Points\3D_Cloud_Points\Debug\3D_Cloud_Points.log
?????文件????????200??2015-11-12?16:13??3D_Cloud_Points\3D_Cloud_Points\Debug\3D_Cloud_Points.tlog\3D_Cloud_Points.lastbuildstate
?????文件????????922??2015-11-12?16:13??3D_Cloud_Points\3D_Cloud_Points\Debug\3D_Cloud_Points.tlog\cl.command.1.tlog
?????文件??????27330??2015-11-12?16:13??3D_Cloud_Points\3D_Cloud_Points\Debug\3D_Cloud_Points.tlog\CL.read.1.tlog
?????文件????????760??2015-11-12?16:13??3D_Cloud_Points\3D_Cloud_Points\Debug\3D_Cloud_Points.tlog\CL.write.1.tlog
?????文件???????1794??2015-11-12?16:13??3D_Cloud_Points\3D_Cloud_Points\Debug\3D_Cloud_Points.tlog\li
?????文件???????3832??2015-11-12?16:13??3D_Cloud_Points\3D_Cloud_Points\Debug\3D_Cloud_Points.tlog\li
?????文件????????744??2015-11-12?16:13??3D_Cloud_Points\3D_Cloud_Points\Debug\3D_Cloud_Points.tlog\li
?????文件?????715776??2015-11-12?16:13??3D_Cloud_Points\3D_Cloud_Points\Debug\vc120.idb
?????文件?????765952??2015-11-12?16:13??3D_Cloud_Points\3D_Cloud_Points\Debug\vc120.pdb
?????文件?????281263??2015-11-12?16:13??3D_Cloud_Points\3D_Cloud_Points\Debug\源.obj
?????文件??????12024??2015-11-04?11:57??3D_Cloud_Points\3D_Cloud_Points\xyzdata.txt
?????文件??????11848??2015-11-12?16:13??3D_Cloud_Points\3D_Cloud_Points\源.cpp
?????文件???38535168??2015-11-12?16:26??3D_Cloud_Points\3D_Cloud_Points.sdf
?????文件????????991??2015-11-03?15:52??3D_Cloud_Points\3D_Cloud_Points.sln
????..A..H.?????31232??2015-11-12?16:26??3D_Cloud_Points\3D_Cloud_Points.v12.suo
?????文件?????112128??2015-11-12?16:13??3D_Cloud_Points\Debug\3D_Cloud_Points.exe
?????文件????1915964??2015-11-12?16:13??3D_Cloud_Points\Debug\3D_Cloud_Points.ilk
?????文件????3182592??2015-11-12?16:13??3D_Cloud_Points\Debug\3D_Cloud_Points.pdb
?????目錄??????????0??2015-11-12?16:13??3D_Cloud_Points\3D_Cloud_Points\Debug\3D_Cloud_Points.tlog
?????目錄??????????0??2015-11-12?16:13??3D_Cloud_Points\3D_Cloud_Points\Debug
?????目錄??????????0??2015-11-12?16:13??3D_Cloud_Points\3D_Cloud_Points
?????目錄??????????0??2015-11-10?21:30??3D_Cloud_Points\Debug
?????目錄??????????0??2015-11-12?16:26??3D_Cloud_Points
-----------?---------??----------?-----??----
?????????????45607975????????????????????26
- 上一篇:OpenCV相機姿態(tài)更新
- 下一篇:Masm for Windows
評論
共有 條評論