Example #1
0
        private void BnSavarFace_Click(object sender, EventArgs e)
        {
            try
            {
                using (var db = new BdDataContext())
                {
                    labels.Clear();
                    tranningImages.Clear();
                    Count    = Count + 1;
                    grayFace = camera.QueryGrayFrame().Resize(320, 240, INTER.CV_INTER_CUBIC);
                    MCvAvgComp[][] Detectfaces = grayFace.DetectHaarCascade(faceDetect, 1.2, 10, HAAR_DETECTION_TYPE.DO_CANNY_PRUNING, new Size(20, 20));
                    foreach (MCvAvgComp f in Detectfaces[0])
                    {
                        TrainedFace = Frame.Copy(f.rect).Convert <Gray, byte>();
                        break;
                    }
                    TrainedFace = result.Resize(100, 100, INTER.CV_INTER_CUBIC);
                    tranningImages.Add(TrainedFace);
                    labels.Add(txtName.Text);

                    int lista = tranningImages.Count();
                    for (int i = 0; i < lista; i++)
                    {
                        //salva no o Banco sql Server
                        Face face = new Face
                        {
                            NomeFace     = txtName.Text,
                            DataCadastro = DateTime.Now
                        };
                        db.faces.Add(face);
                        db.SaveChanges();
                        tranningImages.ToArray()[0].Save(Application.StartupPath + "/Faces/" + "face" + face.Id + ".bmp");
                        MessageBox.Show(face.NomeFace + " Add com Sucesso!!");
                        txtName.Clear();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Example #2
0
 public Form1()
 {
     InitializeComponent();
     faceDetect = new HaarCascade("haarcascade_frontalface_default.xml");
     try
     {
         using (var db = new BdDataContext())
         {
             //Busca do Banco sql Server
             var    Labelsinf = db.faces.ToList();
             string FaceLoad;
             foreach (var item in Labelsinf)
             {
                 FaceLoad = "face" + item.Id + ".bmp";
                 tranningImages.Add(new Image <Gray, byte>(Application.StartupPath + $"/Faces/{FaceLoad}"));
                 labels.Add(Labelsinf.Where(d => d.Id == item.Id).First().NomeFace);
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Opss: " + ex.Message);
     }
 }