Ejemplo n.º 1
0
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     // CREATE ALL THE FILES HERE!
     // if you are trying to reset the database, you must remove the entire folder
     if (!Directory.Exists(EnrollmentManager.filepath))
     {
         Directory.CreateDirectory(EnrollmentManager.filepath);
         Directory.CreateDirectory(EnrollmentManager.filepath + "feed");
         File.Create(EnrollmentManager.filepath + "contacts.txt");
         File.Create(EnrollmentManager.filepath + "context.txt");
         File.Create(EnrollmentManager.filepath + "nameDB.txt");
         File.Create(EnrollmentManager.filepath + "faceDB.txt");
         // no one in database
         EnrollmentManager.firstTime      = true;
         EnrollmentManager.window.Content = new EnterNamePage();
     }
     else
     {
         // no one in database
         if (File.ReadAllLines(EnrollmentManager.filepath + "faceDB.txt").Length == 0)
         {
             EnrollmentManager.firstTime      = true;
             EnrollmentManager.window.Content = new EnterNamePage();
         }
         else
         {
             EnrollmentManager.Finish(true);
         }
     }
 }
Ejemplo n.º 2
0
 private void Button_Click_1(object sender, RoutedEventArgs e)
 {
     EnrollmentManager.isKinect2();
     // CREATE ALL THE FILES HERE!
     if (!Directory.Exists(EnrollmentManager.filepath))
     {
         EnrollmentManager.window.Content = new ErrorPage();
     }
     else
     {
         // kinect 2 should not be doing any enrollment manager stuff
         EnrollmentManager.Finish(true);
     }
 }
Ejemplo n.º 3
0
 private void Cancel_Click(object sender, RoutedEventArgs e)
 {
     EnrollmentManager.Finish(true);
 }
Ejemplo n.º 4
0
        private void ReceiveFrame(BitmapSource frame, IEnumerable <Rect> faceBoxes)
        {
            Rect faceBox = Rect.Empty;

            PersonTrainingData person = EnrollmentManager.personToTrain;


            if (faceBoxes.Count() == 1) // people in the shot, only want one right now
            {
                //Debug.WriteLine("faceboxes COUNT: " + faceBoxes.Count());
                Rect bounds = new Rect(new System.Windows.Size(frame.Width, frame.Height));
                IEnumerable <Rect> filteredFaceBoxes = faceBoxes.Select((box) => Util.TransformFace(box));
                filteredFaceBoxes = filteredFaceBoxes.Where((box) => Util.IsValidRect(box, bounds));
                faceBox           = filteredFaceBoxes.FirstOrDefault();



                Bitmap image = Util.SourceToBitmap(frame);


                i++;

                if ((i % 4) == 0)
                {
                    FaceRecognition.FaceRecognizerBridge.Preview(image, faceBox);
                    MemoryStream ms       = new MemoryStream();
                    BitmapImage  bi       = new BitmapImage();
                    byte[]       bytArray = File.ReadAllBytes(EnrollmentManager.filepath + "preview.jpg");
                    ms.Write(bytArray, 0, bytArray.Length); ms.Position = 0;
                    bi.BeginInit();
                    bi.StreamSource = ms;
                    bi.EndInit();
                    snapshotImage.Source = bi;

                    if (person.trainingImages.Count() == NUMBER_TO_TRAIN)
                    {
                        EnrollmentManager.OnFrameReceived -= ReceiveFrame;
                        EnrollmentManager.Finish(false);
                    }
                    person.trainingImages.Insert(j, image);
                    person.faceBoxes.Insert(j, faceBox);
                    j++;
                }

                if (i == NUMBER_TO_TRAIN)
                {
                    i = 0;
                    //EnrollmentManager.OnFrameReceived -= ReceiveFrame;
                    //EnrollmentManager.Finish(false);
                }

                // }
            }
            else if (faceBoxes.Count() > 1)
            {
                Debug.WriteLine("Too many people in the shot: " + faceBoxes.Count());
            }

            // drawing the red boxes
            DrawingVisual drawingVisual = new DrawingVisual();

            using (DrawingContext drawingContext = drawingGroup.Open())
            {
                drawingContext.DrawImage(frame, new Rect(new System.Windows.Size(frame.Width, frame.Height)));
                var brush = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Red);
                var pen   = new System.Windows.Media.Pen(brush, 5);
                drawingContext.DrawRectangle(null, pen, faceBox);
            }

            lastFrame = frame;
        }
Ejemplo n.º 5
0
 private void Done_Click(object sender, RoutedEventArgs e)
 {
     EnrollmentManager.OnFrameReceived -= ReceiveFrame;
     EnrollmentManager.Finish(false);
 }