/// <summary> /// Handle the new body frames /// </summary> private async void OnBodiesArrive(object sender, BodyFrameArrivedEventArgs e) { // Retrieve the body reference BodyFrameReference bodyRef = e.FrameReference; if (bodyRef == null) return; // Acquire the body frame using (BodyFrame frame = bodyRef.AcquireFrame()) { if (frame == null) return; // Create a new collection when required if (_bodies == null || _bodies.Count() != frame.BodyCount) _bodies = new Body[frame.BodyCount]; // Refresh the bodies frame.GetAndRefreshBodyData(_bodies); // Start tracking faces foreach (Body body in _bodies) { if (body.IsTracked) { // Create a new tracker if required if (!_trackers.ContainsKey(body.TrackingId)) { FaceTracker tracker = new FaceTracker(body.TrackingId, _faceFrameFeatures, _kinect); tracker.FaceAnalyticsAvailable += OnFaceAnalyticsAvailable; // Add to dictionary _trackers.Add(body.TrackingId, tracker); } } } } }