Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
El Bruno - Kinect V2 Get Tracked Bodies
/// <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++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.