Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to track ONE person with Kinect (trackingID)

I would like to track the first person, and use this person's right hand to navigate in the application that I made.

I can take over the cursor, now I just want only one person being tracked. So basically when one person is navigating in the program, and there are people walking behind him or are looking with this guy, if they move, the kinect shouldn't recognise anyone else.

How can I implement this, I know it's something with the trackingId but what? :s

        foreach (SkeletonData s in allSkeletons.Skeletons)
        {

                if (s.TrackingState == SkeletonTrackingState.Tracked)
                {
                    if (s.TrackingID == 0)
                    {

                        foreach (Joint joint in s.Joints)
                        {
                        }
                    }
                }
        }
like image 720
Letoir Avatar asked Dec 09 '11 08:12

Letoir


1 Answers

Every tracked person has a player index. Just ignore players with other indexes.
The player index is part of the data in the depth stream image. You have to extract it:

int playerIdx = depthFrame16[i16] & 0x07;

In order to get this info you have to initialize your Kinect Runtime correctly:

_kinectNui.Initialize(RuntimeOptions.UseDepthAndPlayerIndex | ....

See here for more infos: http://www.codeproject.com/KB/dotnet/KinectGettingStarted.aspx

I totally recommend this video tutorial from MS: http://research.microsoft.com/apps/video/?id=152249

If you look in the ShapeGameDemo that is coming with the SDK you can see how they do it. (They just use the index of the skeletion in the array):

int playerId = 0;
foreach (SkeletonData data in skeletonFrame.Skeletons) {
   if (SkeletonTrackingState.Tracked == data.TrackingState) {
      Player player;
      if (players.ContainsKey(playerId))
         player = players[playerId];
      else
         player = new Player(playerId);
   }
   playerId++;
}

Simplifying things you can do that (using your code):

int myPlayerIndex = 0; //probably 0 since you are the first person entered the kinect scope
int playerId = 0;
foreach (SkeletonData s in allSkeletons.Skeletons) {
   if(playerId != myPlayerIndex)
      continue;       

   if (s.TrackingState == SkeletonTrackingState.Tracked) {
      foreach (Joint joint in s.Joints)
      {
      }
   }
   playerId++;
}

To round things up here is a similar question in an MS forum that explains it: http://social.msdn.microsoft.com/Forums/en-US/kinectsdk/thread/d821df8d-39ca-44e3-81e7-c907d94acfca

like image 146
juergen d Avatar answered Oct 01 '22 15:10

juergen d