Reputation: 1274
I am creating a an application using Kinect, I want to track only 1 person at a time, right now Kinect starts detecting another person if he comes in within Kinect range. I have written the following code, and it detects any person who comes within Kinect range. Kindly tell me how can i restrict it to detect only 1 person at a time.
/*------------------------------------------
* SKELETON JOINTS
--------------------------------------------
*/
Skeleton[] _skeletons = new Skeleton[0];
using (SkeletonFrame usingSkeletonFrame = e.OpenSkeletonFrame())
{
if (usingSkeletonFrame != null)
{
_skeletons = new Skeleton[usingSkeletonFrame.SkeletonArrayLength];
usingSkeletonFrame.CopySkeletonDataTo(_skeletons);
}
}
if(_skeletons.Length >0)
// if (_skeletons.Length == SkeletonTrackingState.Tracked)
{
isSkeleton = true;
foreach (Skeleton skl in _skeletons)
{
if (skl.TrackingState == SkeletonTrackingState.Tracked)
{
// string str = "";
Joint shoulderCenter = skl.Joints[JointType.ShoulderCenter];
Joint rightShoulder = skl.Joints[JointType.ShoulderRight];
leftShoulder = skl.Joints[JointType.ShoulderLeft];
Joint Head = skl.Joints[JointType.Head];
Upvotes: 0
Views: 563
Reputation: 4366
I would see this answer I wrote on another question.
int trackingID;
skeletonTracked = new Skeleton();
bool first = true;
Skeleton skeleton;
Skeleton[] skeletons = new Skeleton[6];
...
public void AllFramesReady(object sender, AllFramesReadyEventArgs e)
{
using (SkeletonFrame sFrame = e.OpenSkeletonFrame())
{
sFrame.CopySkeletonDataTo(skeletons);
skeleton = (from s in skeletons where s.TrackingState == SkeletonTrackingState.Tracked select s).FirstOrDefault();
if (skeleton == null)
return;
if (skeleton.TrackingState == SkeletonTrackingState.Tracked)
{
if (first)
{
skeletonTracked = skeleton;
trackingId = skeleton.TrackingID;
...
first = false;
}
if (skeleton.TrackingID == trackingId)
{
...
}
}
}
Upvotes: 1