我试图弄清楚如何区分使用Kinect 2跟踪的两个人。因此,如果玩家1做了这个动作,请执行此操作。如果玩家2执行此操作,请执行此操作。我尝试使用跟踪ID,但我不确定我是否正确使用了跟踪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语句。只需要弄清楚现在发生了什么。答案 0 :(得分:0)
解决了Getters和Setters作为值1并且跟踪ID被重置。