/// <summary> /// Disposes the EyeTracker. /// </summary> public void Dispose() { faceTracker.Dispose(); }
private async Task FaceTrackingAsync(TimeSpan dueTime, TimeSpan interval, CancellationToken token) { if (interval.TotalMilliseconds == 0) return; // Initial wait time before we begin the periodic loop. if (dueTime > TimeSpan.Zero) await Task.Delay(dueTime, token); DateTime LocalTimestamp = Timestamp; FaceTracker tracker = new FaceTracker(Sensor); // Repeat this loop until cancelled. while (!token.IsCancellationRequested) { // Skip already work with given data if (Timestamp == LocalTimestamp) { await Task.Delay(interval, token); continue; } // Timestamp data LocalTimestamp = Timestamp; FaceTrackWatch.Again(); // Do Job try { CopyColorData = true; CopySkeletons = true; FPoints = null; Mood = 0; if (null != GestureManager && null != GestureManager.Skeleton) { FaceTrackFrame frame = tracker.Track(ColorFormat, ColorData, DepthFormat, DepthData, GestureManager.Skeleton); if (frame.TrackSuccessful) { // Only once. It doesn't change. if (FTriangles == null) { FTriangles = frame.GetTriangles(); } FPoints = frame.GetProjected3DShape(); Mood = frame.GetAnimationUnitCoefficients()[AnimationUnit.LipCornerDepressor]; WSRProfileManager.GetInstance().UpdateMood(Mood); } } } catch (Exception ex) { WSRConfig.GetInstance().logError("FACE", ex); } FaceTrackWatch.Stop(); // Wait to repeat again. if (interval > TimeSpan.Zero) await Task.Delay(interval, token); } // Dispose Tracker tracker.Dispose(); }