Esempio n. 1
0
 public DetectedPoints getFeatureVector(int[][] p)
 {
     DetectedPoints output = new DetectedPoints();
     foreach (var a in pointsOfInterest) {
         output[a.IndexVal] = a.Locate(p);
     }
     return output;
 }
Esempio n. 2
0
 public TestResult Predict(DetectedPoints pts)
 {
     TestResult result = new TestResult();
     Dictionary<Label, double> results = new Dictionary<Label,double>();
     foreach (var a in library) {
         double comparison = a.Value.Compare(pts);
         results[a.Key] = comparison;
     }
     result.Add(results);
     return result;
 }
Esempio n. 3
0
 internal void Train(DetectedPoints pts, Label label, TestResult result)
 {
     if (!library.ContainsKey(label)) {
         library[label] = pts;
     } else {
         var baseVal = library[label].Compare(pts);
         foreach (var a in library) {
             if (a.Key == label) continue;
             var a1 = a.Value.Compare(pts);
             if (a1 > baseVal) {
                 a.Value.Sanitize(pts);
             }
         }
     }
 }
Esempio n. 4
0
        private void Run()
        {
            while (true)
            {
                try
                {
                    var targetColor = _detectorEntity.DetectedColors.FirstOrDefault(x => x.Name == _analyzerColor);
                    if (targetColor == null)
                    {
                        Thread.Sleep(1000);
                        continue;
                    }

                    if (targetColor.RecognisedArray == null)
                    {
                        Thread.Sleep(100);
                        continue;
                    }

                    var detectedPoints = new List <Vector2>();

                    if (_checkArray == null ||
                        _checkArray.GetLength(0) != targetColor.RecognisedArray.GetLength(0) ||
                        _checkArray.GetLength(1) != targetColor.RecognisedArray.GetLength(1))
                    {
                        _checkArray =
                            new bool[targetColor.RecognisedArray.GetLength(0), targetColor.RecognisedArray.GetLength(1)];
                    }
                    else
                    {
                        for (var x = 0; x < _checkArray.GetLength(0); x++)
                        {
                            for (var y = 0; y < _checkArray.GetLength(1); y++)
                            {
                                _checkArray[x, y] = false;
                            }
                        }
                    }

                    for (var x = 0; x < targetColor.RecognisedArray.GetLength(0); x++)
                    {
                        for (var y = 0; y < targetColor.RecognisedArray.GetLength(1); y++)
                        {
                            var score = targetColor.RecognisedArray[x, y] / targetColor.Sensitivity;

                            if (score > _pointThreshold && !_checkArray[x, y])
                            {
                                if (FloodFillCheckAt(targetColor, _checkArray, x, y))
                                {
                                    detectedPoints.Add(new Vector2(x, y));
                                }
                            }
                        }
                    }

                    DetectedPoints = detectedPoints;

                    // If we have four points, try and determine top-left, top-right, bottom-left and bottom-right.
                    if (DetectedPoints.Count == 4)
                    {
                        TopLeft    = DetectedPoints.OrderBy(x => x.X + x.Y).FirstOrDefault();
                        TopRight   = DetectedPoints.OrderBy(x => (_checkArray.GetLength(0) - x.X) + x.Y).FirstOrDefault();
                        BottomLeft =
                            DetectedPoints.OrderBy(x => x.X + (_checkArray.GetLength(1) - x.Y)).FirstOrDefault();
                        BottomRight =
                            DetectedPoints.OrderBy(
                                x => (_checkArray.GetLength(0) - x.X) + (_checkArray.GetLength(1) - x.Y))
                            .FirstOrDefault();
                        TopLeftNormalized = new Vector2(TopLeft.Value.X / (float)_checkArray.GetLength(0),
                                                        TopLeft.Value.Y / (float)_checkArray.GetLength(1));
                        TopRightNormalized = new Vector2(TopRight.Value.X / (float)_checkArray.GetLength(0),
                                                         TopRight.Value.Y / (float)_checkArray.GetLength(1));
                        BottomLeftNormalized = new Vector2(BottomLeft.Value.X / (float)_checkArray.GetLength(0),
                                                           BottomLeft.Value.Y / (float)_checkArray.GetLength(1));
                        BottomRightNormalized = new Vector2(BottomRight.Value.X / (float)_checkArray.GetLength(0),
                                                            BottomRight.Value.Y / (float)_checkArray.GetLength(1));
                    }
                    else
                    {
                        TopLeft               = null;
                        TopRight              = null;
                        BottomLeft            = null;
                        BottomRight           = null;
                        TopLeftNormalized     = null;
                        TopRightNormalized    = null;
                        BottomLeftNormalized  = null;
                        BottomRightNormalized = null;
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex);
                }

                Thread.Sleep(20);
            }
        }