原始深度数据到文本kinect v1.0 C#

原始深度数据到文本kinect v1.0 C#,c#,text,kinect,depth,C#,Text,Kinect,Depth,我一直在网上搜索,但我一点运气都没有。我正在使用Xbox Kinect和Kinect SDK v1.0。我想获取原始深度数据并将其转换为文本文档,以便使用深度数据。我在这个网站上找到了一些东西,但它是针对Beta2的,我需要使用v1.0。任何帮助是感激的,但我是新的编码,所以样本代码将是最好的 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Win

我一直在网上搜索,但我一点运气都没有。我正在使用Xbox Kinect和Kinect SDK v1.0。我想获取原始深度数据并将其转换为文本文档,以便使用深度数据。我在这个网站上找到了一些东西,但它是针对Beta2的,我需要使用v1.0。任何帮助是感激的,但我是新的编码,所以样本代码将是最好的

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Kinect;
using System.Diagnostics;
using System.IO;

namespace DepthTextStream
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
    }

    const float MaxDepthDistance = 4095; // max value returned
    const float MinDepthDistance = 850; // min value returned
    const float MaxDepthDistanceOffset = MaxDepthDistance - MinDepthDistance;

    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        kinectSensorChooser1.KinectSensorChanged += new DependencyPropertyChangedEventHandler(kinectSensorChooser1_KinectSensorChanged);

    }

    void kinectSensorChooser1_KinectSensorChanged(object sender, DependencyPropertyChangedEventArgs e)
    {

        var oldSensor = (KinectSensor)e.OldValue;

        //stop the old sensor
        if (oldSensor != null)
        {
            oldSensor.Stop();
            oldSensor.AudioSource.Stop();
        }

        //get the new sensor
        var newSensor = (KinectSensor)e.NewValue;
        if (newSensor == null)
        {
            return;
        }

        //turn on features that you need
        newSensor.DepthStream.Enable(DepthImageFormat.Resolution320x240Fps30);
        newSensor.SkeletonStream.Enable(); 

        //sign up for events if you want to get at API directly
        newSensor.AllFramesReady += new EventHandler<AllFramesReadyEventArgs>(newSensor_AllFramesReady);


        try
        {
            newSensor.Start();
        }
        catch (System.IO.IOException)
        {
            //this happens if another app is using the Kinect
            kinectSensorChooser1.AppConflictOccurred();
        }
    }

    void newSensor_AllFramesReady(object sender, AllFramesReadyEventArgs e)
    {
        short[] depthData;

        using (DepthImageFrame depthFrame = e.OpenDepthImageFrame()) //create a new frame every time one is ready
    {
    //assign a value to depthData
    depthData = new short[depthFrame.PixelDataLength];
    } 

    }


    private void SaveDepthData(short[] depthData)
    {
        //initialize a StreamWriter
        StreamWriter sw = new StreamWriter(@"C:/Example.txt");

        //search the depth data and add it to the file
        for (int i = 0; i < depthData.Length; i++)
        {
            sw.WriteLine(depthData[i] + "\n"); //\n for a new line
        }

        //dispose of sw
        sw.Close();
        SaveDepthData(depthData);
    }      

    private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
    {
        StopKinect(kinectSensorChooser1.Kinect); 
    }

    private void StopKinect(KinectSensor sensor)
    {
        if (sensor != null)
        {
            if (sensor.IsRunning)
            {
                //stop sensor 
                sensor.Stop();

                //stop audio if not null
                if (sensor.AudioSource != null)
                {
                    sensor.AudioSource.Stop();
                }
            }
        }
    } 
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Windows;
使用System.Windows.Controls;
使用System.Windows.Data;
使用System.Windows.Documents;
使用System.Windows.Input;
使用System.Windows.Media;
使用System.Windows.Media.Imaging;
使用System.Windows.Navigation;
使用System.Windows.Shapes;
使用Microsoft.Kinect;
使用系统诊断;
使用System.IO;
命名空间深度文本流
{
/// 
///MainWindow.xaml的交互逻辑
/// 
公共部分类主窗口:窗口
{
公共主窗口()
{
初始化组件();
}
const float MaxDepthDistance=4095;//返回的最大值
const float MinDepthDistance=850;//返回的最小值
常量浮点MaxDepthDistanceOffset=MaxDepthDistance-MinDepthDistance;
已加载私有无效窗口(对象发送器、路由目标)
{
kinectSensorChooser1.KinectSensorChanged+=新的从属属性更改Deventhandler(kinectSensorChooser1\u KinectSensorChanged);
}
无效kinectSensorChooser1\u KinectSensorChanged(对象发送器,从属属性更改Deventargs e)
{
var oldSensor=(KinectSensor)e.OldValue;
//停止旧的传感器
如果(旧传感器!=null)
{
oldSensor.Stop();
oldSensor.AudioSource.Stop();
}
//去拿新的传感器
var newSensor=(KinectSensor)e.NewValue;
if(newSensor==null)
{
返回;
}
//打开所需的功能
newSensor.depthream.Enable(DepthImageFormat.Resolution320x240Fps30);
newSensor.SkeletonStream.Enable();
//如果您想直接访问API,请注册参加活动
newSensor.AllFramesReady+=新事件处理程序(newSensor_AllFramesReady);
尝试
{
newSensor.Start();
}
捕获(System.IO.IOException)
{
//如果其他应用程序正在使用Kinect,则会发生这种情况
kinectSensorChooser1.AppConflictOccurd();
}
}
void newSensor_AllFramesReady(对象发送方,AllFramesReadyEventArgs e)
{
短[]深度数据;
使用(DepthImageFrame depthrframe=e.OpenDepthImageFrame())//每次准备好一个新帧时都创建一个新帧
{
//为depthData指定一个值
depthData=新短[depthFrame.PixelDataLength];
} 
}
私有void SaveDepthData(short[]depthData)
{
//初始化StreamWriter
StreamWriter sw=新的StreamWriter(@“C:/Example.txt”);
//搜索深度数据并将其添加到文件中
for(int i=0;i

}

使用1.5.0.1版非常简单,它实际上与1.0版相同,可以使用。您只需完成以下操作:A)A
short[]
保存深度数据B)A
DepthImageFrame
将数据移动到阵列,C)A
StreamWriter
保存数据

