Пример #1
0
        private static void DetectFaces()
        {
            var grayframe = CurrentFullFrame.Convert <Gray, byte>();

            Faces         = FrontalFaceCascadeClassifier.DetectMultiScale(grayframe, 1.1, 10, Size.Empty);
            FacesDetected = Faces.Length > 0;
        }
Пример #2
0
        private void FacesRecognizerElapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            Users.Clear();

            if (Faces.Length == 0 && IsBrowserOpen)
            {
                ShutdownBrowserSession();
            }

            foreach (var face in Faces)
            {
                var grayframe = CurrentFullFrame.Convert <Gray, byte>();
                CurrentCroppedFrame = new Image <Gray, byte>(Crop(grayframe.ToBitmap(), face.Left, face.Top, face.Width, face.Height));

                var result = RecognizerEngine.RecognizeUser(CurrentCroppedFrame);
                Users.Add(new User
                {
                    UserName = result.UserName,
                    URL      = result.URL,
                    Distance = result.Distance,
                    Face     = face
                });
                if (IsBrowserOpen && result.UserName.Equals(Config.UnrecognizedUserName))
                {
                    AuthenticatedButUnrecognizedCount++;
                    if (AuthenticatedButUnrecognizedCount == 3)
                    {
                        ShutdownBrowserSession();
                        AuthenticatedButUnrecognizedCount = 1;
                    }
                }

                // Recognized & valid user found.
                if (!result.UserName.Equals(Config.UnrecognizedUserName))
                {
                    if (IsBrowserOpen)                                                  // Browser already open.
                    {
                        if (result.UserName.Equals(UserName) && result.URL.Equals(URL)) // Same user is still in front of the camera, continue.
                        {
                            continue;
                        }
                        else                                                             // Browser is open but a different user is found. Shut down for privacy.
                        {
                            ShutdownBrowserSession();
                        }
                    }
                    else                // Browser not open, launch with the current user's URL.
                    {
                        IsBrowserOpen     = true;
                        Application.Idle -= ProcessFrame;
                        UserName          = result.UserName;
                        URL = result.URL;
                        BrowserProcessID = Process.Start($"http://{URL}").Id;
                    }
                }
            }
        }
Пример #3
0
        private void FacesRecognizerElapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            Users.Clear();

            foreach (var face in Faces)
            {
                var grayframe = CurrentFullFrame.Convert <Gray, byte>();
                CurrentCroppedFrame = new Image <Gray, byte>(Crop(grayframe.ToBitmap(), face.Left, face.Top, face.Width, face.Height));

                var result = RecognizerEngine.RecognizeUser(CurrentCroppedFrame);
                Users.Add(new User
                {
                    UserName = result.UserName,
                    URL      = result.URL,
                    Distance = result.Distance,
                    Face     = face
                });
                if (result.UserName.Equals(Config.UnrecognizedUserName))
                {
                    AuthenticatedButUnrecognizedCount++;
                    if (AuthenticatedButUnrecognizedCount == 3)
                    {
                        AuthenticatedButUnrecognizedCount = 1;
                    }
                }

                // Recognized & valid user found.
                if (!result.UserName.Equals(Config.UnrecognizedUserName))
                {
                    if (result.UserName.Equals(UserName))      // Same user is still in front of the camera, continue.
                    {
                        UserName = result.UserName;
                        continue;
                    }
                }
            }
        }
Пример #4
0
        private void AddUserButton_Click(object sender, EventArgs e)
        {
            try
            {
                if (Faces.Length > 0)
                {
                    var croppedImage = Crop(CurrentFullFrame.Convert <Gray, byte>().ToBitmap(), Faces[0].Left, Faces[0].Top, Faces[0].Width, Faces[0].Height);

                    var result = RecognizerEngine.RecognizeUser(new Image <Gray, byte>(croppedImage));
                    File = (byte[])new ImageConverter().ConvertTo(croppedImage, typeof(byte[]));
                    UserInfo userInfoForm = new UserInfo();
                    if (!result.UserName.Equals(Config.UnrecognizedUserName))
                    {
                        userInfoForm.Populate(result.UserName, result.URL);
                    }
                    userInfoForm.Show();
                    userInfoForm.Activate();
                }
            }
            catch (Exception)
            {
                return;
            }
        }