I have documents scanned as .jpg images in a folder, and I would like to do OCR in C # for each of my documents in this folder. so far this has done:
public string CheckFilesAndDoOCR(string directoryPath)
{
directoryPath = Environment.SpecialFolder.MyPictures + "\\OCRTempPictures\\";
IEnumerator files = Directory.GetFiles(directoryPath).GetEnumerator();
string TheTxt = "";
while (files.MoveNext())
{
FileInfo nfo = new FileInfo(Convert.ToString(files.Current));
string fileName = AlltoJPG(nfo);
FileInfo foo = new FileInfo(fileName);
if (foo.Extension == ".jpg" || foo.Extension == ".JPG")
{
try
{
MODI.Document md = new MODI.Document();
md.Create(foo.FullName);
md.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, false, false);
MODI.Image image = (MODI.Image)md.Images[0];
TheTxt = image.Layout.Text;
md.Close(false);
FileStream createFile = new FileStream(foo.DirectoryName + "\\" + foo.Name.Replace(foo.Extension,string.Empty) + ".txt", FileMode.CreateNew);
StreamWriter writeFile = new StreamWriter(createFile);
writeFile.Write(TheTxt);
writeFile.Close();
}
catch (Exception ex)
{
string LogPath = System.Environment.SpecialFolder.MyPictures + "\\OCRTempPictures\\OCRInfo.txt";
Logger(LogPath, "| Exception: Source[" + ex.Source + "] Message[" + ex.Message + "] InnerException[" + ex.InnerException + "] StackTrace[" + ex.StackTrace + "] | ");
}
}
}
return TheTxt;
}
but MODI gives errors OCR running!or Cant reach file.File is in use..
Depending on the situation:
If someone can answer any of the above questions, it will be appreciated.
source
share