Today we will learn how to get depth data from a kinect and what the format of the data is





kinect code





kinect Initialization





To get the depth data from the kinect, simply change the argument to NuiImageStreaOpen().





The First argument is now NUI_IMAGE_TYPE_DEPATH,telling the Kinect that wo now want depath images





instead of RGB iamges.(For clarity we also changed the name of the handle to reflect this)





We also should enable the Near Mode.let the kinect to be more sensitive to closer objects(say from 50cm to





200cm),otherwise,from 80 to 400cm.





To done that,passing flag NUI_IMAGE_FLAG_ENABLE_NEAR_MODE as the third argument

<span style="font-size:12px;"><span style="font-size:10px;">// NEW VARIABLE
HANDLE depthStream; bool initKinect() {
// Get a working kinect sensor
int numSensors;
if (NuiGetSensorCount(&numSensors) < 0 || numSensors < 1) return false;
if (NuiCreateSensorByIndex(0, &sensor) < 0) return false; // Initialize sensor
sensor->NuiInitialize(NUI_INITIALIZE_FLAG_USES_DEPTH | NUI_INITIALIZE_FLAG_USES_COLOR); // --------------- START CHANGED CODE -----------------
sensor->NuiImageStreamOpen(
NUI_IMAGE_TYPE_DEPTH, // Depth camera or rgb camera? NUI_IMAGE_RESOLUTION_640x480, // Image resolution
NUI_IMAGE_STREAM_FLAG_ENABLE_NEAR_MODE, // Image stream flags, e.g. near mode
2, // Number of frames to buffer
NULL, // Event handle
&depthStream);
// --------------- END CHANGED CODE -----------------
return sensor;
}</span></span>

For more information about the near mode,please prefer to offficial blog.









getting a depth frame from the kinect





the display of the dapth image from the kinect in grayscale.Each pixel will just be the pixel's distance





from the kinect(in millimeters)mod 256.





note the NuiDepthPixelToDepth fuction,calling this function returns the depth in millimeters at that pixel.





The depth data is 16 bits,so we use a USHORT to read it in.

<span style="font-size:12px;"><span style="font-size:10px;">      const USHORT* curr = (const USHORT*) LockedRect.pBits;
const USHORT* dataEnd = curr + (width*height); while (curr < dataEnd) {
// Get depth in millimeters
USHORT depth = NuiDepthPixelToDepth(*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;
}
</span></span>

that's all the Kinect code! The rest is just how to get it to display.

版权声明:本文博客原创文章。博客,未经同意,不得转载。

Kinect SDK C++ - 2. Kinect Depth Data的更多相关文章

  1. OpenCV、PCL;Xtion、kinect;OpenNI、kinect for windows SDK比较

    一.对比介绍: 1. OpenCV:开源跨平台,OpenCV于1999年由Intel建立,如今由Willow Garage提供支持. 2. OpenNI:OpenNI组织创建于2010年11月.主要成 ...

  2. Kinect SDK(1):读取彩色、深度、骨骼信息并用OpenCV显示

    Kinect SDK 读取彩色.深度.骨骼信息并用OpenCV显示 一.原理说明 对于原理相信大家都明白大致的情况,因此,在此只说比较特别的部分. 1.1 深度流数据: 深度数据流所提供的图像帧中,每 ...

  3. Kinect开发笔记之三Kinect开发环境配置具体解释

            0.前言:        首先说一下我的开发环境,Visual Studio是2013的,系统是win8的64位版本号,SDK是Kinect for windows SDK 1.8版本 ...

  4. Kinect SDK 安装失败

    错误提示:Kinect Management failed to start. 原因: 1, Kinect Management 服务相依的 Plug and Play的服务没有启动. 2,系统安装了 ...

  5. Kinect 开发 —— Hello,Kinect

    控制台输出深度数据: using System; using System.Collections.Generic; using System.Linq; using System.Text; usi ...

  6. Kinect开发资源汇总

    Kinect开发资源汇总   转自: http://www.sigvc.org/bbs/forum.php?mod=viewthread&tid=254&highlight=kinec ...

  7. 【翻译】Kinect v2程序设计(C++) Body 篇

    Kinect SDK v2预览版的主要功能的使用介绍,基本上完成了.这次,是关于取得Body(人体姿势)方法的说明.   上一节,是使用Kinect SDK v2预览版从Kinect v2预览版取得B ...

  8. 【翻译】Kinect v2程序设计(C++) BodyIndex篇

    通过Kinect SDK v2预览版,取得BodyIndex(人体区域)的方法和示例代码. 上一节,介绍了从Kinect v2预览版用Kinect SDK v2预览版获取Depth数据的方法.   这 ...

  9. 【翻译】Kinect v2程序设计(C++) Color篇

    Kinect SDK v2预览版,获取数据的基本流程的说明.以及取得Color图像的示例程序的介绍. 上一节,是关于当前型号Kinect for Windows(后面称作Kinect v1)和次世代型 ...

随机推荐

  1. 【翻译自mos文章】回收 asm磁盘空间的方法

    回收 asm磁盘空间的方法 參考原文: How To Reclaim Asm Disk Space? (Doc ID 351866.1) 适用于: Oracle Database - Enterpri ...

  2. sql function递归

    alter function Fn_GetUserGroupRelation ( @DHsItemID int ) returns nvarchar(1024) begin declare @Col_ ...

  3. 理解JavaScript的闭包

    在JS这块,免不了被问什么是闭包. 从一个常见的循环问题说起. 有一个ul列表, 里面有5个li标签,我希望点击每个li标签的时候,弹出每个li标签对应的索引值(第一个弹出0,第二个弹出1...). ...

  4. [LeetCode258] Add Digits 非负整数各位相加

    题目: Given a non-negative integer num, repeatedly add all its digits until the result has only one di ...

  5. 【Android进阶】自定义控件实现底部扇形展开菜单效果

    这个项目是优化的其他人的,主要优化了界面菜单的显示,下面开始. 先看效果图 项目的总结构 下面开始贴代码,由于必要的地方都添加了注释,所以不过多讲解 anim_button.xml <?xml ...

  6. DataTable填补了实体类返回泛型集合

    坤哥见我昨天找了一段代码,如下面: 略微解释下,这段代码时D层查询结束后,将datatable查询到的结果赋值给实体对象的属性,然后返回实体的过程.坤哥看了之后问我,假设实体有500多个属性,难道也要 ...

  7. c++学籍管理系统v1.10

    //////////////新增添加学生和成绩录入系统 #include<iostream> #include <string> #include<conio.h> ...

  8. oracle查看经常使用的系统信息

    总结了查看oracle数据库的经常使用sql ,有助于分析优化出一个健壮的系统程序来. 1.当前的数据库连接数: select count(*) from v$process 2.数据库同意的最大连接 ...

  9. Linux 多学习过程

    1Linux流程概述 过程是,一旦运行过程中的程序,他和程序本质上的区别.程序是静态的,他奉命收集指令存储在磁盘上. 进程是动态的概念.他是执行者的程序,包括进程的动态创建.调度和消亡,是Linux的 ...

  10. Linux删除以破折号开头的文件Windows在批处理文件来删除隐藏属性

    昨天去打印店打印的材料.结果中毒.所有的文件被隐藏.生成一个一堆快捷键.回来后.我很容易地把它放入Linux机,我想删除这些文件怪. 下面是该过程,遇到的问题. 1.您无法删除'-'该文件的开头 最初 ...