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 }
/// <summary> /// Read Text from Image and Store in Text File /// </summary> /// <param name="ImagePath">specify the Image Path</param> /// <param name="StoreTextFilePath">Specify the Store Text File</param> private static void ReadTextFromImage(String ImagePath, String StoreTextFilePath) { try { // Grab Text From Image MODI.Document ModiObj = new MODI.Document(); ModiObj.Create(ImagePath); ModiObj.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, true, true); //Retrieve the text gathered from the image MODI.Image ModiImageObj = (MODI.Image)ModiObj.Images[0]; // Store Image Content in Text File FileStream CreateFileObj = new FileStream(StoreTextFilePath, FileMode.Create); //save the image text in the text file StreamWriter WriteFileObj = new StreamWriter(CreateFileObj); WriteFileObj.Write(ModiImageObj.Layout.Text); WriteFileObj.Close(); ModiObj.Close(); } catch (Exception ex) { throw new Exception(ex.Message); } }
/* * 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 int Recognize(Bitmap bmpFile) { Bitmap bmpNew = new Bitmap(200, 200); Graphics gfx = Graphics.FromImage(bmpNew); gfx.FillRectangle(Brushes.White, 0, 0, 200, 200); gfx.DrawImage(bmpFile, 100, 100, bmpFile.Width, bmpFile.Height); string fileName = string.Format("{0}.tiff", number++); bmpNew.Save(fileName, System.Drawing.Imaging.ImageFormat.Tiff); MODI.Document md = new MODI.Document(); try { md.Create(fileName); md.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, true, true); } catch (Exception e) { //if cannot recognize there is must be empty image return(0); } MODI.Image image = (MODI.Image)md.Images[0]; try { recognizedDigit = Int32.Parse(image.Layout.Text); } catch (Exception e) { return(0); } return(recognizedDigit); }
/// <summary> /// Check for Images /// read text from these images. /// save text from each image in text file automaticly. /// handle problems with images /// </summary> /// <param name="directoryPath">Set Directory Path to check for Images in it</param> public string doOCR(string file) { try { //OCR Operations ... MODI.Document md = new MODI.Document(); md.Create(file); md.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, true, true); MODI.Image image = (MODI.Image)md.Images[0]; return(image.Layout.Text); } catch (Exception exc) { string msgTxt; if (exc.Message == "OCR running error") { msgTxt = "Es konnten keine Buchstaben erkannt werden. \r\nDas Bild wird unter einer laufenden Nummer gespeichert."; } else { msgTxt = exc.Message; } //uncomment the below code to see the expected errors System.Windows.MessageBox.Show(msgTxt, "OCR Exception"); return(string.Empty); } }
public string GetTextData(string path) { string fileExtension = Path.GetExtension(path); string fileName = Path.GetFileName(path); if (fileExtension != ".jpg" && fileExtension != ".JPG") throw new Exception("Nieobsługiwany typ pliku."); MODI.Document md = new MODI.Document(); md.Create(path); md.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH); MODI.Image image = (MODI.Image)md.Images[0]; return image.Layout.Text; }
private string OCR(string fp) { try { //OCR Operations ... MODI.Document md = new MODI.Document(); md.Create(fp); md.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, true, true); MODI.Image image = (MODI.Image)md.Images[0]; return(image.Layout.Text); } catch (Exception ex) { DebugHelper.WriteException(ex, "Error attempting to OCR " + fp); return(string.Empty); } }
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); }
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); }
private static void ReadTextFromImage(String ImagePath) { try { // Grab Text From Image MODI.Document ModiObj = new MODI.Document(); ModiObj.Create(ImagePath); ModiObj.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, true, true); //Retrieve the text gathered from the image MODI.Image ModiImageObj = (MODI.Image)ModiObj.Images[0]; System.Console.WriteLine(ModiImageObj.Layout.Text); ModiObj.Close(); } catch (Exception ex) { throw new Exception(ex.Message); } }