Exemple #1
0
        private void pictureBox1_Click(object sender, EventArgs e)
        {
#if false
            MODI.Document doc = new MODI.Document();
            doc.Create(@"test.bmp");
            doc.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, false, false);

            StringBuilder str = new StringBuilder();

            for (int i = 0; i < doc.Images.Count; i++)
            {
                MODI.Image  img    = (MODI.Image)doc.Images[i];
                MODI.Layout layout = img.Layout;

                Console.WriteLine(layout.Text);
                Console.WriteLine();

                for (int j = 0; j < layout.Words.Count; j++)
                {
                    MODI.Word word = (MODI.Word)layout.Words[j];
                    str.Append("[" + word.Text + "]");
                }
            }
            StreamWriter outfile = new StreamWriter(@"ocr.txt");
            outfile.Write(str.ToString());
            outfile.Close();
#endif
        }
Exemple #2
0
        /*
         * public SubtitleImage GetImage()
         * {
         *      Bitmap b = GetBitmap();
         *      Debugger.Print(Scan());
         *      return new SubtitleImage(GetBitmap());
         * }*/

        public string Scan()
        {
            string bitmapName = Path.GetTempPath() + "suprip_temp.png";

            MODI.Document md = new MODI.Document();
            GetBitmap().Save(bitmapName);

            md.Create(bitmapName);

            md.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, true, true);

            MODI.Image  image  = (MODI.Image)md.Images[0];
            MODI.Layout layout = image.Layout;

            string scanned = "";

            ocrWords = new List <OcrWord>();
            for (int j = 0; j < layout.Words.Count; j++)
            {
                // Get this word and deal with it.
                MODI.Word word = (MODI.Word)layout.Words[j];

                OcrWord w = new OcrWord(word.RecognitionConfidence, word.Text);
                ocrWords.Add(w);

                string text = word.Text;
                scanned += text + " ";
                int rc = word.RecognitionConfidence;
            }
            md.Close(false);

            return(scanned);
        }
        public static Document CreateByMODI(MODI.Document document)
        {
            Document doc = new Document();

            for (int p = 0; p < document.Images.Count; p++)
            {
                Page page = new Page();
                doc.Pages.Add(page);
                MODI.Image image = (MODI.Image)document.Images[p];
                for (int i = 0; i < image.Layout.Words.Count; i++)
                {
                    MODI.Word MODIWord = (MODI.Word)image.Layout.Words[i];
                    Word      newWord  = Word.CreateBYMODI(MODIWord);

                    page.Words.Add(newWord);
                }
            }
            return(doc);
        }
        /// <summary>
        /// Converts a MODI element to a Word instance
        /// </summary>
        /// <param name="word"></param>
        /// <returns></returns>
        public static Word CreateBYMODI(MODI.Word word)
        {
            Word newWord = new Word();

            newWord.Reference = word;
            Rectangle bounds = Rectangle.Empty;

            for (int i = 0; i < word.Rects.Count; i++)
            {
                MODI.MiRect rect    = (MODI.MiRect)word.Rects[i];
                Rectangle   newRect = new Rectangle(rect.Left, rect.Top, rect.Right - rect.Left, rect.Bottom - rect.Top);
                if (bounds.IsEmpty)
                {
                    bounds = newRect;
                }
                bounds = Rectangle.Union(bounds, newRect);
            }
            newWord.Bounds = bounds;
            return(newWord);
        }