Kinect SDK C++ - 2. Kinect Depth Data
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的更多相关文章
- OpenCV、PCL;Xtion、kinect;OpenNI、kinect for windows SDK比较
一.对比介绍: 1. OpenCV:开源跨平台,OpenCV于1999年由Intel建立,如今由Willow Garage提供支持. 2. OpenNI:OpenNI组织创建于2010年11月.主要成 ...
- Kinect SDK(1):读取彩色、深度、骨骼信息并用OpenCV显示
Kinect SDK 读取彩色.深度.骨骼信息并用OpenCV显示 一.原理说明 对于原理相信大家都明白大致的情况,因此,在此只说比较特别的部分. 1.1 深度流数据: 深度数据流所提供的图像帧中,每 ...
- Kinect开发笔记之三Kinect开发环境配置具体解释
0.前言: 首先说一下我的开发环境,Visual Studio是2013的,系统是win8的64位版本号,SDK是Kinect for windows SDK 1.8版本 ...
- Kinect SDK 安装失败
错误提示:Kinect Management failed to start. 原因: 1, Kinect Management 服务相依的 Plug and Play的服务没有启动. 2,系统安装了 ...
- Kinect 开发 —— Hello,Kinect
控制台输出深度数据: using System; using System.Collections.Generic; using System.Linq; using System.Text; usi ...
- Kinect开发资源汇总
Kinect开发资源汇总 转自: http://www.sigvc.org/bbs/forum.php?mod=viewthread&tid=254&highlight=kinec ...
- 【翻译】Kinect v2程序设计(C++) Body 篇
Kinect SDK v2预览版的主要功能的使用介绍,基本上完成了.这次,是关于取得Body(人体姿势)方法的说明. 上一节,是使用Kinect SDK v2预览版从Kinect v2预览版取得B ...
- 【翻译】Kinect v2程序设计(C++) BodyIndex篇
通过Kinect SDK v2预览版,取得BodyIndex(人体区域)的方法和示例代码. 上一节,介绍了从Kinect v2预览版用Kinect SDK v2预览版获取Depth数据的方法. 这 ...
- 【翻译】Kinect v2程序设计(C++) Color篇
Kinect SDK v2预览版,获取数据的基本流程的说明.以及取得Color图像的示例程序的介绍. 上一节,是关于当前型号Kinect for Windows(后面称作Kinect v1)和次世代型 ...
随机推荐
- 匿名方法,Lambda表达式,高阶函数
原文:匿名方法,Lambda表达式,高阶函数 匿名方法 c#2.0引入匿名方法,不必创建单独的方法,因此减少了所需的编码系统开销. 常用于将委托和匿名方法关联,例如1. 使用委托和方法关联: this ...
- Gradle cookbook(转)
build.gradle apply plugin:"java" [compileJava,compileTestJava,javadoc]*.options*.encoding ...
- java计算器 图形用户界面 精简版
package com.rgy.entity; import java.awt.*; import java.awt.event.*; @SuppressWarnings("serial&q ...
- MFC 将文件拖进对话框获得文件信息
非常多软件都支持直接将文件拖进去进行处理的功能,详细一点如暴风影音,将视频或者音频文件拖进去就会自己主动開始播放,那么这个功能在MFC上面怎么实现的呢?事实上非常easy,过程例如以下: 第一步:将对 ...
- 查看SQLSERVER内部数据页面的小插件Internals Viewer
原文:查看SQLSERVER内部数据页面的小插件Internals Viewer 查看SQLSERVER内部数据页面的小插件Internals Viewer 感觉internals viewer这个名 ...
- Git显示漂亮日志的小技巧
Git的传统log如下所示,你喜欢吗? 看看下面这个你喜不喜欢?(点击图片看大图) 要做到这样,命令行如下: 1 git log --graph --pretty=format:'%Cred%h%Cr ...
- 为什么windows dos和Linux shell有这样的差别??
Windows dos随着impdp导入数据库: impdp "sys/password@ip:1521/sidname as sysdba" directory=dbdir du ...
- Android ListView分页载入(服务端+android端)Demo
Android ListView分页载入功能 在实际开发中经经常使用到,是每一个开发人员必须掌握的内容,本Demo给出了服务端+Android端的两者的代码,并成功通过了測试. 服务端使用MyEcli ...
- WindowState注意事项
本文将分析具体WindowState个别关键的成员变量和成员函数. Window #3 Window{20dd178e u0 com.android.mms/com.android.mms.ui.Co ...
- 大约linux的几个问题,你能回答几个?--回复14-20称号
14.select和poll差异?Poll和epoll的差别? (1)select和poll的差别:(參考:http://blog.csdn.net/mituan2008/article/detail ...