Example #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
        }
Example #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);
        }
Example #3
0
        public static string getTextBitmap(string nameImage)
        {
            string text = null;

            try {
                string        file = Path.GetFullPath(nameImage + ".jpg");
                MODI.Document md   = new MODI.Document();
                md.Create(file);
                md.OCR(MODI.MiLANGUAGES.miLANG_SPANISH, false, false);
                MODI.Image  image  = (MODI.Image)md.Images[0];
                MODI.Layout layout = image.Layout;

                text = image.Layout.Text.Trim().Replace("\r\n", "");
                md.Close(false);
            }catch (Exception e) {
                text = null;
            }
            return(text);
        }
        private void pickConvertButton_Click(object sender, EventArgs e)
        {
            openFileDialog1.FileName = "";
            openFileDialog1.Filter   = "Image|*.jpg; *.png; *.bmp; *.jpeg; *.PNG;";
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                pictureBox1.Image = Image.FromFile(openFileDialog1.FileName.ToString());
            }

            try
            {
                MODI.Document doc = new MODI.Document();
                doc.Create(openFileDialog1.FileName.ToString());

                if (comboBox1.SelectedIndex == 0)
                {
                    doc.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, true, true);
                }
                else if (comboBox1.SelectedIndex == 1)
                {
                    doc.OCR(MODI.MiLANGUAGES.miLANG_GERMAN, true, true);
                }
                else
                {
                    doc.OCR(MODI.MiLANGUAGES.miLANG_TURKISH, true, true);
                }

                foreach (MODI.Image p in doc.Images)
                {
                    MODI.Layout txt = p.Layout;
                    richTextBox1.Text = txt.Text;
                }
                doc.Close();
            }
            catch (Exception errorMes)
            {
                MessageBox.Show(errorMes.Message.ToString(), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }