资源简介
用的xtion(kinect也相同)和openni获取深度数据,转换为三维点云后在opengl中表示(用彩色数据作纹理),可用鼠标和键盘对三维点云进行旋转与缩放。

代码片段和文件信息
#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(){
// 获取设备信息
Array aDeviceList;
OpenNI::enumerateDevices(&aDeviceList);
cout << “电脑上连接着 “ << aDeviceList.getSize() << “ 个体感设备.“ << endl;
for (int i = 0; i < aDeviceList.getSize(); ++i)
{
cout << “设备 “ << i << endl;
const DeviceInfo& rDevInfo = aDeviceList[i];
cout << “设备名: “ << rDevInfo.getName() << endl;
cout << “设备Id: “ << rDevInfo.getUsbProductId() << endl;
cout << “供应商名: “ << rDevInfo.getVendor() << endl;
cout << “供应商Id: “ << rDevInfo.getUsbVendorId() << endl;
cout << “设备URI: “ << rDevInfo.getUri() << endl;
}
}
void* GetDataFromXtion(void *p)
{
Status rc = STATUS_OK;
// 初始化OpenNI环境
OpenNI::initialize();
showdevice();
// 声明并打开Device设备。
Device xtion;
const char * deviceURL = openni::ANY_DEVICE; //设备名
rc = xtion.open(deviceURL);
// 创建深度数据流
VideoStream streamDepth;
rc = streamDepth.create(xtion SENSOR_DEPTH);
if (rc == STATUS_OK)
{
// 设置深度图像视频模式
VideoMode mModeDepth;
// 分辨率大小
mModeDepth.setResolution(640 480);
// 每秒30帧
mModeDepth.setFps(30);
// 像素格式
mModeDepth.setPixelFormat(PIXEL_FORMAT_DEPTH_1_MM);
streamDepth.setVideoMode(mModeDepth);
streamDepth.setMirroringEnabled(false);
// 打开深度数据流
rc = streamDepth.start();
if (rc != STATUS_OK)
{
cerr << “无法打开深度数据流:“ << OpenNI::getExtendedError() << endl;
streamDepth.destroy();
}
}
else
{
cerr << “无法创建深度数据流:“ << OpenNI::getExtendedError() << endl;
}
// 创建彩色图像数据流
VideoStream streamColor;
rc = streamColor.create(xtion SENSOR_COLOR);
if (rc == STATUS_OK)
{
// 同样的设置彩色图像视频模式
VideoMode mModeColor;
mModeColor.setResolution(320 240);
mModeColor.setFps(30);
mModeColor.setPixelFormat(PIXEL_FORMAT_RGB888);
streamColor.setVideoMode(mModeColor);
// 解决镜像问题
streamColor.setMirroringEnabled(false);
// 打开彩色图像数据流
rc = streamColor.start();
if (rc != STATUS_OK)
{
cerr << “无法打开彩色图像数据流:“ << OpenNI::getExtendedError() << endl;
streamColor.destroy();
}
}
else
{
cerr << “无法创建彩色图像数据流:“ << OpenNI::getExtendedError() << endl;
}
if (!streamColor.isValid() || !streamDepth.isValid())
{
cerr << “数据流不合法“ << endl;
OpenNI::shutdown();
return NULL;
}
// 图像模式注册彩色图与深度图对齐
if (xtion.isImageRegistrationModeSupported(
IMAGE_REGISTRATION_DEPTH_TO_COLOR))
{
xtion.setImageRegistrationMode(IMAGE_REGISTRATION_DEPTH_TO_COLOR);
}
// 创建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相机姿态更新
- 下一篇:Masm for Windows
相关资源
- OpenGL参考手册
- Qt Creator opengl实现四元数鼠标控制轨迹
- OpenGL文档,api大全,可直接查询函数
- opengl轮廓字体源代码
- MFC读三维模型obj文件
- 利用OpenGL写毛笔字算法
- MFC中OpenGL面和体的绘制以及动画效果
- 基于OPENGL的光线跟踪源代码368758
- VC 实现三维旋转(源码)
- 自编用openGL实现3D分形树,分形山
- OpenGL球形贴图自旋程序
- OpenGL导入贴图的Texture类
- 计算机图形学(openGL)代码
- 用OpenGL开发的机械臂运动仿真程序(
- OpenGL-3D坦克模拟
- OPENGL实现世界上最小的3D游戏
- VS2012OpenGL配置所需要的全部libdllh文件
- 基于OpenGL的仿蝗虫机器人三维动态仿
- 图形学 - OpenGL实现3种三维茶壶显示源
- opengl程序-会跳舞的骷髅
- opengl实现三维网格光顺Laplacian算法
- opengl——爆炸
- OpenGL三维地形建模
- opengl游戏编程徐明亮版(含源码)
- 用OPENGL画的一个简单的直升飞机
- opengl完美天空盒
- Kinect手势代替鼠标控制PC
- SfM稀疏三维点云重建--完整工程文件
- 3D绘图程序设计:使用Direct3D 10/9和Ope
- OpenGL绘制可运动自行车源程序.zip
评论
共有 条评论