2014-12-24 2 views
0

나는 kinect에서 초보자이며 matlab에 사용하고 싶습니다. 해골 데이터에서 조인트 각도 정보가 필요합니다. 가장 쉬운 방법은 무엇입니까? 감사합니다. .Kinect-Matlab : 관절 각도 정보 얻기

답변

3

나는 매트 실험실 좋은하지 오전 이미지 수집 도구 상자가 필요하지만, 비주얼 스튜디오와 C#을 사용하려고합니다. 이 코드를 추가 할 템플릿으로 마이크로 소프트 SDK's의 SkeletonBasics-WPF를 사용

public class Angles 
    { 
    public double AngleBetweenTwoVectors(Vector3D vectorA, Vector3D vectorB) 
     { 
      double dotProduct; 
      vectorA.Normalize(); 
      vectorB.Normalize(); 
      dotProduct = Vector3D.DotProduct(vectorA, vectorB); 

      return (double)Math.Acos(dotProduct)/Math.PI*180; 
     } 

     public byte[] GetVector(Skeleton skeleton) 
     { 
      Vector3D ShoulderCenter = new Vector3D(skeleton.Joints[JointType.ShoulderCenter].Position.X, skeleton.Joints[JointType.ShoulderCenter].Position.Y, skeleton.Joints[JointType.ShoulderCenter].Position.Z); 
      Vector3D RightShoulder = new Vector3D(skeleton.Joints[JointType.ShoulderRight].Position.X, skeleton.Joints[JointType.ShoulderRight].Position.Y, skeleton.Joints[JointType.ShoulderRight].Position.Z); 
      Vector3D LeftShoulder = new Vector3D(skeleton.Joints[JointType.ShoulderLeft].Position.X, skeleton.Joints[JointType.ShoulderLeft].Position.Y, skeleton.Joints[JointType.ShoulderLeft].Position.Z); 
      Vector3D RightElbow = new Vector3D(skeleton.Joints[JointType.ElbowRight].Position.X, skeleton.Joints[JointType.ElbowRight].Position.Y, skeleton.Joints[JointType.ElbowRight].Position.Z); 
      Vector3D LeftElbow = new Vector3D(skeleton.Joints[JointType.ElbowLeft].Position.X, skeleton.Joints[JointType.ElbowLeft].Position.Y, skeleton.Joints[JointType.ElbowLeft].Position.Z); 
      Vector3D RightWrist = new Vector3D(skeleton.Joints[JointType.WristRight].Position.X, skeleton.Joints[JointType.WristRight].Position.Y, skeleton.Joints[JointType.WristRight].Position.Z); 
      Vector3D LeftWrist = new Vector3D(skeleton.Joints[JointType.WristLeft].Position.X, skeleton.Joints[JointType.WristLeft].Position.Y, skeleton.Joints[JointType.WristLeft].Position.Z); 
      Vector3D UpVector = new Vector3D(0.0, 1.0, 0.0); 

      double AngleRightElbow = AngleBetweenTwoVectors(RightElbow - RightShoulder, RightElbow - RightWrist); 
      double AngleRightShoulder = AngleBetweenTwoVectors(UpVector, RightShoulder - RightElbow); 
      double AngleLeftElbow = AngleBetweenTwoVectors(LeftElbow - LeftShoulder, LeftElbow - LeftWrist); 
      double AngleLeftShoulder = AngleBetweenTwoVectors(UpVector, LeftShoulder - LeftElbow); 


      byte[] Angles = {Convert.ToByte(AngleRightElbow), Convert.ToByte(AngleRightShoulder),Convert.ToByte(AngleLeftElbow),Convert.ToByte(AngleLeftShoulder)}; 
      return Angles; 
     } 
} 

는 상단이 삽입합니다. 여기에 GetVector() 메서드를 호출 : 당신이 볼 수 있듯이 내가 네 각도 (RS, LF, RE, LE)를 계산하고 같은

private void SensorSkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e) 
     { 

      Skeleton[] skeletons = new Skeleton[0]; 

      using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame()) 
      { 
       if (skeletonFrame != null) 
       { 
        skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength]; 
        skeletonFrame.CopySkeletonDataTo(skeletons); 

       } 
      } 

      using (DrawingContext dc = this.drawingGroup.Open()) 
      { 
       // Draw a transparent background to set the render size 
       dc.DrawRectangle(Brushes.Black, null, new Rect(0.0, 0.0, RenderWidth, RenderHeight)); 

       if (skeletons.Length != 0) 
       { 
        foreach (Skeleton skel in skeletons) 
        { 
         RenderClippedEdges(skel, dc); 

         if (skel.TrackingState == SkeletonTrackingState.Tracked) 
         { 
          this.DrawBonesAndJoints(skel, dc); 
          Angles MyAngles = new Angles(); 
          byte[] ReadyAngles = MyAngles.GetVector(skel); 
          RightElbow.Text = ReadyAngles[0].ToString(); 
          RightShoulder.Text = ReadyAngles[1].ToString(); 
          LeftElbow.Text = ReadyAngles[2].ToString(); 
          LeftShoulder.Text = ReadyAngles[3].ToString(); 
          byte[] SequenceStart = {255}; 

          if (ArduinoPort.IsOpen) 
          { 
           ArduinoPort.Write(SequenceStart,0,1); 
           ArduinoPort.Write(ReadyAngles, 0, 4); 
          } 
         } 
         else if (skel.TrackingState == SkeletonTrackingState.PositionOnly) 
         { 
          dc.DrawEllipse(
          this.centerPointBrush, 
          null, 
          this.SkeletonPointToScreen(skel.Position), 
          BodyCenterThickness, 
          BodyCenterThickness); 
         } 
        } 
       } 

       // prevent drawing outside of our render area 
       this.drawingGroup.ClipGeometry = new RectangleGeometry(new Rect(0.0, 0.0, RenderWidth, RenderHeight)); 
      } 
     } 

나는 4 텍스트 상자를 추가했습니다. 이 앵글은 내 .xaml 파일의 텍스트 상자로 전달됩니다. 나는 이것이 당신을 위해 일하기를 바랍니다.