Created
November 30, 2014 17:10
-
-
Save tomkerkhove/3fe7ad2d717de000766c to your computer and use it in GitHub Desktop.
Handle multiple faces
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private Dictionary<ulong, FaceFrameSource> _faceSources = new Dictionary<ulong, FaceFrameSource>(); | |
private Dictionary<ulong, FaceFrameReader> _faceReaders = new Dictionary<ulong, FaceFrameReader>(); | |
/// <summary> | |
/// Process body frames | |
/// </summary> | |
private void OnBodyFrameReceived(object sender, BodyFrameArrivedEventArgs e) | |
{ | |
// Get Frame ref | |
BodyFrameReference bodyRef = e.FrameReference; | |
if (bodyRef == null) return; | |
// Get body frame | |
using (BodyFrame frame = bodyRef.AcquireFrame()) | |
{ | |
if (frame == null) return; | |
// Allocate array when required | |
if (_bodies == null) | |
_bodies = new Body[frame.BodyCount]; | |
// Refresh bodies | |
frame.GetAndRefreshBodyData(_bodies); | |
foreach (Body body in _bodies) | |
{ | |
if (body.IsTracked && !_faceSources.ContainsKey(body.TrackingId)) | |
{ | |
// Create new sources with body TrackingId | |
FaceFrameSource faceSource = new FaceFrameSource(_kinect, body.TrackingId, _faceFrameFeatures); | |
// Create new reader | |
FaceFrameReader faceReader = _faceSource.OpenReader(); | |
// Wire events | |
faceReader.FrameArrived += OnFaceFrameArrived; | |
faceSource.TrackingIdLost += OnTrackingIdLost; | |
// Add sources to dictionary | |
_faceSources.Add(body.TrackingId, faceSource); | |
_faceReaders.Add(body.TrackingId, faceReader); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment