繁体   English   中英

Kinect v2跟踪个人

[英]Kinect v2 tracking individual people

我试图找出如何区分使用Kinect 2追踪的两个人。因此,如果玩家一个做出此手势,请执行此操作。 如果第二个玩家做出此手势,请执行此操作。 我正在尝试使用跟踪ID,但不确定执行正确的方法。 这是我的代码片段:

/// <summary>
    /// Gets or sets the body tracking ID associated with the current detector
    /// The tracking ID can change whenever a body comes in/out of scope
    /// </summary>
    public ulong TrackingId
    {
        get
        {

            return this.vgbFrameSource.TrackingId;
        }

        set
        {

            Debug.WriteLine(value);
            if (this.vgbFrameSource.TrackingId != value)
            {
                this.vgbFrameSource.TrackingId = value;
                if (value == 0)
                {
                    outOfFrame = 0;
                    this.vgbFrameSource.TrackingIdLost += this.Source_TrackingIdLost;
                }
                else if (one == 0 )
                {
                    playerOne = value;
                    ++one;
                    ++outOfFrame;
                }
                else if (two == 0 && value != playerOne)
                {
                    playerTwo = value;
                    ++two;
                    ++outOfFrame;
                }

                Debug.WriteLine(outOfFrame);
            }
        }
    }

这会获取并设置一个跟踪ID,在这里我尝试区分2个人

if (outOfFrame == 0)
{
     Debug.WriteLine("No Players in Frame");
}
else if (result.Detected && this.vgbFrameSource.TrackingId == playerOne && outOfFrame != 0)
{
      //nameGest = gestureName;
      //Debug.WriteLine(gestureName);
      Player1.AbstractState.setGestureName((string)gestureName);
      //Player1.AbstractState.setDetector(this);
}

else if (result.Detected && this.vgbFrameSource.TrackingId != playerOne && outOfFrame != 0)
{
      //nameGest = gestureName;
      //Player2.AbstractState.setGestureName(gestureName);
      Player2.AbstractState.setGestureName((string)gestureName);
      //Player2.AbstractState.setDetector(this);
}

这就是我发送数据的地方。

这是基于Microsoft的离散手势检测器源代码构建的。

编辑:发现了问题。 播放器一的跟踪ID被多次重置,因此它永远不会进入TrackingId中的最后一个if语句。 只需找出现在发生了什么。

使用Getters和Setters求解,将其值1和跟踪ID重置了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM