private static void DetectFaces() { var grayframe = CurrentFullFrame.Convert <Gray, byte>(); Faces = FrontalFaceCascadeClassifier.DetectMultiScale(grayframe, 1.1, 10, Size.Empty); FacesDetected = Faces.Length > 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; } } } }
private void ProcessFrame(object sender, EventArgs e) { try { CurrentFullFrame = VideoCapture.QueryFrame().ToImage <Bgr, Byte>(); if (CurrentFullFrame != null) { if (!FacesDetected) { DetectFaces(); } else { foreach (var face in Faces) { CurrentFullFrame.Draw(face, new Bgr(Color.Red), 1); } string temp = ""; foreach (var item in Users) { temp += item.UserName + " - "; } //MessageBox.Show(temp); foreach (var user in Users) { DialogResult sino = MessageBox.Show("Es usted " + user.UserName + " ?", "Reconocimiento", MessageBoxButtons.YesNo); if (sino == DialogResult.Yes) { UserName = user.UserName; this.DialogResult = DialogResult.OK; this.Dispose(); FacesDetectorTimer.Stop(); FacesRecognizerTimer.Stop(); VideoCapture.Stop(); break; } //CurrentFullFrame.Draw(user.UserName, new Point(user.Face.Left, user.Face.Top), Emgu.CV.CvEnum.FontFace.HersheySimplex, 1, new Bgr(Color.White), 2); //CurrentFullFrame.Draw(user.Distance.ToString(), new Point(user.Face.Right, user.Face.Bottom), Emgu.CV.CvEnum.FontFace.HersheySimplex, 1, new Bgr(Color.White), 2); //MessageBox.Show("Test " + user.UserName); } } FPS++; VideoFrameImageBox.Image = CurrentFullFrame; } } catch (Exception) { return; } }
private void ProcessFrame(object sender, EventArgs e) { try { CurrentFullFrame = VideoCapture.QueryFrame().ToImage <Bgr, Byte>(); if (CurrentFullFrame != null) { if (!FacesDetected) { DetectFaces(); } else { if (IsBrowserOpen && Faces.Length == 0) // No face found when browser is open. Therefore, turn off the browser. { ShutdownBrowserSession(); } foreach (var face in Faces) { CurrentFullFrame.Draw(face, new Bgr(Color.Red), 1); } foreach (var user in Users) { CurrentFullFrame.Draw(user.UserName, new Point(user.Face.Left, user.Face.Top), Emgu.CV.CvEnum.FontFace.HersheySimplex, 1, new Bgr(Color.White), 2); CurrentFullFrame.Draw(user.Distance.ToString(), new Point(user.Face.Right, user.Face.Bottom), Emgu.CV.CvEnum.FontFace.HersheySimplex, 1, new Bgr(Color.White), 2); } } FPS++; VideoFrameImageBox.Image = CurrentFullFrame; } } catch (Exception) { return; } }
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; } } } }
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; } }
private void ProcessFrame(object sender, EventArgs e) { try { CurrentFullFrame = VideoCapture.QueryFrame().ToImage <Bgr, Byte>(); if (CurrentFullFrame != null) { if (!FacesDetected) { DetectFaces(); } else { foreach (var face in Faces) { CurrentFullFrame.Draw(face, new Bgr(Color.Red), 1); } string temp = ""; foreach (var item in Users) { temp += item.UserName + " - "; } //MessageBox.Show(temp); foreach (var user in Users) { DialogResult sino = MessageBox.Show("Es usted " + user.UserName + " ?", "Reconocimiento", MessageBoxButtons.YesNo); if (sino == DialogResult.Yes) { UserName = user.UserName; this.DialogResult = DialogResult.OK; using (StreamWriter writer = new StreamWriter(Path.GetTempPath() + @"\Archivo.dat")) { writer.WriteLine(string.Format("{0}", user.UserName)); } //try //{ // miPrimerSocket.Connect(miDireccion); // //Console.WriteLine("Conectado con exito"); // //Console.WriteLine("Ingrese el texto a enviar al servidor: "); // textoEnviar = Encoding.Default.GetBytes(UserName); //pasamos el texto a array de bytes // miPrimerSocket.Send(textoEnviar, 0, textoEnviar.Length, 0); // y lo enviamos // miPrimerSocket.Close(); //} //catch (Exception error) //{ // MessageBox.Show(error.Message); //} this.Dispose(); FacesDetectorTimer.Stop(); FacesRecognizerTimer.Stop(); VideoCapture.Stop(); break; } //CurrentFullFrame.Draw(user.UserName, new Point(user.Face.Left, user.Face.Top), Emgu.CV.CvEnum.FontFace.HersheySimplex, 1, new Bgr(Color.White), 2); //CurrentFullFrame.Draw(user.Distance.ToString(), new Point(user.Face.Right, user.Face.Bottom), Emgu.CV.CvEnum.FontFace.HersheySimplex, 1, new Bgr(Color.White), 2); //MessageBox.Show("Test " + user.UserName); } } FPS++; VideoFrameImageBox.Image = CurrentFullFrame; } } catch (Exception) { return; } }