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; } } } }
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; } } } }