Example #1
0
        private void RecognizeFace(object sender, EventArgs e)
        {
            doWork = false;

            var faceToSave = new Image <Gray, byte>(ImageFrame.Bitmap);

            Byte[] file;


            var username = "******";
            var filePath = Application.StartupPath + String.Format("/{0}.bmp", username);

            faceToSave.ToBitmap().Save(filePath);
            using (var stream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
            {
                using (var reader = new BinaryReader(stream))
                {
                    file = reader.ReadBytes((int)stream.Length);
                }
            }


            RecognizerEngine r = new RecognizerEngine(null);
            int result         = r.RecognizeUser(faceToSave);

            MessageBox.Show("Face recognize: " + faces[result].UserName);
        }
Example #2
0
        private void CaptureFace(object sender, EventArgs e)
        {
            doWork = false;

            var faceToSave = new Image <Gray, byte>(ImageFrame.Bitmap);

            Byte[] file;

            Form2 form2 = new Form2();

            if (form2.ShowDialog() == DialogResult.OK)
            {
                MessageBox.Show("Sample " + form2.name + " was captured");
            }

            username = form2.name;
            var filePath = Application.StartupPath + String.Format("/{0}.bmp", username);

            faceToSave.ToBitmap().Save(filePath);
            using (var stream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
            {
                using (var reader = new BinaryReader(stream))
                {
                    file = reader.ReadBytes((int)stream.Length);
                }
            }

            int id = 0;

            /* if(persons.Faces.Count() > 0)
             * {
             *   id = (from faces in persons.Faces
             *         where faces.Id != null
             *         select faces.Id).Max();
             * }
             * id++;*/
            id = faces.Count;
            Faces face = new Faces();

            face.Id         = id;
            face.UserName   = username;
            face.FaceSample = file;

            /*  using (var dbContextTransaction = persons.Database.BeginTransaction())
             * {
             *    try
             *    {
             *        persons.Faces.Add(face);
             *        persons.SaveChanges();
             *        dbContextTransaction.Commit();
             *    }
             *    catch(Exception)
             *    {
             *        dbContextTransaction.Rollback();
             *        throw;
             *    }
             * }
             * //no updates */

            //save data
            faces.Add(face);

            RecognizerEngine r = new RecognizerEngine(null);

            r.TrainRecognizer(faces);
        }