Пример #1
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            imageBox1.Image = cap.QueryFrame();
            IDBAccess dataStore = new DBAccess("facesDB.db");

            cascadeClassifier = new CascadeClassifier(Application.StartupPath + "/haarcascade_frontalface_default.xml");
            using (var imageFrame = cap.QueryFrame().ToImage<Bgr, Byte>())
            {
                if (imageFrame != null)
                {
                    var grayframe = imageFrame.Convert<Gray, byte>();
                    var faces = cascadeClassifier.DetectMultiScale(grayframe, 1.2, 10, Size.Empty); //the actual face detection happens here

                    PackageHost.PushStateObject<Rectangle[]>("faces", faces);
                    string txt = "";
                    foreach (var face in faces)
                    {

                        
                        imageFrame.Draw(face, new Bgr(Color.BurlyWood), 3); //the detected face(s) is highlighted here using a box that is drawn around it/them

                        if (File.Exists(Application.StartupPath + "/RecognizerEngineData.YAML"))
                        {
                            txt += dataStore.GetUsername(recoEngine.RecognizeUser(imageFrame.GetSubRect(face).Convert<Gray, byte>())) + " ";
                        }
                        else
                        {
                            txt += "Train the recognizer engine first !";
                        }
                        
                    }
                    if (faces.GetLength(0) > 0)
                    {
                        imageFrame.Draw(faces[0], new Bgr(Color.Red), 3);
                    }
                    textBox1.Text = txt;
                }
                imageBox1.Image = imageFrame;
            }
        }
Пример #2
0
 public RecognizerEngine(String databasePath, String recognizerFilePath)
 {
     this.recognizerFilePath = recognizerFilePath;
     dbAccess = new DBAccess(databasePath);
     faceRecognizer = new EigenFaceRecognizer(80, double.PositiveInfinity);
 }
Пример #3
0
        private void button3_Click(object sender, EventArgs e)
        {
            //var faceToSave = new Image<Gray, Byte>(imageBox1.Image.Bitmap);
            var faceToSave = cap.QueryFrame();
            timer1.Stop();
            Byte[] file;
            IDBAccess dataStore = new DBAccess("facesDB.db");

            var frmSaveDialog = new FrmSaveDialog();
            if (frmSaveDialog.ShowDialog() == DialogResult.OK)
            {
                if (frmSaveDialog._identificationNumber.Trim() != String.Empty)
                {
                    var username = frmSaveDialog._identificationNumber.Trim().ToLower();
                    var filePath = Application.StartupPath + String.Format("/{0}.bmp", username);
                    faceToSave.Save(filePath);
                    using (var stream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
                    {
                        using (var reader = new BinaryReader(stream))
                        {
                            file = reader.ReadBytes((int)stream.Length);
                        }
                    }
                    var result = dataStore.SaveFace(username, file);
                    MessageBox.Show(result, "Save Result", MessageBoxButtons.OK);
                }

            }
            timer1.Start();
        }