Example #1
0
        private void AnalyzeSamples()
        {
            currentTrackingQuality = GetStatus();
            EyeCount quality = VisibleEyesCount(currentTrackboxObj);

            if (quality == EyeCount.One || quality == EyeCount.Two)
            {
                badSuccessiveSamples = 0;
                latestGoodSample     = currentTrackboxObj;

                // calculate eye angle if both eyes are visible
                if (quality == EyeCount.Two)
                {
                    float dx = currentTrackboxObj.Right.X - currentTrackboxObj.Left.X;
                    float dy = currentTrackboxObj.Right.Y - currentTrackboxObj.Left.Y;
                    latestNormalizedDistance = Math.Sqrt(dx * dx + dy * dy);
                    latestAngle = RadToDeg * Math.Atan2(dy * controlSize.Height, dx * controlSize.Width);
                }
            }
            else
            {
                // we are forgiving with a couple of bad samples
                badSuccessiveSamples++;

                if (badSuccessiveSamples < MAX_BAD_SAMPLES)
                {
                    currentTrackboxObj = latestGoodSample;
                }
            }
        }
Example #2
0
        private void UpdateEye(FrameworkElement eye, PointF pos, EyeCount validity, TransformGroup transformation)
        {
            if (pos != PointF.Empty && validity <= EyeCount.Two)
            {
                eye.Visibility = Visibility.Visible;
                var scale = eyeScale + DoEyeSizeDiff() * eyeScale;
                var x     = pos.X * controlSize.Width;
                var y     = pos.Y * controlSize.Height;

                ((RotateTransform)transformation.Children[0]).Angle = latestAngle;
                ((ScaleTransform)transformation.Children[1]).ScaleX = scale;
                ((ScaleTransform)transformation.Children[1]).ScaleY = scale;
                ((TranslateTransform)transformation.Children[2]).X  = x - (eye.ActualWidth) / 2;
                ((TranslateTransform)transformation.Children[2]).Y  = y - (eye.ActualHeight) / 2;
            }
            else
            {
                eye.Visibility = Visibility.Collapsed;
            }
        }
 private void UpdateEye(Image eye, PointF pos, EyeCount validity, TransformGroup transformation)
 {
     if (pos != PointF.Empty && validity <= EyeCount.Two)
     {
         eye.Visibility = Visibility.Visible;
         var scale = EyeScale + DoEyeSizeDiff() * EyeScale;
         var x = pos.X * ControlSize.Width;
         var y = pos.Y * ControlSize.Height;
         ((RotateTransform)transformation.Children[0]).Angle = LatestAngle;
         ((ScaleTransform)transformation.Children[1]).ScaleX = scale;
         ((ScaleTransform)transformation.Children[1]).ScaleY = scale;
         ((TranslateTransform)transformation.Children[2]).X = x - (eye.ActualWidth) / 2;
         ((TranslateTransform)transformation.Children[2]).Y = y - (eye.ActualHeight) / 2;
         eye.RenderTransform = transformation;
     }
     else
     {
         eye.Visibility = Visibility.Collapsed;
     }
 }