最近忙着搞老师的任务,没来得及更新点云系列。
目前在做Kinect,在这里接着做个笔记。
原文地址: Kinect Tutorials
这仅仅是做一个笔记以及自己的实际操作记录


关于KINECT V2.0 C++ SDK 基础教程的笔记 EP2

  • 1、概述
    • 1.1 更改代码
      • 1.1.1 改变数据源
      • 1.1.2 获取深度数据帧
    • 1.2 完整代码
    • 1.3 结果图

跟着网上的教程,学习Kinect c++ SDK。
⬇⬇⬇⬇⬇⬇⬇⬇⬇⬇⬇⬇⬇⬇⬇⬇⬇⬇⬇⬇⬇⬇⬇⬇⬇⬇⬇⬇⬇⬇⬇⬇⬇⬇⬇⬇⬇⬇⬇⬇⬇
➡➡➡➡➡<<< Kinect Tutorials >>>⬅⬅⬅⬅⬅⬅
⬆⬆⬆⬆⬆⬆⬆⬆⬆⬆⬆⬆⬆⬆⬆⬆⬆⬆⬆⬆⬆⬆⬆⬆⬆⬆⬆⬆⬆⬆⬆⬆⬆⬆⬆⬆⬆⬆⬆⬆⬆
跟着网上的教程,学习Kinect c++ SDK。


1、概述

在上一章获取RGB的基础上进行了深度图展示

1.1 更改代码

1.1.1 改变数据源

IDepthFrameReader* reader;     // Kinect depth data sourcebool initKinect() {if (FAILED(GetDefaultKinectSensor(&sensor))) {return false;}if (sensor) {sensor->Open();IDepthFrameSource* framesource = NULL;sensor->get_DepthFrameSource(&framesource);framesource->OpenReader(&reader);if (framesource) {framesource->Release();framesource = NULL;}return true;} else {return false;}
}

1.1.2 获取深度数据帧