添加一个
short[]
来存储深度数据,并在
DepthFrameReadyEventArgs
(或
AllFramesReadyEventArgs
)的内部通过以下操作“使用”一个
DepthImageFrame

 short[] depthData;

 ...

 using (DepthImageFrame depthFrame = e.OpenDepthImageFrame(()) //create a new frame every time one is ready
 {
       //assign a value to depthData
       depthData = new short[depthFrame.PixelDataLength];
 } 
然后,您可以使用
DepthImageFrame.CopyPixelDataTo将每个帧的深度添加到
depthData

 using (DepthImageFrame depthFrame = e.OpenDepthImageFrame(()) //create a new frame every time one is ready
 {
       //assign a value to depthData
       depthData = new short[depthFrame.PixelDataLength];

       //add raw depth data to depthData
       depthFrame.CopyPixelDataTo(depthData);
 } 
然后,我们可以使用
StreamWriter
编写保存数据的方法

 private void SaveDepthData(short[] depthData)
 {
       //initialize a StreamWriter
       StreamWriter sw = new StreamWriter(@"C:/Example.txt");

       //search the depth data and add it to the file
       for (int i = 0; i < depthData.Length; i++)
       {
            sw.WriteLine(depthData[i] + "\n"); //\n for a new line
       }

       //dispose of sw
       sw.Close();
 }      

 ...

 SaveDepthData(depthData);
private void SaveDepthData(short[]depthData)
{
//初始化StreamWriter
StreamWriter sw=新的StreamWriter(@“C:/Example.txt”);
//搜索深度数据并将其添加到文件中
for(int i=0;i

希望这有帮助

使用1.5.0.1版非常简单,它实际上与1.0版相同,可以使用。您只需完成以下操作:A)A
short[]
保存深度数据B)A
DepthImageFrame
将数据移动到阵列,C)A
StreamWriter
保存数据

添加一个
short[]
来存储深度数据,并在
DepthFrameReadyEventArgs
(或
AllFramesReadyEventArgs
)的内部通过以下操作“使用”一个
DepthImageFrame

 short[] depthData;

 ...

 using (DepthImageFrame depthFrame = e.OpenDepthImageFrame(()) //create a new frame every time one is ready
 {
       //assign a value to depthData
       depthData = new short[depthFrame.PixelDataLength];
 } 
然后,您可以使用
DepthImageFrame.CopyPixelDataTo将每个帧的深度添加到
depthData

 using (DepthImageFrame depthFrame = e.OpenDepthImageFrame(()) //create a new frame every time one is ready
 {
       //assign a value to depthData
       depthData = new short[depthFrame.PixelDataLength];

       //add raw depth data to depthData
       depthFrame.CopyPixelDataTo(depthData);
 } 
然后,我们可以使用
StreamWriter
编写保存数据的方法

 private void SaveDepthData(short[] depthData)
 {
       //initialize a StreamWriter
       StreamWriter sw = new StreamWriter(@"C:/Example.txt");

       //search the depth data and add it to the file
       for (int i = 0; i < depthData.Length; i++)
       {
            sw.WriteLine(depthData[i] + "\n"); //\n for a new line
       }

       //dispose of sw
       sw.Close();
 }      

 ...

 SaveDepthData(depthData);
private void SaveDepthData(short[]depthData)
{
//初始化StreamWriter
StreamWriter sw=新的StreamWriter(@“C:/Example.txt”);
//搜索深度数据并将其添加到文件中
对于(int i=0