void Timer_Tick(object sender, EventArgs e) { //Тестить, фиксить try { CurrentFrame = Capture.QueryFrame().ToImage <Bgr, Byte>(); } catch (Exception) { try { Thread.Sleep(100); Capture = new VideoCapture(CameraIndex); } catch (Exception) { CameraDisconected.Visibility = Visibility.Visible; StartStopButton_Click(null, null); } return; } string reportLog = "", log = String.Format("{0} - {1}: ", DateTime.Now.ToString(), CameraName.Content); Image <Bgr, Byte> image = CurrentFrame.Copy(); using (UMat ugray = new UMat()) { CvInvoke.CvtColor(image, ugray, ColorConversion.Bgr2Gray); CvInvoke.EqualizeHist(ugray, ugray); Faces.Clear(); Faces = new List <System.Drawing.Rectangle>(); Faces.AddRange(MainWindow.HaarCascade.DetectMultiScale(ugray, 1.1, 10, new System.Drawing.Size(20, 20))); int recognizeCount = 0; foreach (var face in Faces) { image.Draw(face, new Bgr(0, 0, 255), 3); if (MainWindow.PeopleData.Face.Count() != 0) { var result = MainWindow.FaceRecognizer.Predict(ugray.ToImage <Gray, Byte>().Copy(face).Resize(100, 100, Inter.Cubic)); if (result.Label > 0 && result.Distance <= 100) { recognizeCount++; string name = MainWindow.PeopleData.Name[result.Label - 1]; image.Draw(100 - (int)result.Distance + " " + name, new System.Drawing.Point(face.X, face.Y - 10), FontFace.HersheyComplex, 0.8, new Bgr(0, 0, 255)); reportLog += name + "; "; } } } int unknownFaces = Faces.Count() - recognizeCount; if (unknownFaces > 0) { reportLog += unknownFaces + " неизвестных"; } else if (reportLog == "") { reportLog = " ---"; } if (reportLog != prevReportLog) { MainWindow.Logs.Add(log + reportLog); } prevReportLog = reportLog; } VideoStream.Source = Watcher.ToBitmapSource(image); RecognizeCount.Content = "(" + Faces.Count() + ")"; }
public void SaveLogs(object sender, EventArgs e) { Watcher.WriteJson(Logs, ConfigurationManager.AppSettings["LogData"]); }
private void RenameButton_Click(object sender, RoutedEventArgs e) { CameraName.Content = Watcher.SetName("Введите новое название камеры:"); }