Click here to Skip to main content
14,367,615 members
Rate this:
Please Sign up or sign in to vote.
See more:
I'm creating an application 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 Skeleton 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 with 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.

Could someone please help me? Thx!

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... 
Posted
Comments
SASS_Shooter 23-Apr-12 12:14pm
   
You are making at least 3 method calls in the snippet of code.
Where do you get the error of invalid expression?

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Here are a few minor suggestions in your code:

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(firstSkeleton); 
 

 
if (SkeletonTrackingState.Tracked == firstSkeleton.TrackingState)



Making Skeletons renamed as skeletons avoids potential naming conflict with a Kinect namespace object of the same name.
Data of type int can never be null. Your null check was also AFTER you already used to variable. Removed the redundant code.

When calling a method you pass your variable you do not specify a type then the variable.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100