Exemplo n.º 1
0
        // Todo: prevFile isn't necessary. Instead store the features of the current scan to be used on the next.
        // That could cause sync problems so it needs to be investigated.
        private void NewRun(Scan scan, int index)
        {
            var deltas            = new double[CompiledFeatures.FeatureCount];
            var benchmarks        = new double[CompiledFeatures.FeatureCount];
            var now               = scan.CurrentFrame.DateTime;
            var fileImageBase     = scan.CurrentFrame.Bitmap;
            var prevFileImageBase = CompiledFeatures.UsesDupeCheck(now) ? scan.PreviousFrame.Bitmap : null;

            try
            {
                foreach (var cWatchZone in CompiledFeatures.CWatchZones)
                {
                    CropScan(ref deltas, ref benchmarks, now, fileImageBase, prevFileImageBase, cWatchZone);
                }
            }
            catch (Exception e)
            {
                scan.Dispose();
                Log.Error(e, "Error scanning frame.");
                if (IsVideoSourceRunning() && !IsScannerLocked)
                {
                    ScanningCount--;
                }
            }

            var scanEnd = TimeStamp.CurrentDateTime.Time;

            try
            {
                DeltaManager?.AddResult(index, scan, scanEnd, deltas, benchmarks);
                NewResult(this, new DeltaOutput(DeltaManager, index, CurrentFPS));

                ScanningCount--;

                if (ScanFinished != null)
                {
                    ScanFinished(this, scan);
                }

                //scan.Dispose();

                // It's on its own thread so running it here should be okay.
                if (index % Math.Ceiling(AverageFPS) == 0)
                {
                    RefreshBenchmarks();
                }

                if (index >= DeltaManager.History.Count && AverageFPS > 70d)
                {
                    Log.Warning("Framerate is abnormally high, usually an indicator the video feed is not active.");
                    Restart();
                }
            }
            catch (Exception e)
            {
                Log.Error(e, "Unknown Scanner Error.");
            }
        }
Exemplo n.º 2
0
        public void HandleNewFrame(object sender, NewFrameEventArgs e)
        {
            var now = TimeStamp.CurrentDateTime.Time;

            InitCount++;
            if (!IsScannerLocked &&
                (InitCount > 255 || InitCount % 10 == 0) &&
                !CompiledFeatures.IsPaused(now) &&
                ScanningCount < 12)
            {
                ScanningCount++;

                var currentFrame  = new Frame(now, (Bitmap)e.Frame.Clone());
                var previousFrame = CurrentFrame;
                CurrentFrame = currentFrame;

                var newScan = new Scan(currentFrame, previousFrame, CompiledFeatures.UsesDupeCheck(now));

                var index = CurrentIndex;
                CurrentIndex++;

                Task.Factory.StartNew(() => NewRun(newScan, index));
            }
            else if (ScanningCount >= 12)
            {
                OverloadCount++;
                if (OverloadCount > 50)
                {
                    Log.Warning("Frame handler is too overloaded, restarting scanner...");
                    Restart();
                }
                else
                {
                    Log.Warning("Frame handler is overloaded!!!");
                }
            }
        }