private void toolStripButton6_Click(object sender, EventArgs e) { if (VideoState == VideoState.Running) { capture.Pause(); VideoState = VideoState.Paused; } else { capture.Start(); VideoState = VideoState.Running; } UpdateUI(); }
private void button1_Click(object sender, EventArgs e) { if (_capture != null) { if (_captureInProgress) { //stop the capture button1.Text = "Stop Face Capture"; timer1.Enabled = true; timer1.Start(); _capture.Pause(); } else { //start the capture timer1.Enabled = false; button1.Text = "Start Face Capture"; timer1.Stop(); _capture.Start(); } _captureInProgress = !_captureInProgress; } }
public void TestFileCapturePause() { int totalFrames1 = 0; String fileName = EmguAssert.GetFile("tree.avi"); String fileName2 = fileName.Replace("tree.avi", "tree2.avi"); File.Copy(fileName, fileName2, true); VideoCapture capture1 = new VideoCapture(fileName); //capture one will continute capturing all the frames. EventHandler captureHandle1 = delegate { Mat img = new Mat(); capture1.Retrieve(img); totalFrames1++; Trace.WriteLine(String.Format("capture 1 frame {0}: {1}", totalFrames1, DateTime.Now.ToString())); }; capture1.ImageGrabbed += captureHandle1; capture1.Start(); System.Threading.Thread.Sleep(2); int totalFrames2 = 0; VideoCapture capture2 = new VideoCapture(fileName2); int counter = 0; //capture 2 will capture 2 frames, pause for 1 seconds, then continute; EventHandler captureHandle = delegate { counter++; totalFrames2++; bool needPause = (counter >= 2); if (needPause) { capture2.Pause(); counter = 0; } Mat img = new Mat(); capture2.Retrieve(img); Trace.WriteLine(String.Format("capture 2 frame {0}: {1}", totalFrames2, DateTime.Now.ToString())); if (needPause) { System.Threading.ThreadPool.QueueUserWorkItem(delegate { Trace.WriteLine("Sleep for 1 sec"); System.Threading.Thread.Sleep(1000); capture2.Start(); }); } }; capture2.ImageGrabbed += captureHandle; capture2.Start(); //int totalFrames = 69; Stopwatch s = Stopwatch.StartNew(); while (! (totalFrames1 == totalFrames2)) { System.Threading.Thread.Sleep(1000); if (s.ElapsedMilliseconds > 120 * 1000) { EmguAssert.IsTrue(false, "Unable to finished reading frames in 2 mins"); break; } } capture1.Dispose(); capture2.Dispose(); }