简体   繁体   中英

Kinect v2 tracking individual people

I'm trying to figure out how to differentiate between two people being tracked using the Kinect 2. So, if player one does this gesture, perform this action. If player two does this gesture, perform this action. I'm trying to use the tracking ID but I'm not sure I'm doing it correctly. Here is some snippets of my code:

/// <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);
            }
        }
    }

This gets and sets a tracking id, and here I try to differentiate between 2 people

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

And this is where I send off the data.

This is building off of source code from microsoft for a discrete gesture detector.

EDIT: Found the issue. The tracking ID of player one is being reset multiple times so it never gets into the last if statement in TrackingId. Just need to figure out whats going on there now.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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