/// <summary> /// 点击开始按钮时 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ButtonStart_Click(object sender, EventArgs e) { #region 识别老照片 DirectoryInfo TheFolder = new DirectoryInfo(@"C:\Users\mrls\Desktop\video"); if (!TheFolder.Exists) { MessageBox.Show("文件夹不存在"); return; } var files = TheFolder.GetFiles().Where(x => ".jpg,.png,".Contains(x.Extension.ToLower() + "")).ToList(); foreach (FileInfo NextFile in files) { float[] oldEigenValues; Bitmap oldImg = (Bitmap)Image.FromFile(NextFile.FullName); var oldFaces = ViewFace.FaceDetector(oldImg); if (oldFaces.Length > 0) { var oldPoints = ViewFace.FaceMark(oldImg, oldFaces[0]); oldEigenValues = ViewFace.Extract(oldImg, oldPoints); } else { oldEigenValues = new float[0]; } var person = new PersonInfo(); person.Name = NextFile.Name.Substring(0, NextFile.Name.IndexOf(".")); person.oldEigenValues = oldEigenValues; personInfos.Add(person); } #endregion if (VideoPlayer.IsRunning) { VideoPlayer.SignalToStop(); VideoPlayer.WaitForStop(); TimerDetector.Start(); ButtonStart.Text = "打开摄像头并识别人脸"; } else { if (comboBox1.SelectedIndex == -1) { return; } FilterInfo info = VideoDevices[comboBox1.SelectedIndex]; VideoCaptureDevice videoCapture = new VideoCaptureDevice(info.MonikerString); VideoPlayer.VideoSource = videoCapture; VideoPlayer.Start(); TimerDetector.Start(); ButtonStart.Text = "关闭摄像头"; } }
void Setup() { try { SlideInterval = int.Parse(ConfigurationManager.AppSettings["SlideInterval"]); DetectorInterval = int.Parse(ConfigurationManager.AppSettings["DetectorInterval"]); TimerDetector.Interval = DetectorInterval; SlideTimer.Interval = SlideInterval; if (ImagePath == null) { ImagePath = new List <string>(); } if (ImageCounter == null) { ImageCounter = new Dictionary <int, int>(); } var mapFile = ConfigurationManager.AppSettings["MappingFile"]; if (File.Exists(mapFile)) { var AllLines = File.ReadAllLines(mapFile); foreach (var line in AllLines) { var path = line.Split(',')[1]; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); Directory.CreateDirectory(path + "\\Male"); Directory.CreateDirectory(path + "\\Female"); } ImagePath.Add(path); } } if (Datas == null) { Datas = new List <DetectionResult>(); } _frame = new Mat(); detector = new DetectAgeGender(); _capture = new VideoCapture(); _capture.ImageGrabbed += _capture_ImageGrabbed; _capture.Start(); TimerDetector.Start(); SlideTimer.Start(); } catch (NullReferenceException excpt) { MessageBox.Show(excpt.Message); } }
private void startTimer() { this.timerDetector = new TimerDetector(); this.timerDetector.TimerCallBack += (object sender, TimerDetectorEventArgs e) => { this.Invoke(new Action(() => { this.textBoxSignalMessage.Text += e.DataIdentifier.DataUniqueID; this.textBoxSignalMessage.Text += " : "; this.textBoxSignalMessage.Text += ((object[])(e.DataIdentifier.RawData))[0].ToString(); this.textBoxSignalMessage.Text += "\r\n"; this.textBoxSignalMessage.SelectionStart = this.textBoxSignalMessage.Text.Length; this.textBoxSignalMessage.ScrollToCaret(); this.textBoxSignalMessage.Refresh(); })); }; this.timerDetector.Detect(); }
/// <summary> /// 点击开始按钮时 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ButtonStart_Click(object sender, EventArgs e) { if (VideoPlayer.IsRunning) { VideoPlayer.SignalToStop(); VideoPlayer.WaitForStop(); TimerDetector.Start(); ButtonStart.Text = "打开摄像头并识别人脸"; } else { if (comboBox1.SelectedIndex == -1) { return; } FilterInfo info = VideoDevices[comboBox1.SelectedIndex]; VideoCaptureDevice videoCapture = new VideoCaptureDevice(info.MonikerString); VideoPlayer.VideoSource = videoCapture; VideoPlayer.Start(); TimerDetector.Start(); ButtonStart.Text = "关闭摄像头"; } }