Ejemplo n.º 1
0
        private void DeleteFaces_Click(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show("Вы действительно собираетесь удалить базу лиц?", "Подтверждение",
                                MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
            {
                FaceItemsPlace.Children.Clear();
                foreach (var file in PeopleData.Face)
                {
                    if (File.Exists(Environment.CurrentDirectory + file))
                    {
                        File.Delete(Environment.CurrentDirectory + file);
                    }
                }
                PeopleData = new PeopleData();
                if (File.Exists(Environment.CurrentDirectory + ConfigurationManager.AppSettings["JsonData"]))
                {
                    File.Delete(Environment.CurrentDirectory + ConfigurationManager.AppSettings["JsonData"]);
                }

                if (File.Exists(ConfigurationManager.AppSettings["FaceRecognizerData"]))
                {
                    File.Delete(ConfigurationManager.AppSettings["FaceRecognizerData"]);
                }
                FaceRecognizer = new LBPHFaceRecognizer(1, 8, 8, 8, 100);
                MessageBox.Show("Данные обучения удалены");
            }
        }
Ejemplo n.º 2
0
        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 + " сохранено");
        }