I am trying to catch joint X, Y, Z positions and write them into txt file on button click. Everything is fine, but every time, I get 0, 0, 0 for X,Y,Z. What could be wrong? My app is also displaying / drawing the skeleton, so I guess that it should have the positions of each joint. I even tried to print X position of head joint to the textbox in the drawing method, but with same result (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);
   }
  }
有帮助吗?

解决方案

You have to start the sensor, subscribe to the SkeletonFrameReady event and update the positions in the eventhandler. Starting to Develop with Kinect might be useful for you.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top