博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Kinect SDK C++ - 2. Kinect Depth Data
阅读量:5132 次
发布时间:2019-06-13

本文共 2489 字,大约阅读时间需要 8 分钟。

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
// NEW VARIABLEHANDLE 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.
      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;        }
that's all the Kinect code! The rest is just how to get it to display.

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

转载于:https://www.cnblogs.com/zfyouxi/p/4615179.html

你可能感兴趣的文章
TextArea中定位光标位置
查看>>
非常棒的Visual Studo调试插件:OzCode 2.0 下载地址
查看>>
判断字符串在字符串中
查看>>
hdu4374One hundred layer (DP+单调队列)
查看>>
类间关系总结
查看>>
properties配置文件读写,追加
查看>>
Linux环境下MySql安装和常见问题的解决
查看>>
lrzsz——一款好用的文件互传工具
查看>>
ZPL语言完成条形码的打印
查看>>
这20件事千万不要对自己做!
查看>>
Linux环境下Redis安装和常见问题的解决
查看>>
玩转小程序之文件读写
查看>>
HashPump用法
查看>>
cuda基础
查看>>
virutalenv一次行安装多个requirements里的文件
查看>>
Vue安装准备工作
查看>>
.NET 母版页 讲解
查看>>
Android Bitmap 和 Canvas详解
查看>>
最大权闭合子图
查看>>
oracle 创建暂时表
查看>>