コード例 #1
0
ファイル: KnnCore.cs プロジェクト: aweeesome/scribex
        /// <summary>
        /// Feed each character of a paragraph to a recognizer.
        /// </summary>
        /// <param name="paragraph"></param>
        /// <returns></returns>
        public string RecognizeParagraph(Paragraph paragraph)
        {
            string result = "";
            foreach (Line line in paragraph.lines)
            {
                foreach (Word word in line.words)
                {
                    foreach (Character character in word.characters)
                    {
                        Image resized = ImageHelper.ResizeImage(character.image, ImageHelper.RecommendedSize, ImageHelper.RecommendedSize);
                        Image resized_mono = ImageHelper.ThresholdAndConvertTo1bpp(resized);
                            //Classification classification = RecognizeImageWithBoolArrayMethod(resized_mono);
                            //Classification classification = RecognizeSuperimposedImageWithHausdorffMethod(resized_mono);
                            //Classification classification = RecognizeSuperimposedImageWithBoolArrayMethod(resized_mono);
                        Classification classification = RecognizeSuperimposedAndEnhancedImageWithBoolArrayMethod(resized_mono);
                        if(classification == Classification.Eight)  //Handle special case where 3 and 8 can be confused by RecognizeSuperimposedAndEnhancedImageWithBoolArrayMethod().
                        {
                            Classification newClassification = RecognizeImageWithBoolArrayMethod(resized_mono);
                            Classification newClassification2 = RecognizeSuperimposedImageWithHausdorffMethod(resized_mono);
                            if (newClassification == newClassification2)
                                classification = newClassification;
                        }
                        result += ClassificationToString(classification);
                    }
                    result += " ";
                }
                result += "\n";
            }

            return result;
        }
コード例 #2
0
ファイル: ImageHelper.cs プロジェクト: aweeesome/scribex
        /// <summary>
        /// Preprocesses a scanned image to be recognized.
        /// Operations performed: thresholding, noise removal, line segmentation, word segmentation and character segmentation.
        /// </summary>
        /// <param name="oriImage">Original image to be processed.</param>
        /// <returns></returns>
        public static Paragraph PreprocessScannedImage(Image oriImage)
        {
            Paragraph paragraph = new Paragraph();
            Image bpp = ThresholdAndConvertTo1bpp(oriImage);
            Image bppRgb = Convert1bppTo24bpp(bpp);
            Image noised = RemoveNoise(bppRgb);
            List<Image> lines_img = LineSegmentation(noised);
            foreach (Image line in lines_img)
            {
                Line line_class = new Line();
                List<Image> words_img = WordSegmentation(line);
                foreach (Image word in words_img)
                {
                    Word word_class = new Word();
                    List<Image> characters_img = CharacterSegmentation(word);
                    foreach (Image character in characters_img)
                    {
                        Character character_class = new Character();
                        character_class.image = character;
                        word_class.characters.Add(character_class);
                    }
                    line_class.words.Add(word_class);
                }
                paragraph.lines.Add(line_class);
            }

            return paragraph;
        }