Exemplo n.º 1
0
        static void LearnOcr(string pImageInputPath)
        {
            ImageProcessor proc = new ImageProcessor();

            proc.DebugWindow();

            KNearestOcr ocr = new KNearestOcr();

            ocr.LoadTrainingData();
            Console.WriteLine("Entering OCR training mode!\n");
            Console.WriteLine("<0>..<9> to answer digit, <space> to ignore digit, <s> to save and quit, <q> to quit without saving.\n");

            var images = Directory.GetFiles(pImageInputPath);
            int key    = 0;

            foreach (var image in images)
            {
                proc.SetInput(new Image <Bgr, byte>(image));
                proc.Process();

                key = ocr.Learn(proc.GetOutput());

                if (key == 'q' || key == 's')
                {
                    Console.WriteLine("Quit\n");
                    break;
                }
            }

            if (key != 'q')
            {
                Console.WriteLine("Saving training data\n");
                ocr.SaveTrainingData();
            }
        }
Exemplo n.º 2
0
        static void TestOcr(string pImageInputPath)
        {
            ImageProcessor proc = new ImageProcessor();

            proc.DebugWindow();
            proc.DebugDigits();

            Plausi plausi = new Plausi();

            KNearestOcr ocr = new KNearestOcr();

            if (!ocr.LoadTrainingData())
            {
                Console.WriteLine("Failed to load OCR training data\n");
                return;
            }
            Console.WriteLine("OCR training data loaded.\n");
            Console.WriteLine("<q> to quit.\n");

            var images = Directory.GetFiles(pImageInputPath, "*.png");

            foreach (var image in images)
            {
                proc.SetInput(new Image <Bgr, byte>(image));
                proc.Process();

                var output = proc.GetOutput();

                var result = ocr.Recognize(output);
                Console.WriteLine("Result: " + result);

                if (plausi.Check(result, DateTime.Now))
                {
                    Console.WriteLine(plausi.CheckedValue);
                }
                else
                {
                    Console.WriteLine("  -------");
                }
                int key = CvInvoke.WaitKey(delay);

                if (key == 'q')
                {
                    Console.WriteLine("Quit\n");
                    break;
                }
            }
        }