void getKinectData(GLubyte* dest) {IDepthFrame* frame = NULL;if (SUCCEEDED(reader->AcquireLatestFrame(&frame))) {unsigned int sz;unsigned short* buf;frame->AccessUnderlyingBuffer(&sz, &buf);const unsigned short* curr = (const unsigned short*)buf;const unsigned short* dataEnd = curr + (width*height);while (curr < dataEnd) {// Get depth in millimetersunsigned short depth = (*curr++);// Draw a grayscale image of the depth:// B,G,R are all set to depth%256, alpha set to 1.for (int i = 0; i < 3; ++i)*dest++ = (BYTE)depth % 256;*dest++ = 0xff;}}if (frame) frame->Release();
}

遇到找不到freeglut.dll的错误,把freeglut.dll放到Debug文件夹下就可以了

1.2 完整代码

//这是一个基于gult显示深度图的代码// SDL
//包含文件
//为了Kinect正常工作#include <Windows.h>
#include <Ole2.h>
//为可视化
#include <gl/GL.h>
#include <gl/GLU.h>
#include <gl/glut.h>
//kinect主要头文件
#include <Kinect.h>//常量和全局变量
#define width 512
#define height 424// OpenGL Variables 变量
GLuint textureId;              // ID of the texture to contain Kinect RGB Data 包含 Kinect RGB 数据的纹理 ID
GLubyte data[width * height * 4];  // BGRA array containing the texture data  包含纹理数据的 BGRA 数组// Kinect variables 变量
IKinectSensor* sensor;         // Kinect sensor  Kinect传感器
IDepthFrameReader* reader;     // Kinect color data source    Kinect 颜色数据源//Kinect初始化
//initKinect()函数的作用是初始化一个 Kinect 设备。它包含了两个部分:首先,我们需要找到一个已连接到电脑的 Kinect 传感器,然后将其初始化并准备从中读取数据。
bool initKinect() {if (FAILED(GetDefaultKinectSensor(&sensor))) {return false;}if (sensor) {sensor->Open();IDepthFrameSource* framesource = NULL;sensor->get_DepthFrameSource(&framesource);framesource->OpenReader(&reader);if (framesource) {framesource->Release();framesource = NULL;}return true;} else {return false;}
}//从 Kinect 中获取 RGB 帧
void getKinectData(GLubyte* dest) {IDepthFrame* frame = NULL;if (SUCCEEDED(reader->AcquireLatestFrame(&frame))) {unsigned int sz;unsigned short* buf;frame->AccessUnderlyingBuffer(&sz, &buf);const unsigned short* curr = (const unsigned short*)buf;const unsigned short* dataEnd = curr + (width * height);while (curr < dataEnd) {// Get depth in millimetersunsigned short depth = (*curr++);// Draw a grayscale image of the depth:// B,G,R are all set to depth%256, alpha set to 1.for (int i = 0; i < 3; ++i)*dest++ = (BYTE)depth % 256;*dest++ = 0xff;}}if (frame) frame->Release();
}void drawKinectData() {glBindTexture(GL_TEXTURE_2D, textureId);getKinectData(data);glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_BGRA_EXT, GL_UNSIGNED_BYTE, (GLvoid*)data);glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);glBegin(GL_QUADS);glTexCoord2f(0.0f, 0.0f);glVertex3f(0, 0, 0);glTexCoord2f(1.0f, 0.0f);glVertex3f(width, 0, 0);glTexCoord2f(1.0f, 1.0f);glVertex3f(width, height, 0.0f);glTexCoord2f(0.0f, 1.0f);glVertex3f(0, height, 0.0f);glEnd();
}
//具体的初始化代码取决于使用那种实现方式 (GLUT 或 SDL)。它只是使用适当的 API 初始化一个窗口,失败时返回 false。GLUT 版本的实现还会通过指定draw()函数在每次循环迭代中被调用来设置主循环。
//主循环在execute()函数中启动。在 GLUT中,循环是在后台处理的,所以我们需要做的就是调用glutMainLoop()函数。
void draw() {drawKinectData();glutSwapBuffers();
}void execute() {glutMainLoop();
}bool init(int argc, char* argv[]) {glutInit(&argc, argv);glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);glutInitWindowSize(width, height);glutCreateWindow("Kinect SDK Tutorial");glutDisplayFunc(draw);glutIdleFunc(draw);return true;
}int main(int argc, char* argv[]) {if (!init(argc, argv)) return 1;if (!initKinect()) return 1;// Initialize textures//代码中描述了三个步骤——设置纹理以包含图像帧,准备 OpenGL 来绘制纹理,以及设置摄像机视点(对 2D 图像使用正投影)。glGenTextures(1, &textureId);glBindTexture(GL_TEXTURE_2D, textureId);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height,0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, (GLvoid*)data);glBindTexture(GL_TEXTURE_2D, 0);// OpenGL setupglClearColor(0, 0, 0, 0);glClearDepth(1.0f);glEnable(GL_TEXTURE_2D);// Camera setupglViewport(0, 0, width, height);glMatrixMode(GL_PROJECTION);glLoadIdentity();glOrtho(0, width, height, 0, 1, -1);glMatrixMode(GL_MODELVIEW);glLoadIdentity();// Main loopexecute();return 0;
}

1.3 结果图

关于KINECT V2.0 C++ SDK 基础教程的笔记 EP2相关推荐

  1. Kinect v2.0 for Windows10 安装教程

    最近试了下kinect 2.0,但是发现买了之后不知道怎么用,于是研究了两天,参照各位前人的资料后,整合,再加上和客服联系沟通的结果,重新整理了一份适合小白的安装教程,有的引用可能忘了是哪里了,因为我 ...

  2. 深度相机(五)--Kinect v2.0

    原文:http://blog.csdn.net/qq1175421841/article/details/50412994 ----微软Build2012大会:Kinect for Windows P ...

  3. 自由天空XP/2K3封装工具 Easy Sysprep v2.0 正式版封装教程

    自由天空XP/2K3封装工具 Easy Sysprep v2.0 正式版封装教程     制作万能Ghost系统光盘必须对操作系统进行重新封装,在<[原创]跟我一起打造自己的GHOST系统安装光 ...

  4. linux磁盘符变化autofs,Linux基础教程学习笔记之Autofs自动挂载

    Linux基础教程学习笔记之Autofs自动挂载 Autofs自动挂载: yum -y install autofs vim /etc/auto.master  在文件中添加下面行 /home/gue ...

  5. 网络存储 linux 访问,Linux基础教程学习笔记28——使用Samba访问网络存储

    Linux基础教程学习笔记28--使用Samba访问网络存储 SMB用于Windows和类Linux系统直接的文件共享 安装samba client包: [root@linuxidc~]# yum i ...

  6. 黑马程序员最新版JavaWeb基础教程-学习笔记

    da@黑马程序员最新版JavaWeb基础教程-学习笔记 day06-HTML&CSS HTML HTML(HyperTest Markup Language):超文本标记语言 是一门语言,所有 ...

  7. 【计算机视觉】深度相机(六)--Kinect v2.0 手势样本库制作

    目录为1.如何使用Kinect Studio录制手势剪辑:2.如何使用Visual Gesture Builder创建手势项目:3.如何在我的C#程序中使用手势:4.关于录制.剪辑手势过程中的注意事项 ...

  8. 深度相机(六)--Kinect v2.0 手势样本库制作

    目录为1.如何使用Kinect Studio录制手势剪辑:2.如何使用Visual Gesture Builder创建手势项目:3.如何在我的C#程序中使用手势:4.关于录制.剪辑手势过程中的注意事项 ...

  9. Kinect v2.0 for windows开发环境说明

    官方文档里是这些: Supported Operating Systems and Architectures The following operating systems and architec ...

最新文章

  1. javaweb实现mysql备份功能_java web 实现mysql 数据库备份、恢复
  2. 九坤投资投身基础科研,携手IDEA成立联合实验室
  3. Android事件传递(分发)机制
  4. 浅析Facebook LibraBFT与比原链Bystack BBFT共识
  5. 经典复现:《统计学习方法》的代码实现(在线阅读!)
  6. 关于Storm Tick
  7. 如何将自己的Java项目部署到外网
  8. mysql查询各类课程的总学分_基于jsp+mysql的JSP学生选课信息管理系统
  9. 计算机网络/操作系统
  10. Tensorflow中图像的预处理
  11. pytorch中的反卷积的output_padding参数
  12. Linux acpi off关于Suspend to Disk 问题分析
  13. React五——React-router
  14. C++ OpenCV 学习笔记【1】-安装环境搭建+基础文件资源链接
  15. 论文翻译:2021_语音增强模型压缩_Performance optimizations on deep noise suppression models...
  16. 浏览器沙箱(sandBox)到底是什么?
  17. 罗格斯的计算机科学,清华大学计算机科学与技术系
  18. 网易云音乐api歌单数据获取
  19. [渝粤教育] 南京交通职业技术学院 计算机基础 参考 资料
  20. 点我一下,你将获得排查性能问题的超能力~

热门文章

  1. Python正则表达式(二)
  2. 庄子心得10:心态与状态
  3. 使用partx重读磁盘分区信息及自动挂载分区的方法
  4. 24个节气之美,每一个都如诗如画!
  5. H5--新增表单元素控件属性事件
  6. Python基础(四)——列表
  7. 东莞厚街工业机器人展会_2020东莞国际工业自动化及机器人展览会
  8. 用面向对象来判断三角形
  9. Cocos2d里面如何使用Texture Packer和像素格式来优化spritesheet
  10. 南充市住房公积金领取流程