private void SaveFace_Click(object sender, RoutedEventArgs e)
        {
            if (selectedFaces.Count() == 0)
            {
                MessageBox.Show("Лицо не выбрано");
                return;
            }
            if (String.IsNullOrWhiteSpace(PersonName.Text))
            {
                MessageBox.Show("Поле для ввода имени должно быть заполнено");
                return;
            }

            using (UMat ugray = new UMat())
            {
                Image <Bgr, Byte> img = selectedFaces[currentFace].Resize(100, 100, Inter.Cubic);
                CvInvoke.CvtColor(img, ugray, ColorConversion.Bgr2Gray);
                CvInvoke.EqualizeHist(ugray, ugray);

                DateTime date     = DateTime.UtcNow;
                string   filepath = "/Faces/face" + date.Year + date.Month +
                                    date.Day + date.Hour + date.Minute + date.Second + date.Millisecond + ".bmp";
                ugray.Save(Environment.CurrentDirectory + filepath);

                PeopleData.Add(PersonName.Text, filepath);

                Watcher.WriteJson(PeopleData, ConfigurationManager.AppSettings["JsonData"]);

                TrainFaceRecognizer();
            }

            FaceItemsPlace.Children.Add(new FaceItem(this, PeopleData.Face.Count - 1));
            NoFaces.Visibility = Visibility.Collapsed;
            MessageBox.Show("Лицо " + PersonName.Text + " сохранено");
        }
예제 #2
0
        private void DeleteButton_Click(object sender, RoutedEventArgs e)
        {
            int faceId = MainWindow.FaceItemsPlace.Children.IndexOf(this);
            int nameId = MainWindow.PeopleData.NameId[faceId];

            if (File.Exists(Environment.CurrentDirectory + MainWindow.PeopleData.Face[faceId]))
            {
                File.Delete(Environment.CurrentDirectory + MainWindow.PeopleData.Face[faceId]);
            }

            MainWindow.PeopleData.NameId.RemoveAt(faceId);
            MainWindow.PeopleData.Face.RemoveAt(faceId);
            if (MainWindow.PeopleData.NameId.IndexOf(nameId) == -1)
            {
                MainWindow.PeopleData.Name[nameId - 1] = null;
                MainWindow.PeopleData.DeletedNamesId.Add(nameId - 1);
            }
            while (MainWindow.PeopleData.Name.Count() != 0 && MainWindow.PeopleData.Name.Last() == null)
            {
                int last = MainWindow.PeopleData.Name.Count() - 1;
                MainWindow.PeopleData.DeletedNamesId.Remove(last);
                MainWindow.PeopleData.Name.RemoveAt(last);
            }
            Watcher.WriteJson(MainWindow.PeopleData, ConfigurationManager.AppSettings["JsonData"]);
            MainWindow.TrainFaceRecognizer();
            MainWindow.FaceItemsPlace.Children.Remove(this);
        }
 public void SaveLogs(object sender, EventArgs e)
 {
     Watcher.WriteJson(Logs, ConfigurationManager.AppSettings["LogData"]);
 }