public DummyCamera(string filePath)
 {
     if (!FaceState.LoadFromFile(filePath, out _faceState))
     {
         throw new System.IO.FileNotFoundException("File not found!", filePath);
     }
 }
        static public bool LoadFromFile(string path, out FaceState faceState)
        {
            bool result = false;

            faceState = new FaceState();

            try
            {
                using (StreamReader file = File.OpenText(path))
                {
                    JsonSerializer serializer = new JsonSerializer();
                    faceState = (FaceState)serializer.Deserialize(file, typeof(FaceState));
                    result    = true;
                }

                //using (FileStream file = File.OpenRead(path))
                //{
                //    var reader = new BinaryFormatter();
                //    faceState = (FaceState)reader.Deserialize(file);
                //    result = true;
                //}
            }
            catch (FileNotFoundException)
            {
                result = false;
            }

            return(result);
        }
        private void OnRenderFormKeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
        {
            switch (Char.ToUpperInvariant(e.KeyChar))
            {
            case '+':
                this.zoom          += ZoomDelta;
                this.transformation = CalculateTransformation(this.faceCenter, this.zoom, Width, Height);
                e.Handled           = true;
                break;

            case '-':
                this.zoom          -= ZoomDelta;
                this.zoom           = Math.Max(ZoomDelta, this.zoom);
                this.transformation = CalculateTransformation(this.faceCenter, this.zoom, Width, Height);
                e.Handled           = true;
                break;

            case 'D':
                this.showDebugInfo = !this.showDebugInfo;
                e.Handled          = true;
                break;

            case 'S':
                if (FaceState.SaveToFile(this.CurrentFaceState, StateFilePath))
                {
                    this.savedFaceStateTimeout = this.framesPerSecond.RunTime.Add(new TimeSpan(0, 0, EventTimeoutSeconds));
                }
                e.Handled = true;
                break;
            }
        }
        static public bool SaveToFile(FaceState faceState, string path)
        {
            bool result = false;

            using (StreamWriter file = File.CreateText(path))
            {
                JsonSerializer serializer = new JsonSerializer();
                serializer.Serialize(file, faceState);
                result = true;
            }

            return(result);
        }
        private void Draw(FaceState faceState)
        {
            this.isLeftEyeClosed  = faceState.IsLeftEyeClosed;
            this.isRightEyeClosed = faceState.IsRightEyeClosed;
            this.isHappy          = faceState.IsHappy;
            this.isMouthOpen      = faceState.IsMouthOpen;
            this.isMouthMoved     = faceState.IsMouthMoved;
            this.isWearingGlasses = faceState.IsWearingGlasses;

            if (faceState.Points != null && faceState.Points.Length > 0)
            {
                this.facePoints = faceState.Points.ConvertToVector2();

                this.faceBoundingBox = faceState.BoundingBox.ConvertToRectangleF();

                this.faceCenter = new Vector2(
                    this.facePoints[this.faceCamera.IndexTopOfHeadPoint].X,
                    this.facePoints[this.faceCamera.IndexTopOfHeadPoint].Y + (this.faceBoundingBox.Height / 2.0f));

                this.transformation = CalculateTransformation(this.faceCenter, this.zoom, Width, Height);
            }

            // this.GenerateFace();
        }
 private void OnFaceChanged(object sender, FaceState faceState)
 {
     this.Draw(faceState);
 }