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 iskinect 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 ><span >// 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 ><span > 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.
最后更新:2017-04-03 07:57:00
上一篇:
淘宝数据库OceanBase SQL编译器部分 源码阅读--生成物理查询计划
下一篇:
Picasso and Android-Universal-Image-Loader缓存框架
《Clojure程序设计》——导读
WebService——通过契约优先开发webservice
"0x00a1bdb3" 指令引用的 "0x00000001" 内存。该内存不能为 "read"。
就百度网页快照抓取时间的论点
谈谈分布式事务之一:SOA需要怎样的事务控制方式
java中的this关键字
Android Project Butter分析
9月29日云栖精选夜读:武装到“牙齿”!阿里云发布史上最强企业云安全架构 11层防护
Android锁屏未读短信,未接电话
完美的单例实现(The Perfect Singleton)