Inheritance: IDisposable
Exemplo n.º 1
0
 public static void ProcessImageFile(OcrReader ocrReader, string file)
 {
     using (Bitmap bmp = ImageFiles.LoadImageFile(file))
     {
         Bitmap grayscale, binary, binarySplit;
         PageSections pageSections = PrepareBitmaps(bmp, out grayscale, out binary, out binarySplit);
         ocrReader.ReadPage(new Bytemap(grayscale), new Bytemap(binary), new Bytemap(binarySplit), pageSections);
         grayscale.Dispose();
         binary.Dispose();
         binarySplit.Dispose();
     }
 }
Exemplo n.º 2
0
        public static void ProcessImageFile(OcrReader ocrReader, string file, out Bitmap displayA, out Bitmap displayB)
        {
            using (Bitmap bmp = ImageFiles.LoadImageFile(file))
            {
                Bitmap grayscale, binary, binarySplit;
                PageSections pageSections = PrepareBitmaps(bmp, out grayscale, out binary, out binarySplit);

                displayA = new Bitmap(binary);
                displayB = new Bitmap(grayscale);
                AnnotatePageStructure(displayA, pageSections);
                AnnotatePageHeatmap(displayB, ocrReader.QualityData);
            }
        }
Exemplo n.º 3
0
        public static bool ProcessImage(OcrReader ocrReader, Bitmap bmp, out Bitmap displayA, out Bitmap displayB)
        {
            Bitmap grayscale, binary, binarySplit;
            bmp = bmp.Clone() as Bitmap;
            PageSections pageSections = PrepareBitmaps(bmp, out grayscale, out binary, out binarySplit);
            if (pageSections == null)
            {
                displayA = new Bitmap(binary);
                displayB = new Bitmap(grayscale);
                return false;
            }
            ocrReader.ReadPage(new Bytemap(grayscale), new Bytemap(binary), new Bytemap(binarySplit), pageSections);

            displayA = new Bitmap(binary);
            displayB = new Bitmap(grayscale);
            AnnotatePageStructure(displayA, pageSections);
            AnnotatePageHeatmap(displayB, ocrReader.QualityData);
            return true;
        }
Exemplo n.º 4
0
        // Train the neural networks. 
        //Note: This depends on the way your knowlwdge directory is set up and may need to be changed whenever retraining!
        public static void TrainNN(out OcrReader ocrReader)
        {
            int dimensionX = Properties.Settings.Default.DimensionX;
            int dimensionY = Properties.Settings.Default.DimensionY;

            NeuralNet nnDescriptions, nnTables, nnNumbers, nnHeadlines, nnDelimiters;

            List<string> knowledge = new List<string>();
            List<char> netKeys = new List<char>();
            string files = "abcdefghijklmnopqrstuvwy";
            for (int i = 0; i < files.Length; i++)
            {
                knowledge.Add(PathHelpers.BuildKnowledgeFilename(DescriptionsNetwork, files[i].ToString() + "_lower"));
                netKeys.Add(files[i]);
            }
            knowledge.Add(PathHelpers.BuildKnowledgeFilename(DescriptionsNetwork, "delimiter"));
            netKeys.Add('.');
            netKeys.Add('#');

            nnDescriptions = new NeuralNet(dimensionX, dimensionY, netKeys, knowledge);
            nnDescriptions.SaveFile = PathHelpers.BuildNetworkFilename(DescriptionsNetwork);
            nnDescriptions.Train(Properties.Settings.Default.SamplesDescriptions);

            knowledge.Clear();
            netKeys.Clear();

            files = "ABCDEFGHIJKLMNOPRSTUVWXY";
            for (int i = 0; i < files.Length; i++)
            {
                knowledge.Add(PathHelpers.BuildKnowledgeFilename(TablesNetwork, files[i].ToString() + "_upper"));
                netKeys.Add(files[i]);
            }
            knowledge.Add(PathHelpers.BuildKnowledgeFilename(TablesNetwork, "delimiter"));
            netKeys.Add(':');
            netKeys.Add('(');
            netKeys.Add(')');
            knowledge.Add(PathHelpers.BuildKnowledgeFilename(TablesNetwork, "minus"));
            netKeys.Add('-');

            nnTables = new NeuralNet(dimensionX, dimensionY, netKeys, knowledge);
            nnTables.SaveFile = PathHelpers.BuildNetworkFilename(TablesNetwork);
            nnTables.Train(Properties.Settings.Default.SamplesTables);

            knowledge.Clear();
            netKeys.Clear();

            knowledge.Add(PathHelpers.BuildKnowledgeFilename(DelimitersNetwork, "comma"));
            netKeys.Add('#');
            knowledge.Add(PathHelpers.BuildKnowledgeFilename(DelimitersNetwork, "dot"));
            netKeys.Add('.');
            knowledge.Add(PathHelpers.BuildKnowledgeFilename(DelimitersNetwork, "minus"));
            netKeys.Add('-');
            nnDelimiters = new NeuralNet(dimensionX, dimensionY, netKeys, knowledge);
            nnDelimiters.SaveFile = PathHelpers.BuildNetworkFilename(DelimitersNetwork);
            nnDelimiters.Train(Properties.Settings.Default.SamplesNumbers);

            knowledge.Clear();
            netKeys.Clear();

            files = "0123456789";
            for (int i = 0; i < files.Length; i++)
            {
                knowledge.Add(PathHelpers.BuildKnowledgeFilename(NumbersNetwork, files[i].ToString()));
                netKeys.Add(files[i]);
            }
            nnNumbers = new NeuralNet(dimensionX, dimensionY, netKeys, knowledge);
            nnNumbers.SaveFile = PathHelpers.BuildNetworkFilename(NumbersNetwork);
            nnNumbers.Train(Properties.Settings.Default.SamplesNumbers);

            knowledge.Clear();
            netKeys.Clear();

            files = "0123456789";
            for (int i = 0; i < files.Length; i++)
            {
                knowledge.Add(PathHelpers.BuildKnowledgeFilename(HeadlinesNetwork, files[i].ToString()));
                netKeys.Add(files[i]);
            }
            files = "ABCDEFGHIJKLMNOPQRSTUVXYZ";
            for (int i = 0; i < files.Length; i++)
            {
                knowledge.Add(PathHelpers.BuildKnowledgeFilename(HeadlinesNetwork, files[i].ToString() + "_upper"));
                netKeys.Add(files[i]);
            }
            files = "abcdefghijklmnopqrstuvwyz";
            for (int i = 0; i < files.Length; i++)
            {
                knowledge.Add(PathHelpers.BuildKnowledgeFilename(HeadlinesNetwork, files[i].ToString() + "_lower"));
                netKeys.Add(files[i]);
            }
            knowledge.Add(PathHelpers.BuildKnowledgeFilename(HeadlinesNetwork, "minus"));
            netKeys.Add('-');

            nnHeadlines = new NeuralNet(15, 22, netKeys, knowledge);
            nnHeadlines.SaveFile = PathHelpers.BuildNetworkFilename(HeadlinesNetwork);
            nnHeadlines.Factor = 2;
            nnHeadlines.Train(Properties.Settings.Default.SamplesHeadlines);

            ocrReader = new OcrReader(nnDescriptions, nnTables, nnNumbers,nnHeadlines, nnDelimiters);
        }