Reputation: 97
I'm creating an application using the SDK, in which I must have only one user and lock it so if somebody else comes along, even if that person is closer to Kinect, the application keeps tracking the first skeleton it tracked.
From the msdn library I found I could use the Skeletom Stream Class:
Property: AppChoosesSkeletons = Gets or sets a Boolean value that determines whether the application chooses which skeletons to track.
Method: SkeletonStream.ChooseSkeletons (Int32) = Chooses one skeleton to track. Syntax: public void ChooseSkeletons (int trackingId1)
I'm not very good at programming and I'm using C#, I thought of writing something like the code down, but it says that I'm using an Invalid Expression.
SkeletonFrame SFrame = e.OpenSkeletonFrame();
if (SFrame == null) return;
Skeleton[] Skeletons = new Skeleton[SFrame.SkeletonArrayLength];
SFrame.CopySkeletonDataTo(Skeletons);
int firstSkeleton = Skeletons[0].TrackingId;
sensor.SkeletonStream.ChooseSkeletons(int firstSkeleton);
if (firstSkeleton == null)
return;
if (SkeletonTrackingState.Tracked == firstSkeleton.TrackingState)
{
//body...
The problem is with the sensor.SkeletonStream.ChooseSkeletons(int firstSkeleton
, it says int firstSkeleton cannot be used
.
Could someone please help me? Thanks!
Upvotes: 5
Views: 1587
Reputation: 793
You can not lock a skeleton, but you can choose the skeleton that you want to track, regardless of its position. It gets complicated when both people leave the Kinect's field of view.
By setting AppChoosesSkeletons
to true you are able to chose the user that you want to track. To specify the user or users to track, call the SkeletonStream.ChooseSkeletons
method and pass the tracking ID of one or two skeletons you want to track (or no parameters if no skeletons are to be tracked).
Something like this:
private void ChooseSkeleton()
{
if (this.kinect != null && this.kinect.SkeletonStream != null)
{
if (!this.kinect.SkeletonStream.AppChoosesSkeletons)
{
this.kinect.SkeletonStream.AppChoosesSkeletons = true; // Ensure AppChoosesSkeletons is set
}
foreach (Skeleton skeleton in this.skeletonData.Where(s => s.TrackingState != SkeletonTrackingState.NotTracked))
{
int ID { get.skeleton[1]}//Get ID here
}
if (ID = 0)
{
this.kinect.SkeletonStream.ChooseSkeletons(ID); // Track this skeleton
}
}
}
Upvotes: 2
Reputation: 4641
sensor.SkeletonStream.ChooseSkeletons(int firstSkeleton);
What do you want to achive with this line ?
Imo if you want to cast firstSkeleton to int write it like this:
sensor.SkeletonStream.ChooseSkeletons((int) firstSkeleton);
if you don`t want to cast it and just to give and int variable to methid just write:
sensor.SkeletonStream.ChooseSkeletons(firstSkeleton);
Upvotes: 3