• 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

  • 相关阅读:
    cURL(wget)—— 测试 RESTful 接口及模拟 GET/POST/PUT/DELETE/OPTIONS 请求
    docker 第一课 —— 从容器到 docker
    docker 第一课 —— 从容器到 docker
    多类 SVM 的损失函数及其梯度计算
    软RAID 0的技术概要及实现
    用 Linux blkid 命令查找块设备详情
    常用命令
    Ubuntu---samba(安装、配置、使用)***
    系统常用命令
    在64位的UBUBTU 服务器 ***
  • 原文地址:https://www.cnblogs.com/BlueMountain-HaggenDazs/p/4072593.html
Copyright © 2020-2023  润新知