Kinect关节位置X,Y,Z始终= 0

时间:2014-03-01 14:49:22

标签: c# kinect kinect-sdk

我正在尝试捕捉关节X,Y,Z位置,并在按钮点击时将它们写入txt文件。 一切都很好,但每次,我得到0,0,0为X,Y,Z。 可能有什么不对? 我的应用程序也显示/绘制骨架,所以我猜它应该有每个关节的位置。我甚至尝试在绘图方法中将头部关节的X位置打印到文本框,但结果相同(X = 0)。

using System;
using System.Collections.Generic;
using System.Linq; 
using System.Windows; 
using System.Windows.Media; 
using Microsoft.Kinect; 
using System.IO;

namespace WpfApplication1
{
    public partial class MainWindow : Window
    {


  private double rightX;
  private double rightY;
  private double rightZ;

  public void positions(Skeleton skeleton)
  {
  // get the joint
  Joint rightHand = skeleton.Joints[JointType.HandRight];

  // get the individual points of the right hand
  rightX = rightHand.Position.X;
  rightY = rightHand.Position.Y;
  rightZ = rightHand.Position.Z;     
  }



 void sensor_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
    {
        //declare an array of Skeletons
        Skeleton[] skeletons = new Skeleton[1];

        //Opens a SkeletonFrame object, which contains one frame of skeleton data.
        using (SkeletonFrame skeletonframe = e.OpenSkeletonFrame())
        {
            //Check if the Frame is Indeed open 
            if (skeletonframe != null)
            {

                skeletons = new Skeleton[skeletonframe.SkeletonArrayLength];

                // Copies skeleton data to an array of Skeletons, where each Skeleton contains a collection of the joints.
                skeletonframe.CopySkeletonDataTo(skeletons);

                //draw the Skeleton based on the Default Mode(Standing), "Seated"
                if (sensor.SkeletonStream.TrackingMode == SkeletonTrackingMode.Default)
                {
                    //Draw standing Skeleton
                    DrawStandingSkeletons(skeletons);
                }
                else if (sensor.SkeletonStream.TrackingMode == SkeletonTrackingMode.Seated)
                {
                    //Draw a Seated Skeleton with 10 joints
                    DrawSeatedSkeletons(skeletons);
                }
            }

        }

    }



  private void stoji_Click(object sender, RoutedEventArgs e)
  {
  File.AppendAllText(@"E:\skuska.txt", rightX + ", " + rightY + ", " +rightZ + Environment.NewLine);
   }
  }

1 个答案:

答案 0 :(得分:2)

您必须启动传感器,订阅SkeletonFrameReady事件并更新事件处理程序中的位置。 Starting to Develop with Kinect可能对您有用。