Esempio n. 1
0
 private void Run(Emgu.Util.ExceptionHandler eh = null)
 {
     try
     {
         while (_grabState == GrabState.Running || _grabState == GrabState.Pause)
         {
             if (_grabState == GrabState.Pause)
             {
                 _pauseEvent.WaitOne();
             }
             else if (IntPtr.Zero.Equals(_ptr) || !Grab())
             {
                 //capture has been released, or
                 //no more frames to grab, this is the end of the stream.
                 //We should stop.
                 _grabState = GrabState.Stopping;
             }
         }
     }
     catch (Exception e)
     {
         if (eh != null && eh.HandleException(e))
         {
             return;
         }
         throw new Exception("Capture error", e);
     }
     finally
     {
         _grabState = GrabState.Stopped;
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Start the grab process in a separate thread. Once started, use the ImageGrabbed event handler and RetrieveGrayFrame/RetrieveBgrFrame to obtain the images.
        /// </summary>
        /// <param name="eh">An exception handler. If provided, it will be used to handle exception in the capture thread.</param>
        public void Start(Emgu.Util.ExceptionHandler eh = null)
        {
            if (_grabState == GrabState.Pause)
            {
                _grabState = GrabState.Running;
                _pauseEvent.Set();
            }
            else if (_grabState == GrabState.Stopped || _grabState == GrabState.Stopping)
            {
                _grabState = GrabState.Running;

                _captureTask = new Task(delegate { Run(eh); });
                _captureTask.Start();
            }
        }