using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Collections; using System.IO; using System.Drawing.Imaging; namespace OCRSample { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { CheckFileType(@"C:\OCR"); } /// <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 void CheckFileType(string directoryPath) { IEnumerator files = Directory.GetFiles(directoryPath).GetEnumerator(); while (files.MoveNext()) { //get file extension string fileExtension = Path.GetExtension(Convert.ToString(files.Current)); //get file name without extenstion string fileName=Convert.ToString(files.Current).Replace(fileExtension,string.Empty); //Check for JPG File Format if (fileExtension == ".jpg" || fileExtension == ".JPG") // or // ImageFormat.Jpeg.ToString() { try { //OCR Operations ... MODI.Document md = new MODI.Document(); md.Create(Convert.ToString(files.Current)); md.OCR(MODI.MiLANGUAGES.miLANG_ARABIC, true, true); MODI.Image image = (MODI.Image)md.Images[0]; //create text file with the same Image file name FileStream createFile = new FileStream(fileName + ".txt",FileMode.CreateNew); //save the image text in the text file StreamWriter writeFile = new StreamWriter(createFile); writeFile.Write(image.Layout.Text); writeFile.Close(); } catch (Exception) { //MessageBox.Show("This Image hasn't a text or has a problem", //"OCR Notifications", //MessageBoxButtons.OK, MessageBoxIcon.Information); } } } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)