예제 #1
0
        public void Execute()
        {
            Console.WriteLine("Execute OCR");

            OCR.Statistics.Clear();
            OCR.Statistics.AddCounter("Processors", System.Environment.ProcessorCount);

            SISThreshold filter    = new SISThreshold();
            int          Threshold = filter.CalculateThreshold(m_Image.Image, m_Image.Area);

            OtsuThreshold filterOtsu = new OtsuThreshold();

            Threshold = filterOtsu.CalculateThreshold(m_Image.Image, m_Image.Area);

            PreprocessPage Processor = new PreprocessPage();

            Processor.Image    = m_Image;
            Processor.Treshold = m_Image.CalculateOtsuThreshold();
            m_Image.Threshold  = 170;
            Processor.Execute();

            resultBitmap = PageImage.CreateBitmapFromByteArray(m_Image.BinaryBytes, new Size(m_Image.Width, m_Image.Height));

            DetectComponents Step2 = new DetectComponents();

            Step2.Image = m_Image;
            Step2.Execute();

            AnalyseComponents Step3 = new AnalyseComponents();

            Step3.Image = m_Image;
            Step3.Execute();

            DetectSentences Step4 = new DetectSentences();

            Step4.Image = m_Image;
            Step4.Execute();

            ExtractFeatures Step5 = new ExtractFeatures();

            Step5.Image = m_Image;
            Step5.Execute();

            RecogniseComponent Step6 = new RecogniseComponent();

            Step6.Image = m_Image;
            Step6.Execute();

            ProcessSentences Step7 = new ProcessSentences();

            Step7.Image = m_Image;
            Step7.Execute();
        }
        /// <summary>
        /// This functions 'recognises' the given compontent by running its features through
        /// a neural network.
        /// </summary>
        /// <param name="Component"></param>
        public static void RecogniseWithoutConnectedRepair(ShapeNet ShapeNet, PageComponent Component)
        {
            sNeuralOutput Result = new sNeuralOutput();

            ShapeNet.NeuralNetwork.ComputeOutput(RecogniseComponent.CalculateNetworkInput(Component), Result);

            for (int i = 0; i < Result.fOutputs.Count; i++)
            {
                if (Result.fOutputs[i] >= 0.01)
                {
                    Component.AddRecognitionResult(Result.fOutputs[i], ShapeNet.ShapeList[i].Shape);
                }
            }
        }
예제 #3
0
        /// <summary>
        /// This functions splits a character in multiple components. Used for splitting connected characters
        /// </summary>
        public void Split(ShapeNet ShapeNet)
        {
            List <int> SplitLines;

            //Step 1: Get the position for possible splits
            SplitLines = SplitDeterminePositions();

            if (SplitLines.Count == 0)
            {
                return;
            }

            RecognitionResults.Clear();

            //Step 2: Find the combination of the best (highest scores) recognised components
            List <PageComponent> Components = new List <PageComponent>(0);
            PageComponent        newComponent;
            PageComponent        prevComponent;
            Rectangle            SplitArea;
            int start, end;

            SplitLines.Insert(0, 0);
            SplitLines.Add(Width - 1);

            start = 0;
            end   = 1;

            while (end < SplitLines.Count)
            {
                SplitArea = new Rectangle(SplitLines[start] + 1, 0, SplitLines[end] - SplitLines[start] - 2, Height);

                if (SplitArea.Width > 0 && SplitArea.Height > 0)
                {
                    while (NumberPixelsOnRow(BinaryBytes, SplitArea, 0, 0) == 0)
                    {
                        SplitArea.Y      = SplitArea.Y + 1;
                        SplitArea.Height = SplitArea.Height - 1;
                    }

                    while (NumberPixelsOnRow(BinaryBytes, SplitArea, SplitArea.Height - 1, 0) == 0)
                    {
                        SplitArea.Height = SplitArea.Height - 1;
                    }

                    newComponent = PartialCopy(SplitArea);

                    ExtractFeatures.ExecuteExtractFeatures(newComponent, false);
                    RecogniseComponent.RecogniseWithoutConnectedRepair(ShapeNet, newComponent);

                    if (Components.Count > 0 && end - start > 1)
                    {
                        prevComponent = Components.Last();

                        if (prevComponent.ContentProbability < newComponent.ContentProbability && newComponent.Content != "connected" && newComponent.Content != "garbage")
                        {
                            Components.Remove(prevComponent);
                            Components.Add(newComponent);
                        }
                        else
                        {
                            start = end - 1;
                            end--;
                        }
                    }
                    else
                    {
                        Components.Add(newComponent);
                    }
                }
                end++;
            }

            //Add the new recognition result
            RecognitionResult newResult;

            newResult             = new RecognitionResult();
            newResult.Content     = "";
            newResult.Probability = 0;

            foreach (PageComponent Component in Components)
            {
                newResult.Content     += Component.Content;
                newResult.Probability += Component.ContentProbability;
            }

            newResult.Probability = newResult.Probability / Components.Count;

            RecognitionResults.Add(newResult);

            //Save a copy of the image to the disc
            if (DebugTrace.DebugTrace.TraceFeatures)
            {
                String ComponentID = "000000" + ID;
                ComponentID = ComponentID.Substring(ComponentID.Length - 6);

                foreach (int SplitLine in SplitLines)
                {
                    int pointer = SplitLine;

                    for (int y = 0; y < Height; y++)
                    {
                        if (BinaryBytes[SplitLine, y] == 0xFF)
                        {
                            BinaryBytes[SplitLine, y] = 0x10;
                        }
                        pointer += Stride;
                    }
                }

                Bitmap Bitmap   = DebugTrace.DebugTrace.CreateBitmapFromByteArray(BinaryBytes, new Size(Width, Height));
                String Filename = DebugTrace.DebugTrace.TraceFeatureFolder + "image_" + ComponentID + "_split.bmp";
                Bitmap.Save(Filename);
            }
        }