首页 > 代码库 > kinect学习笔记(三)——深度数据的提取

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

一、创建Console工程

image

二、添加kinect引用

image

里面用引用,打开后

image

选择然后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);                            }                }            }        }    }}

四、效果图

image

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