Пример #1
0
 public TemporaryThresholdSettings(ColourDetectorInput target, ThresholdSettings tempSettings)
 {
     _original = new ThresholdSettings();
     _original.Absorb(target.Settings);
     _target = target;
     target.Settings?.Absorb(tempSettings);
 }
 public TemporaryThresholdSettings(ColourDetectorInput target, ThresholdSettings tempSettings)
 {
     _original = new ThresholdSettings();
     _original.Absorb(target.Settings);
     _target = target;
     target.Settings?.Absorb(tempSettings);
 }
Пример #3
0
 public ColourDetectionControl()
 {
     InitializeComponent();
     _colorDetector = new ColourDetector();
     _detectorInput = new ColourDetectorInput();
     _colorSettingsRepo = new ColourSettingsRepository();
 }
Пример #4
0
        int GetDimensionResults(int dimensionMin, int dimensionMax, bool isHighSetting, Func <int, MCvScalar, MCvScalar> scalarUpdator)
        {
            var results      = new List <AutoThresholdResult>();
            var requiredArea = _targetRegion.Area() * RequiredMomentAreaInRoiPercent / 100;
            Func <ColourDetectorOutput, bool> meetsMinimumAreaRequired = o => o.MomentArea >= requiredArea;

            for (int i = dimensionMin; i < dimensionMax; i++)
            {
                var detectorInput = new ColourDetectorInput();
                detectorInput.Captured = _input;
                detectorInput.ErodeDilateIterations = ErodeDilateIterations;
                detectorInput.Settings.Absorb(_settings);
                detectorInput.Settings.MomentArea = new RangeF(0, float.MaxValue);

                if (isHighSetting)
                {
                    detectorInput.Settings.HighThreshold = scalarUpdator(i, detectorInput.Settings.HighThreshold);
                }
                else
                {
                    detectorInput.Settings.LowThreshold = scalarUpdator(i, detectorInput.Settings.LowThreshold);
                }

                var tickResult = new AutoThresholdResult();
                tickResult.DimensionValue = i;

                detectorInput.Settings.Roi = _targetRegion;
                tickResult.RoiOutput       = _colourDetector.Process(detectorInput);

                // Save processing the full screen if it doesn't meet minimum ROI requirements
                if (meetsMinimumAreaRequired(tickResult.RoiOutput))
                {
                    detectorInput.Settings.Roi = Rectangle.Empty;
                    tickResult.FullOutput      = _colourDetector.Process(detectorInput);

                    results.Add(tickResult);
                }

                ColourCheckTick?.Invoke(this, tickResult);
                Intercept?.Invoke(detectorInput);
            }

            // Remove any where region of interest isn't highlighted
            results.RemoveAll(r => r.RoiOutput.MomentArea < requiredArea);

            // Pick the smallest thresholded area left in full screen
            var result = results
                         .OrderBy(r => r.FullOutput.MomentArea)
                         .FirstOrDefault();

            if (result == null)
            {
                return(isHighSetting ? dimensionMax : dimensionMin);
            }

            return(result.DimensionValue);
        }
Пример #5
0
        public ColourDetectionControl()
        {
            InitializeComponent();
            _colorDetector = new ColourDetector();
            _detectorInput = new ColourDetectorInput();
            _colorSettingsRepo = new ColourSettingsRepository();
            _thresholdSelector = new ThresholdSelector();

            _imageBoxSelector = new ImageBoxSelector();
        }
Пример #6
0
        public override void ImageGrabbedHandler(object sender, EventArgs e)
        {
            using (var matCaptured = new Mat())
            {
                CameraCapture.Retrieve(matCaptured);
                var detector = new ColourDetector();
                var input = new ColourDetectorInput
                {
                    Captured = matCaptured
                   ,Settings= Settings
                   ,SetCapturedImage = false
                };

                var result = detector.Process(input);

                if (result.IsDetected)
                {
                    Log.Info(result);
                }
            }
        }
Пример #7
0
        public override void ImageGrabbedHandler(object sender, EventArgs e)
        {
            using (var matCaptured = new Mat())
            {
                CameraCapture.Retrieve(matCaptured);
                
                var input = new ColourDetectorInput
                {
                    Captured = matCaptured
                   ,Settings = Settings
                   ,SetCapturedImage = false
                };

                var result = _detector.Process(input);

                if (result.IsDetected)
                {
                    if (!_objectCurrentlyDetected)
                    {
                        _debounceWatch.Start();
                        _objectCurrentlyDetected = true;
                    }
                    SweeperToRed();
                    Log.Info(m=>m("Red detected! {0}", result));
                }
                else
                {
                    var isInDebouncePeriod = _debounceWatch.IsRunning && _debounceWatch.ElapsedMilliseconds < 800;
                    if (_objectCurrentlyDetected && !isInDebouncePeriod)
                    {
                        _debounceWatch.Reset();
                        Log.Info(m => m("Red gone"));
                        SweeperToGreen();
                        _objectCurrentlyDetected = false;
                    }
                }
            }
        }