您的位置:首页 > 其它

kinect学习笔记(三)——深度数据的提取

2014-11-04 00:24 459 查看
一、创建Console工程





二、添加kinect引用





里面用引用,打开后





选择然后OK。

三、编写代码(有附加注释)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Kinect;

namespace DepthCout
{
class Program
{
static void Main(string[] args)
{
if (KinectSensor.KinectSensors.Count > 0)
{
//设置控制台前景色
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Welecome to the Kinect Matrix");

//默认选择使用第一个kinect传感器= =
KinectSensor _kinect = KinectSensor.KinectSensors[0];

//打开红外摄像头的默认选项
_kinect.DepthStream.Enable();

//注册事件,启动Kinect
_kinect.DepthFrameReady += new EventHandler<DepthImageFrameReadyEventArgs>(_kinect_DepthFrameReady);
_kinect.Start();

//按回车键退出
while (Console.ReadKey().Key != ConsoleKey.Spacebar)
{

}

//关闭kinect
_kinect.Stop();
Console.WriteLine("Exit the Kinect Matrix");
}
else
{
Console.WriteLine("Exit the Kinect Matirx");
}

}

static void _kinect_DepthFrameReady(object sender,DepthImageFrameReadyEventArgs e)
{
//获取kinect摄像头的深度数据,然后打印到console上
using(DepthImageFrame depthFrame = e.OpenDepthImageFrame())
{
if(depthFrame!=null)
{
short[] depthPixelDate = new short[depthFrame.PixelDataLength];
depthFrame.CopyPixelDataTo(depthPixelDate);

foreach(short pixel in depthPixelDate)
{
Console.Write(pixel);

}
}
}
}

}
}


四、效果图



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