Exemplo n.º 1
0
        private void setupWordClassifier(string wordsPath, string wordProbPath)
        {
            Game.ValidWords = new WordDict(wordsPath);

            WordClassifier = new KNearestClassifier(1, Metric.WeightedHammingDistance, WeightMode.Modal);
            WordClassifier.TrainingInstances = new List<Instance>();
            string[] lines = File.ReadAllLines(wordProbPath);

            foreach (string line in lines)
            {
                string[] word = line.Split(' ');
                InstanceS x = new InstanceS(word[0]);
                x.Weight = float.Parse(word[1]);
                WordClassifier.TrainingInstances.Add(x);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:System.Object"/> class.
        /// </summary>
        /// <remarks></remarks>
        public TileOCR(string trainingPath)
        {
            classifier = new KNearestClassifier(1, Metric.EuclideanDistance, WeightMode.InverseDistance);
            training = LoadInstancesFromBitmaps(trainingPath);
            
            classifier.Train(training);

            results = new List<OCRResult>();

            grayscale = new Grayscale(0, 0.85, 0.15);
            invert = new Invert();
            resize = new ResizeNearestNeighbor(32, 32);
            floodFill = new PointedColorFloodFill(Color.Black);
            dilate = new BinaryDilatation3x3();
            blobCounter = new BlobCounter();
            blobCounter.FilterBlobs = true;
            blobCounter.MinWidth = 4;
            blobCounter.MinHeight = 14;
            blobCounter.MaxWidth = 30;
            blobCounter.MaxHeight = 30;
            blobCounter.ObjectsOrder = ObjectsOrder.XY;
            threshold = new BradleyLocalThresholding();
            threshold.PixelBrightnessDifferenceLimit = 0;
            //Threshold.WindowSize = 20;
            threshold.WindowSize = 24;
        }