Exemplo n.º 1
0
        public DetectorEntity(WebcamEntity webcamEntity, IAssetManager assetManager, I2DRenderUtilities renderUtilities)
        {
            _webcamEntity    = webcamEntity;
            _assetManager    = assetManager;
            _renderUtilities = renderUtilities;
            _defaultFont     = _assetManager.Get <FontAsset>("font.Default");

            _colorsToDetect = new List <ColorToDetect>
            {
                new ColorToDetect {
                    Color = new Color(1f, 0f, 0f), Name = "Red"
                },
                new ColorToDetect {
                    Color = new Color(0f, 1f, 0f), Name = "Green"
                },
                new ColorToDetect {
                    Color = new Color(0f, 0f, 1f), Name = "Blue"
                },
                new ColorToDetect {
                    Color = new Color(1f, 1f, 0f), Name = "Yellow"
                }
            };

            _currentIndex = 0;
            _currentColor = _colorsToDetect[_currentIndex];

            GlobalSensitivity = 1 / 10000000f * 25f;

            _thread = new Thread(ProcessorThread);
            _thread.IsBackground = true;
            _thread.Start();
        }
Exemplo n.º 2
0
        private bool FloodFillCheckAt(ColorToDetect targetColor, bool[,] checkArray, int x, int y)
        {
            var totalCount = 0;
            var toCheck    = new Stack <KeyValuePair <int, int> >();

            toCheck.Push(new KeyValuePair <int, int>(x, y));
            while (toCheck.Count > 0)
            {
                var toScan = toCheck.ToList();
                toCheck.Clear();

                foreach (var s in toScan)
                {
                    var xx = s.Key;
                    var yy = s.Value;

                    if (checkArray[xx, yy])
                    {
                        continue;
                    }

                    if (targetColor.RecognisedArray[xx, yy] > _pointThreshold)
                    {
                        totalCount++;

                        if (totalCount > _maxNumberOfPoints)
                        {
                            // We can't be true beyond this point.
                            return(false);
                        }

                        checkArray[xx, yy] = true;

                        if (xx >= 1 && xx < checkArray.GetLength(0) - 1)
                        {
                            if (yy >= 1 && yy < checkArray.GetLength(1) - 1)
                            {
                                toCheck.Push(new KeyValuePair <int, int>(xx - 1, yy - 1));
                                toCheck.Push(new KeyValuePair <int, int>(xx - 1, yy));
                                toCheck.Push(new KeyValuePair <int, int>(xx - 1, yy + 1));
                                toCheck.Push(new KeyValuePair <int, int>(xx, yy - 1));
                                toCheck.Push(new KeyValuePair <int, int>(xx, yy + 1));
                                toCheck.Push(new KeyValuePair <int, int>(xx + 1, yy - 1));
                                toCheck.Push(new KeyValuePair <int, int>(xx + 1, yy));
                                toCheck.Push(new KeyValuePair <int, int>(xx + 1, yy + 1));
                            }
                        }
                    }
                }
            }

            if (totalCount >= _minNumberOfPoints && totalCount <= _maxNumberOfPoints)
            {
                return(true);
            }

            return(false);
        }
 public void NextColor()
 {
     _currentIndex++;
     if (_currentIndex >= _colorsToDetect.Count)
     {
         _currentIndex = 0;
     }
     _currentColor = _colorsToDetect[_currentIndex];
 }
Exemplo n.º 4
0
 public void NextColor()
 {
     _currentIndex++;
     if (_currentIndex >= _colorsToDetect.Count)
     {
         _currentIndex = 0;
     }
     _currentColor = _colorsToDetect[_currentIndex];
 }
        public DetectorEntity(WebcamEntity webcamEntity, IAssetManager assetManager, I2DRenderUtilities renderUtilities)
        {
            _webcamEntity = webcamEntity;
            _assetManager = assetManager;
            _renderUtilities = renderUtilities;
            _defaultFont = _assetManager.Get<FontAsset>("font.Default");

            _colorsToDetect = new List<ColorToDetect>
            {
                new ColorToDetect {Color = new Color(1f, 0f, 0f), Name = "Red"},
                new ColorToDetect {Color = new Color(0f, 1f, 0f), Name = "Green"},
                new ColorToDetect {Color = new Color(0f, 0f, 1f), Name = "Blue"},
                new ColorToDetect {Color = new Color(1f, 1f, 0f), Name = "Yellow"}
            };

            _currentIndex = 0;
            _currentColor = _colorsToDetect[_currentIndex];

            GlobalSensitivity = 1/10000000f*25f;

            _thread = new Thread(ProcessorThread);
            _thread.IsBackground = true;
            _thread.Start();
        }
        private bool FloodFillCheckAt(ColorToDetect targetColor, bool[,] checkArray, int x, int y)
        {
            var totalCount = 0;
            var toCheck = new Stack<KeyValuePair<int, int>>();
            toCheck.Push(new KeyValuePair<int, int>(x, y));
            while (toCheck.Count > 0)
            {
                var toScan = toCheck.ToList();
                toCheck.Clear();

                foreach (var s in toScan)
                {
                    var xx = s.Key;
                    var yy = s.Value;

                    if (checkArray[xx, yy])
                    {
                        continue;
                    }

                    if (targetColor.RecognisedArray[xx, yy] > _pointThreshold)
                    {
                        totalCount++;

                        if (totalCount > _maxNumberOfPoints)
                        {
                            // We can't be true beyond this point.
                            return false;
                        }

                        checkArray[xx, yy] = true;

                        if (xx >= 1 && xx < checkArray.GetLength(0) - 1)
                        {
                            if (yy >= 1 && yy < checkArray.GetLength(1) - 1)
                            {
                                toCheck.Push(new KeyValuePair<int, int>(xx - 1, yy - 1));
                                toCheck.Push(new KeyValuePair<int, int>(xx - 1, yy));
                                toCheck.Push(new KeyValuePair<int, int>(xx - 1, yy + 1));
                                toCheck.Push(new KeyValuePair<int, int>(xx, yy - 1));
                                toCheck.Push(new KeyValuePair<int, int>(xx, yy + 1));
                                toCheck.Push(new KeyValuePair<int, int>(xx + 1, yy - 1));
                                toCheck.Push(new KeyValuePair<int, int>(xx + 1, yy));
                                toCheck.Push(new KeyValuePair<int, int>(xx + 1, yy + 1));
                            }
                        }
                    }
                }
            }

            if (totalCount >= _minNumberOfPoints && totalCount <= _maxNumberOfPoints)
            {
                return true;
            }

            return false;
        }