Hello!

When you work with apps on Kinect that require a special codeĀ for each bodyĀ recognized by the sensor, the entry point tends to be the collection of bodies returning to us inĀ the line 15 of the first block in the following code example


/// <summary>
/// Array for the bodies
/// </summary>
private readonly Body[] _bodies;
private void Reader_BodyFrameArrived(object sender, BodyFrameArrivedEventArgs e)
{
var dataReceived = false;
var hasTrackedBody = false;
using (var bodyFrame = e.FrameReference.AcquireFrame())
{
if (bodyFrame != null)
{
bodyFrame.GetAndRefreshBodyData(_bodies);
dataReceived = true;
}
}


private void Reader_BodyFrameArrived(object sender, BodyFrameArrivedEventArgs e)
{
var dataReceived = false;
var hasTrackedBody = false;
var fullBodies = new Body[_kinectSensor.BodyFrameSource.BodyCount];
using (var bodyFrame = e.FrameReference.AcquireFrame())
{
if (bodyFrame != null)
{
bodyFrame.GetAndRefreshBodyData(fullBodies);
dataReceived = true;
}
}
var trackedBodiesCount = fullBodies.Count(body => body.IsTracked);
_bodies = new Body[trackedBodiesCount];
var bodyToAddIndex = 0;
for (var bodyIndex = 0; bodyIndex < fullBodies.Length; bodyIndex++)
{
var body = _bodies[bodyIndex];
if (!body.IsTracked) continue;
_bodies[bodyToAddIndex] = body;
bodyToAddIndex++;
}

The problem with these lines is the collection of bodies it is usually complete by 6 elements, however there are no 6 people in front of the Kinect. The following image shows the collection and at the same, the 6th element is a correct body, but with the property IsTracked = False .

KV2NotTrackedBdies

The solution is quite simple, a small array preprocessing, filtering by the bodies that are correctly identified. In line 16 of the second block of code we obtain the total number of bodies where IsTracked == True and from there to be processed.

Happy Codding

Greetings @ Home

/El Bruno

Leave a comment

Discover more from El Bruno

Subscribe now to keep reading and get access to the full archive.

Continue reading