private void Start() { ProducerTask = Task.Factory.StartNew(() => { var sw = new Stopwatch(); while (!Stopping) { sw.Reset(); sw.Start(); var image = new Mat(); var success = Reader.Read(image); if (!success) { if (Reader.CaptureType == CaptureType.File) { StopAsync().Wait(); break; } continue; } FrameProvidedAction?.Invoke(image); sw.Stop(); FpsOrigin = 1000.0 / sw.ElapsedMilliseconds; if (!Analyzing) { ProcessFrameAsync(image.ToBytes(".jpg")); } } Reader.Dispose(); Reader = null; }, TaskCreationOptions.LongRunning); }
protected void Start(TimeSpan frameGrabDelay, Func <DateTime> timestampFn) { ProducerTask = Task.Factory.StartNew(() => { while (!Stopping) { var image = Reader.QueryFrame(); FrameProvidedAction?.Invoke(image); if (!Analyzing) { ProcessFrameAsync(image); } } Reader.Dispose(); Reader = null; }, TaskCreationOptions.LongRunning); }