2014-11-20 2 views
1

첫 번째 사람을 추적하고이 사람의 몸만 사용하고 싶습니다.C#에서 Kinect v2로 한 사람/몸만 추적하는 방법

기본적으로 한 사람을 추적하고 그 사람 뒤에서 걷는 사람들이 있거나이 사람을보고있을 때, 움직이면 kinect는 다른 사람을 인식해서는 안됩니다.

C#의 SDK 2.0 "Body Basics-WPF"의 샘플 코드를 사용하고 있습니다. 내 목표는 단 하나의 사람을 형성하는 몇 개의 관절 (성공적으로 완료) 만 인식하는 것입니다. Kinect v1을 어떻게 만들 수 있는지는 실감이지만 Kinect v2는 없습니다. 여기에 코드 :

private void Reader_FrameArrived(object sender, BodyFrameArrivedEventArgs e) 
    { 
     bool dataReceived = false; 

     using (BodyFrame bodyFrame = e.FrameReference.AcquireFrame()) 
     { 
      if (bodyFrame != null) 
      { 
       if (this.bodies == null) 
       { 
        this.bodies = new Body[bodyFrame.BodyCount]; 
       } 

       bodyFrame.GetAndRefreshBodyData(this.bodies); 
       dataReceived = true; 
      } 
     } 

     if (dataReceived) 
     { 
      using (DrawingContext dc = this.drawingGroup.Open()) 
      { 
       dc.DrawRectangle(Brushes.Black, null, new Rect(0.0, 0.0, this.displayWidth, this.displayHeight)); 

       int penIndex = 0; 

       foreach (Body body in this.bodies) 
       { 

        Pen drawPen = this.bodyColors[penIndex++]; 

        if (body.IsTracked) 
        { 
         this.DrawClippedEdges(body, dc); 

         IReadOnlyDictionary<JointType, Joint> joints = body.Joints; 
         Dictionary<JointType, Point> jointPoints = new Dictionary<JointType, Point>(); 

         foreach (JointType jointType in joints.Keys) 
         { 
          if (jointType == JointType.ShoulderRight || jointType == JointType.ElbowRight || jointType == JointType.WristRight || jointType == JointType.HandRight || 
           jointType == JointType.ShoulderLeft || jointType == JointType.ElbowLeft || jointType == JointType.WristLeft || jointType == JointType.HandLeft) 
          { 

           CameraSpacePoint position = joints[jointType].Position; 
           if (position.Z < 0) 
           { 
            position.Z = InferredZPositionClamp; 
           } 

           DepthSpacePoint depthSpacePoint = this.coordinateMapper.MapCameraPointToDepthSpace(position); 
           jointPoints[jointType] = new Point(depthSpacePoint.X, depthSpacePoint.Y);  
          } 
         } 

         this.DrawBody(joints, jointPoints, dc, drawPen); 
        } 
       } 

       this.drawingGroup.ClipGeometry = new RectangleGeometry(new Rect(0.0, 0.0, this.displayWidth, this.displayHeight)); 
      } 
     } 
    } 

답변

0

내가 이전 키 넥트와 함께 일하고 여전히이 나 작동하지 않을 수도 있습니다 새로운 하나를 가지고하지 않은 :은 당신에게 직면 사람의 수를 줄 것이다 bodyFrame.BodyCount 경우 그런 다음 Kinect가 코드를 1로 바꾸어 코드가 다음과 같이됩니다.

this.bodies = new Body [1];

보통 kinect가 가장 가까운 사람을 선택한다고 생각합니다. 시도해보고 무엇을 얻을 수 있는지 말해보십시오.

+1

안녕하세요. this.bodies = new Body [1]이 작동하지 않습니다. 그러나 나는 한 사람을 추적 할 다른 방법을 찾았습니다. HDFaceBasics-WPF 및 방법 FindClosestBody를 확인하십시오. – Ozzy

0

body 배열을 반복하는 데 foreach를 사용하는 대신 목록의 첫 번째 본문 만 사용하면됩니다.

교체 :

foreach (Body body in this.bodies) 
{ 
    if (body.IsTracked) 
    { 
     ... 

으로 :

var body = this.bodies[0]; 
if (body.tracked) 
{ 
    ... 

업데이트 : 난 그냥 키 넥트 Studio와 I를 사용하여이 시도

단 하나의 추적 몸이 경우에도 그것이 발견 배열의 첫 번째 슬롯에있을 수는 없습니다. 내 응용 프로그램에서 지금은 LINQ를 사용하여 IsTracked == true 인 첫 번째 본문을 가져옵니다. 프로덕션 준비가 된 코드에 대해이 작업을 수행하는 방법에 대한 좋은 대답이 없습니다. 이 문제를 해결하면이 게시물을 업데이트 할 것입니다.

1

조용한 시간 전이지만 한 사람을 추적하는 자체 기능으로이 문제를 관리합니다. 추적 한 사람이 본문 배열의 다음 상위 본문을 떠나면 "추적 된 사람"을 얻습니다.

private ulong currTrackingId = 0; 
private Body GetActiveBody() 
{ 
    if (currTrackingId <= 0) 
    { 
     foreach (Body body in this.bodies) 
     { 
      if (body.IsTracked) 
      { 
       currTrackingId = body.TrackingId; 
       return body; 
      } 
     } 

     return null; 
    } 
    else 
    { 
     foreach (Body body in this.bodies) 
     { 
      if (body.IsTracked && body.TrackingId == currTrackingId) 
      { 
       return body; 
      } 
     } 
    } 

    currTrackingId = 0; 
    return GetActiveBody(); 
}