コード例 #1
0
        private void Enter_Click(object sender, RoutedEventArgs e)
        {
            PersonTrainingData person = new PersonTrainingData();

            person.name = personName.Text;
            string[] readText = File.ReadAllLines(EnrollmentManager.filepath + "nameDB.txt");
            // checks to see if name is already in the database
            int pos = Array.IndexOf(readText, person.name);

            if (pos > -1)
            {
                EnrollmentManager.doManualUpdate = true;
                // the array contains the string and the pos variable
                // will have its position in the array

                person.trainingId = pos;
            }
            else
            {
                EnrollmentManager.doManualUpdate = false;
                person.trainingId = readText.Length;
            }
            EnrollmentManager.personToTrain  = person;
            EnrollmentManager.window.Content = new TrainingPage();
        }
コード例 #2
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;
        }