Skip to main content

Track Objects in C# (AR51.Net)

Receive the objects the AR 51 system tracks, such as props, with their position (meters) and rotation. Objects are defined in advance, in Mocap Studio — see Tracked objects.

Receive objects​

Object detection works exactly like skeletons: subscribe to ObjectReceived, or read StreamAsync with await foreach.

ar51.ObjectDetection.ObjectReceived += (_, e) =>
Console.WriteLine($"{e.Object.Name} at {e.Object.Position} m, rotation {e.Object.Rotation}");
await ar51.StartAsync();

ObjectReceived fires once per object per frame, on the stream's background thread — keep handlers short.

What a tracked object contains​

MemberWhat it is
IdTracking id, stable while the object stays tracked
NameThe object's name as defined in Mocap Studio — it also tells you what kind of object it is
PositionPosition in meters (left-handed, X right, Y up, Z forward)
RotationRotation, as a System.Numerics.Quaternion
CaptureTime, ReceivedTimeWhen the cameras captured it (server clock, UTC) and when you received it (local clock)

A TrackedObject is immutable and safe to share across threads.

Complete sample​

Print every tracked object as it arrives. Press Ctrl+C to quit.

Program.cs
// Print the tracked objects as they arrive. Objects are defined in Mocap Studio. Ctrl+C to quit.
using AR51.Net;

await using IAR51Client ar51 = AR51Client.Create();

// One event per object per frame, on the stream's background thread: keep handlers short.
ar51.ObjectDetection.ObjectReceived += (_, e) =>
{
TrackedObject trackedObject = e.Object;
Console.WriteLine($"{trackedObject.Name} ({trackedObject.Id}) at {trackedObject.Position} m, rotation {trackedObject.Rotation}");
};

await ar51.StartAsync();
Console.WriteLine("Receiving objects. Ctrl+C to quit.");

using var quit = new CancellationTokenSource();
Console.CancelKeyPress += (_, e) => { e.Cancel = true; quit.Cancel(); };
try { await Task.Delay(Timeout.Infinite, quit.Token); } catch (OperationCanceledException) { }

View this sample on Bitbucket — clone the samples repository to run it.

Reference​

IObjectDetectionClient · TrackedObject · ObjectDetectionClient

Was this page helpful?