Search code examples
c#kinectkinect-sdk

Write Kinect joint positions to txt on button click


I would like to write joint positions to a txt file. I have a method to get the X,Y,Z positions of one joint.

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

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

and I have my click method

  private void stoji_Click(object sender, RoutedEventArgs e)
    {

           File.AppendAllText(@"E:\skuska.txt", rightX + ", " + rightY + ", " +rightZ + Environment.NewLine);

    }

But obviously the rightX, rightY and rightZ cannot be seen from onclick method. And if I add the code from positions method to onclick method, it does not recognize "skeleton".

Thank you


Solution

  • Make rightX, rightY, rightZ instance variables of your class.

    public class MyKinect
    {
       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;     
       }
    
       private void stoji_Click(object sender, RoutedEventArgs e)
       {
          File.AppendAllText(@"E:\skuska.txt", rightX + ", " + rightY + ", " +rightZ + Environment.NewLine);
        }
    }