private void ChannelSynthesis_Click(object sender, RoutedEventArgs e) { if (!WorkIng) { WorkIng = true; process = new Process(); process.StartInfo.FileName = $"{Environment.CurrentDirectory}/ChannelSynthesisByCPU.exe"; process.StartInfo.Arguments = $"\"{OutPutPath}/Photo\""; //process.StartInfo.UseShellExecute = false; //process.StartInfo.RedirectStandardOutput = true; //process.StartInfo.CreateNoWindow = true; Cancel.IsEnabled = true; OutPutBox.Text = ""; task = new Task(() => { this.OutPutBox.Dispatcher.Invoke(new Action(() => { OutPutBox.AppendText("Alpha通道与RGB通道合成程序已启动,请等待"); OutPutBox.ScrollToEnd(); })); process.Start(); while (!process.HasExited) { Thread.Sleep(100); } this.OutPutBox.Dispatcher.Invoke(new Action(() => { OutPutBox.Text = OutPutBox.Text + $"{Environment.NewLine}核心程序已退出"; OutPutBox.ScrollToEnd(); })); if (Directory.Exists($"{OutPutPath}/Photo/OutPut")) { Process.Start($"{OutPutPath}/Photo/OutPut"); } if (CanCel) { CanCel = false; } this.ChannelSynthesis.Dispatcher.Invoke(new Action(() => { ChannelSynthesis.IsEnabled = false; })); this.Cancel.Dispatcher.Invoke(new Action(() => { Cancel.IsEnabled = false; })); WorkIng = false; }); task.Start(); } else { MessageBox.Show("已有项目在运行,请等待"); } }
private void BeginWebCam() { if (webCam == null) { webCam = new VideoCapture(); } webCam.ImageGrabbed += webCam_ImageGrabbed; webCam.Start(); OutPutBox.AppendText($"WebCam Started...{Environment.NewLine}"); }
private void Timer_Tick(object sender, EventArgs e) { webCam.Retrieve(frame); var imageFrame = frame.ToImage <Gray, byte>(); if (TimerCounter < TimeLimit) { TimerCounter++; if (imageFrame != null) { var faces = faceDetection.DetectMultiScale(imageFrame, 1.3, 5); if (faces.Count() > 0) { var processedImage = imageFrame.Copy(faces[0]).Resize(ProcessedImageWidth, ProcessedImageHeight, Emgu.CV.CvEnum.Inter.Cubic); Faces.Add(processedImage); IDs.Add(Convert.ToInt32(IdBox.Text)); ScanCounter++; OutPutBox.AppendText($"{ScanCounter} Success Scan Taken... {Environment.NewLine}"); OutPutBox.ScrollToCaret(); } } } else { Mat[] faceImages = new Mat[Faces.Count]; faceImages = Faces.Select(c => c.Mat).ToArray(); faceRecognition.Train(faceImages, IDs.ToArray()); faceRecognition.Write(YMLPath); timer.Stop(); Trainbottom.Enabled = !Trainbottom.Enabled; IdBox.Enabled = !IdBox.Enabled; OutPutBox.AppendText($"Training Complete!{Environment.NewLine}"); MessageBox.Show("Training Completed!"); PredictButton.Enabled = true; } }
private void ResourcesRelease_Click(object sender, RoutedEventArgs e) { if (Directory.Exists(InPutPath) && !WorkIng) { WorkIng = true; process = new Process(); process.StartInfo.FileName = $"{Environment.CurrentDirectory}/ResourcesReleaseTool.exe"; process.StartInfo.Arguments = $"-t -i \"{InPutPath}\" -o \"{OutPutPath}\""; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.CreateNoWindow = true; //process.StartInfo.StandardOutputEncoding = Encoding.ASCII; process.Start(); Cancel.IsEnabled = true; OutPutBox.Text = ""; task = new Task(() => { while (!process.HasExited) { string buffer = process.StandardOutput.ReadLine(); this.OutPutBox.Dispatcher.Invoke(new Action(() => { OutPutBox.AppendText(buffer + Environment.NewLine); OutPutBox.ScrollToEnd(); })); } this.OutPutBox.Dispatcher.Invoke(new Action(() => { OutPutBox.AppendText($"{Environment.NewLine}核心程序已退出"); OutPutBox.ScrollToEnd(); })); if (Directory.Exists($"{OutPutPath}/Photo")) { Process.Start($"{OutPutPath}/Photo"); } if (CanCel) { CanCel = false; } else { this.ChannelSynthesis.Dispatcher.Invoke(new Action(() => { ChannelSynthesis.IsEnabled = true; })); } this.Cancel.Dispatcher.Invoke(new Action(() => { Cancel.IsEnabled = false; })); WorkIng = false; }); task.Start(); } else if (WorkIng) { MessageBox.Show("已有项目在运行,请等待"); } else { MessageBox.Show("源目录不正确"); } }