Kinect 仅当一个 Body/Skeleton 在框架中时记录

Kinect Record Only When One Body/Skeleton Is in the Frame

我需要编写一个记录帧的程序,但前提是帧中有一个 skeleton/body。我查看了 bodyCount 方法,但它总是给出 6 的值(无用)。我尝试做的一件事如下所示。此代码基本上显示了存储被跟踪的 body 的索引。但是,我仍然不知道如何知道框架中是否有一具或多具尸体。 我真的很感激任何帮助。 提前致谢。

private void Reader_FrameArrived(object sender, BodyFrameArrivedEventArgs e){
   using (BodyFrame bodyFrame=e.FrameReference.AquireFrame()){
          if (bodyFrame!=null){
                if(this.bodies==null){
                this.bodies=new Body[bodyFrame.BodyCount];
                }
          body.Frame.GetAndRefreshBodyData(this.bodies) 

          for(int i=0; i<6;i++){
              if(this.bodies[i].IsTracked){
              Console.WriteLine("Tracked"+i)
               }
           }

      }

   }

}

只需检查每个 body 的 IsTracked 属性,并将跟踪的骨架数量存储在单个变量中。如果这个数字等于1,则只跟踪到一个骨架,您可以开始录制。

    private Body[] bodies = null;

    [...]

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

                // The first time GetAndRefreshBodyData is called, Kinect will allocate each Body in the array.
                // As long as those body objects are not disposed and not set to null in the array,
                // those body objects will be re-used.
                bodyFrame.GetAndRefreshBodyData(this.bodies);
                dataReceived = true;
            }
        }

        if (dataReceived)
        {
            int trackedBodyCount = 0;
            for (int i=0; i<this.bodies.Length; ++i)
            {
                if(this.bodies[i].IsTracked) {
                    trackedBodyCount += 1;
                }
            }

            if (trackedBodyCount == 1)
            {
                // One skeleton is tracked
            }
        }
    }