2014-02-21 2 views
0

여기까지 제 코드가 있습니다. 제가 Kinect로 코딩하는 법을 배우는 것만으로도 매우 기본입니다.Kinect 센서 (Windows) 스켈레톤 조인트 추적이 없습니다

KinectSensor Sensor = null; 

    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); 
      } 
     } 

     // Draw the skeleton. 
     if (skeletons.Length > 0) 
     { 
      drawSkeleton(skeletons[0]); 
     } 
    } 

    private void drawSkeleton(Skeleton skeleton) 
    { 
     // Dispose of the current image if applicable. 
     if (pctSkeleton.Image != null) 
     { 
      pctSkeleton.Image.Dispose(); 
     } 

     Image image = Image.FromFile(CanvasPath); 

     using (Graphics g = Graphics.FromImage(image)) 
     { 
      // If any joints aren't tracked, return. 
      foreach (Joint joint in skeleton.Joints) 
      { 
       if (joint.TrackingState == JointTrackingState.NotTracked) 
       { 
        return; 
       } 
      } 

      // Sort the 20 joints. 
      Joint head = skeleton.Joints[JointType.Head]; 
      Joint hipCenter = skeleton.Joints[JointType.HipCenter]; 
      Joint spine = skeleton.Joints[JointType.Spine]; 
      Joint shoulderCenter = skeleton.Joints[JointType.ShoulderCenter]; 
      Joint shoulderLeft = skeleton.Joints[JointType.ShoulderLeft]; 
      Joint elbowLeft = skeleton.Joints[JointType.ElbowLeft]; 
      Joint wristLeft = skeleton.Joints[JointType.WristLeft]; 
      Joint handLeft = skeleton.Joints[JointType.HandLeft]; 
      Joint shoulderRight = skeleton.Joints[JointType.ShoulderRight]; 
      Joint elbowRight = skeleton.Joints[JointType.ElbowRight]; 
      Joint wristRight = skeleton.Joints[JointType.WristRight]; 
      Joint handRight = skeleton.Joints[JointType.HandRight]; 
      Joint hipLeft = skeleton.Joints[JointType.HipLeft]; 
      Joint kneeLeft = skeleton.Joints[JointType.KneeLeft]; 
      Joint ankleLeft = skeleton.Joints[JointType.AnkleLeft]; 
      Joint footLeft = skeleton.Joints[JointType.FootLeft]; 
      Joint hipRight = skeleton.Joints[JointType.HipRight]; 
      Joint kneeRight = skeleton.Joints[JointType.KneeRight]; 
      Joint ankleRight = skeleton.Joints[JointType.AnkleRight]; 
      Joint footRight = skeleton.Joints[JointType.FootRight]; 

      Pen inBoundPen = new Pen(Brushes.Green, 3); 

      ///////////////////DRAW BONES//////////////////////// 
      // head => shoulder center. 
      g.DrawLine(inBoundPen, convertX(head.Position.X), convertY(head.Position.Y), convertX(shoulderCenter.Position.X), convertY(shoulderCenter.Position.Y)); 

      // shoulders => shoulder center. 
      g.DrawLine(inBoundPen, convertX(shoulderRight.Position.X), convertY(shoulderRight.Position.Y), convertX(shoulderCenter.Position.X), convertY(shoulderCenter.Position.Y)); 
      g.DrawLine(inBoundPen, convertX(shoulderLeft.Position.X), convertY(shoulderLeft.Position.Y), convertX(shoulderCenter.Position.X), convertY(shoulderCenter.Position.Y)); 

      // shoulder center => spine. 
      g.DrawLine(inBoundPen, convertX(shoulderCenter.Position.X), convertY(shoulderCenter.Position.Y), convertX(spine.Position.X), convertY(spine.Position.Y)); 

      // shoulder right => elbow right 
      g.DrawLine(inBoundPen, convertX(shoulderRight.Position.X), convertY(shoulderRight.Position.Y), convertX(elbowRight.Position.X), convertY(elbowRight.Position.Y)); 

      // elbow right => wrist right 
      g.DrawLine(inBoundPen, convertX(elbowRight.Position.X), convertY(elbowRight.Position.Y), convertX(wristRight.Position.X), convertY(wristRight.Position.Y)); 

      // wrist right => hand right 
      g.DrawLine(inBoundPen, convertX(wristRight.Position.X), convertY(wristRight.Position.Y), convertX(handRight.Position.X), convertY(handRight.Position.Y)); 

      // shoulder left => elbow left 
      g.DrawLine(inBoundPen, convertX(shoulderLeft.Position.X), convertY(shoulderLeft.Position.Y), convertX(elbowLeft.Position.X), convertY(elbowLeft.Position.Y)); 

      // elbow left => wrist left 
      g.DrawLine(inBoundPen, convertX(elbowLeft.Position.X), convertY(elbowLeft.Position.Y), convertX(wristLeft.Position.X), convertY(wristLeft.Position.Y)); 

      // wrist left => hand left 
      g.DrawLine(inBoundPen, convertX(wristLeft.Position.X), convertY(wristLeft.Position.Y), convertX(handLeft.Position.X), convertY(handLeft.Position.Y)); 

      // spine => hip center. 
      g.DrawLine(inBoundPen, convertX(spine.Position.X), convertY(spine.Position.Y), convertX(hipCenter.Position.X), convertY(hipCenter.Position.Y)); 

      // hips => hip center. 
      g.DrawLine(inBoundPen, convertX(hipCenter.Position.X), convertY(hipCenter.Position.Y), convertX(hipLeft.Position.X), convertY(hipLeft.Position.Y)); 
      g.DrawLine(inBoundPen, convertX(hipCenter.Position.X), convertY(hipCenter.Position.Y), convertX(hipRight.Position.X), convertY(hipRight.Position.Y)); 

      // hip left => knee left. 
      g.DrawLine(inBoundPen, convertX(hipLeft.Position.X), convertY(hipLeft.Position.Y), convertX(kneeLeft.Position.X), convertY(kneeLeft.Position.Y)); 

      // knee left => ankle left. 
      g.DrawLine(inBoundPen, convertX(kneeLeft.Position.X), convertY(kneeLeft.Position.Y), convertX(ankleLeft.Position.X), convertY(ankleLeft.Position.Y)); 

      // ankle left => foot left. 
      g.DrawLine(inBoundPen, convertX(ankleLeft.Position.X), convertY(ankleLeft.Position.Y), convertX(footLeft.Position.X), convertY(footLeft.Position.Y)); 

      // hip right => knee right. 
      g.DrawLine(inBoundPen, convertX(hipRight.Position.X), convertY(hipRight.Position.Y), convertX(kneeRight.Position.X), convertY(kneeRight.Position.Y)); 

      // knee right => ankle right. 
      g.DrawLine(inBoundPen, convertX(kneeRight.Position.X), convertY(kneeRight.Position.Y), convertX(ankleRight.Position.X), convertY(ankleRight.Position.Y)); 

      // ankle right => foot right. 
      g.DrawLine(inBoundPen, convertX(ankleRight.Position.X), convertY(ankleRight.Position.Y), convertX(footRight.Position.X), convertY(footRight.Position.Y)); 
      //////////////////////////////////////////////// 

      pctSkeleton.Image = image; 
     } 
    } 

    private float convertX(float x) 
    { 
     return (pctSkeleton.Width/2) + (x * 100); 
    } 

    private float convertY(float y) 
    { 
     return (pctSkeleton.Height/2) - (y * 100); 
    } 

    private void button2_Click(object sender, EventArgs e) 
    { 
     // Get the first sensor 
     Sensor = KinectSensor.KinectSensors[0]; 

     // Enable the skeleton and video streams. 
     Sensor.SkeletonStream.Enable(); 
     Sensor.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30); 

     // Set the event handlers 
     Sensor.SkeletonFrameReady += SensorSkeletonFrameReady; 
     Sensor.ColorFrameReady += SensorColorFrameReady; 

     // Start the kinect. 
     Sensor.Start(); 
    } 

어떤 이유로 센서가 대부분의 시간 동안 골격을 추적하지 않습니다. 그것은 약 20 %의 시간 그러나 작동합니다. 중단 점을 설정할 때 관절이 추적되지 않은 것으로 표시됩니다. 나는 이것에 대해 새로운 것이므로, 내가 잘못하고있는 것에 관한 어떠한 정보도 크게 감사 할 것입니다.

답변

1

20 개의 모든 관절을 추적하면 응용 프로그램에서 스켈레톤 만 그립니다. 단일 관절이 추적되지 않으면 (예 : 왼쪽 발목) 응용 프로그램은 아무 것도하지 않습니다. 센서가 모든 관절을 감지 할 수 있다는 것은 매우 드뭅니다.

kinect developer toolkit에는 관절이 추적되지 않을 때 더 용서가되는 "SkeletonBasics-WPF"라는 샘플이 있습니다.