2014-02-21 68 views

回答

1

謝謝,但它有一個問題,'骨架'在這一行: 骨架骨架=(從s在骨架s.TrackingState == SkeletonTrackingState.Tracked選擇s); System.IO.FileStream fs = new System.IO.FileStream(@「F:\ Kinect Install \ SkeletonBasics-WPF \ Coordinates.txt」,FileMode.Append,FileAccess.Write,FileShare.None); int frame = 0; Skeleton [] skeletons = new Skeleton [0];

public void AllFramesReady(object sender, AllFramesReadyEventArgs e) 
    { 
     StreamWriter sw = new StreamWriter(fs); 
     frame++; 
     using (SkeletonFrame sFrame = e.OpenSkeletonFrame()) 
     { 
      if (sFrame == null) return; 

      sFrame.CopySkeletonDataTo(skeletons); 
      Skeleton skeleton = (from s in skeletons where s.TrackingState == SkeletonTrackingState.Tracked select s); 
      if (skeleton == null) 
       return; 

      if (skeleton.TrackingState == SkeletonTrackingState.Tracked) 
      { 
       foreach (Joint joint in skeleton.Joints) 
       { 
        sw.WriteLine(joint.Position.X + "," + joint.Position.Y + "," + joint.Position.Z + ","); 
       } 
       //writer.Write(Environment.NewLine); 
       sw.Flush(); 
       sw.Close(); 
      } 
     } 
    } 
+0

你可以接受你自己的答案 –

2

如果您使用的是SDK:

using System.IO; 

StreamWriter writer = new StreamWriter(@path); 
int frames = 0; 

... 

void AllFramesReady(object sender, AllFramesReadyEventArgs e) 
{ 
    frames++; 
    using (SkeletonFrame sFrame = e.OpenSkeletonFrameData()) 
    { 
     if (sFrame == null) 
      return; 

     skeletonFrame.CopySkeletonDataTo(skeletons); 

     Skeleton skeleton = (from s in skeletons 
           where s.TrackingState == SkeletonTrackingState.Tracked 
           select s); 
     if (skeleton == null) 
      return; 

     if (skeleton.TrackingState == SkeletonTrackingState.Tracked) 
     { 
      writer.Write("{0} {1}@", frames, timestamp);//I dont know how you want to do this 
      foreach (Joint joint in skeleton.Joints) 
      { 
       writer.Write(joint.Position.X + "," + joint.Position.Y + "," joint.Position.Z + ","); 
      } 
      writer.Write(Environment.NewLine); 
     } 
    } 
} 

這需要檢測骨骼的關節,並沒有指定其相對關節把它們寫到一個文件,但它是在聯合類型的默認順序。請注意,這是距離kinect傳感器的距離。

+0

謝謝,但它有一個問題'骨架' – iamatsundere181

+0

@ iamatsundere181你能詳細說明嗎? –

+0

好吧,我知道了,它工作 – iamatsundere181