Kinect v2 跟踪个人
本文关键字:跟踪 v2 Kinect | 更新日期: 2023-09-27 18:33:30
我正在尝试弄清楚如何使用Kinect 2区分两个被跟踪的人。因此,如果玩家 1 执行此手势,请执行此操作。如果玩家 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);
}
这就是我发送数据的地方。
这是基于微软的源代码构建的离散手势检测器。
编辑:找到了问题。玩家 1 的跟踪 ID 被多次重置,因此它永远不会进入 TrackingId 中的最后一个 if 语句。只需要弄清楚现在那里发生了什么。
使用 Getters 和 Setters 解决,因为值 1 和跟踪 ID 正在重置。