none
saving depth and hand joint information to a file RRS feed

Answers

  • Ravi Mistry,

    If you only want the text file to have joint coordinates for both hands, then you should use data from skeleton frame instead of data from depth image. If you add following code to nui_SkeletonFrameReady method in managed SkeletalViewer sample it should do what you want.

    StreamWriter writer = new StreamWriter("myfile.txt");
     
    writer.WriteLine("LX LY LZ RX RY RZ");
    
    foreach (SkeletonData tracked in (from s in skeletonFrame.Skeletons where s.TrackingState == SkeletonTrackingState.Tracked select s))
    {
        Microsoft.Research.Kinect.Nui.Vector leftHand = tracked.Joints[JointID.HandLeft].Position;
        Microsoft.Research.Kinect.Nui.Vector rightHand = tracked.Joints[JointID.HandRight].Position;
    
        writer.WriteLine(leftHand .X +" "+ leftHand .Y +" "+ leftHand .Z + " " + rightHand .X +" "+ rightHand .Y +" "+ rightHand .Z);
    }
     
    writer.Close();
    

    Hope that helps,
    Eddy


    I'm here to help
    Wednesday, September 7, 2011 9:46 PM

All replies

  • Hi Escorciav,

    First thanks for the response. I am successful to get data from three coordinates.

    First problem is i do not know what point it is detecting (e.g. head, handright, handleft, etc). And second problem is it kills my frames per seconds rate from 30fps to 6-10fps(depending on cpu performance) Currently I am applying following code: 

    (http://social.msdn.microsoft.com/Forums/en-US/kinectsdknuiapi/thread/879d43e6-0dd3-4d2d-be49-81b4202c0676/?prof=required)

    StreamWriter writer = new StreamWriter("myfile.txt");

            writer.WriteLine("X Y Z");

                for (int i = 0; i < Image.Bits.Length; i += 2)

                 {

               int depthPixel = (Image.Bits[i+1] << 8) | Image.Bits[i];

               int x = (i/2) % 320; // Because image width is 320 pixels

               int y = (i/2) / 320;

     

       Microsoft.Research.Kinect.Nui.Vector realWorldPos = 

    nui.SkeletonEngine.DepthImageToSkeleton(((float)x)/320.0f, ((float)y)/240.0f, (short)depthPixel);

           // Store value of realWorldPos

       writer.WriteLine(realWorldPos.X +" "+ realWorldPos.Y +" "+ realWorldPos.Z);

                }

            writer.Close();

     

    Primarily I want to know where exactly should I apply this part of code and what modification I need to make in order to get only both hands' data in the textfile. 

    Thanks in advance. Your help will be highly appreciated.

     

    Wednesday, September 7, 2011 6:17 PM
  • Ravi Mistry,

    If you only want the text file to have joint coordinates for both hands, then you should use data from skeleton frame instead of data from depth image. If you add following code to nui_SkeletonFrameReady method in managed SkeletalViewer sample it should do what you want.

    StreamWriter writer = new StreamWriter("myfile.txt");
     
    writer.WriteLine("LX LY LZ RX RY RZ");
    
    foreach (SkeletonData tracked in (from s in skeletonFrame.Skeletons where s.TrackingState == SkeletonTrackingState.Tracked select s))
    {
        Microsoft.Research.Kinect.Nui.Vector leftHand = tracked.Joints[JointID.HandLeft].Position;
        Microsoft.Research.Kinect.Nui.Vector rightHand = tracked.Joints[JointID.HandRight].Position;
    
        writer.WriteLine(leftHand .X +" "+ leftHand .Y +" "+ leftHand .Z + " " + rightHand .X +" "+ rightHand .Y +" "+ rightHand .Z);
    }
     
    writer.Close();
    

    Hope that helps,
    Eddy


    I'm here to help
    Wednesday, September 7, 2011 9:46 PM
  • Hello Eddy,

    First, thank you so much for providing proper direction and code. It is very helpful. I followed your guidance and been able to pullout both hands' coordinates, the only thing is It do not provide me data throughout the trial. Just provides me one line for any certain instance. Can you please help me with this small part?

     

    Thanks for your help again.

    Tuesday, September 13, 2011 4:54 PM
  • Do you mean that your nui_SkeletonFrameReady event handler only gets called once (e.g.: if you set a breakpoint), or what else do you mean? Maybe if you create the StreamWriter as

    StreamWriter writer = new StreamWriter("myfile.txt", true);
    

    it will do what you expect?

    Eddy


    I'm here to help
    Tuesday, September 13, 2011 7:29 PM
  • Thanks Eddy.

    It works. I really appreciate your help.

    Apology for late response.

    Thursday, November 10, 2011 9:09 PM
  • Where exactly can I inject this code in the SDK 1.8 version? I am working on Kinect Explorer and I actually want to store all joint positions, not only the hands. 

    thank you

    Wednesday, May 7, 2014 11:42 AM
  • please post your question and link to previous threads if they are related. There are several threads that discuss saving data to files. This is not a function of the Kinect for Windows SDK, we only provide you frame data.

    http://social.msdn.microsoft.com/Forums/en-US/c6b1238e-d59d-45fa-a2cb-3d04c469c2fa/saving-skeletal-coordinates-to-file-based-on-kinect-explorer?forum=kinectsdknuiapi


    Carmine Sirignano - MSFT

    Wednesday, May 7, 2014 7:19 PM